Fix #25: eval injection in deny.cli wrapper generation - #39
Merged
Conversation
The CLI deny-wrapper generator embedded user-authored deny.cli patterns into a bash array literal and matched them via `eval`. A pattern like `foo$(id)*` would execute at wrapper-generation time (because bash array assignment performs command substitution) or at match time (because eval re-parses the value of $P). Fix: - Patterns are written to a side file (one per line) and read at run time with `read -r`, which does not perform expansion. - The match uses `[[ "$FULL_CMD" == $P ]]` directly. Parameter expansion of $P substitutes the value but does not recurse into command substitution, so $(...) inside a pattern is matched literally. - Command names (first word of allow/deny patterns) must match a conservative character class; values containing shell metacharacters are dropped at parse time. Extracted the wrapper-script builder to packages/runtime/src/cli-wrapper.ts so it can be unit-tested without the band-server's startup side effects. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
band-server.ts now imports from ./cli-wrapper, which was introduced in the eval-injection fix. CI only copied server.ts to the VM, causing "Cannot find module './cli-wrapper'" on startup. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Owner
Author
|
@copilot resolve the merge conflicts in this pull request |
…ection # Conflicts: # packages/runtime/src/band-server.ts
Contributor
Resolved. The only conflict was in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #25.
What broke
The CLI deny-wrapper generator embedded user-authored
deny.clipatterns into a bash array literal and matched them witheval. A pattern likefoo$(id)*would execute at wrapper-generation time (bash array assignment performs command substitution) or at match time (eval re-parses the value of$P).The attacker is anyone who can author a BAND.md the system loads. Code runs as the host VM user, before sandboxing — privilege escalation inside the VM.
Fix
read -r, which does not perform parameter or command substitution.[[ "$FULL_CMD" == $P ]]directly. Parameter expansion of$Psubstitutes the value but does not recurse into command substitution, so$(...)inside a pattern is matched literally rather than executed.which/readlinkshell call.packages/runtime/src/cli-wrapper.tsso it can be unit-tested without the band-server's startup side effects.Tests
New unit tests in
packages/runtime/test/unit/band-server-cli-wrappers.test.tsverify:evalnor an embeddedDENY_PATTERNS=(...)literal.deny-<cmd>at run time$(id), backticks, semicolons, spaces,../) throwgit-lfs,node18,a.out) are acceptedAll 278 existing unit tests still pass; typecheck clean.
🤖 Generated with Claude Code