Treat unspaced & as a background operator unless redirect-bound - #937
Merged
Merged
Conversation
Merged
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 CL-7781: a permission bypass where
&with no trailing space hid a second command inside one approved segment.Previously
isRedirectAmpersandkeyed off the character following&, soa &bwas treated as a redirect token and stayed one segment — a standing grant for the benign head auto-covered the hidden payload. Now&is redirect-bound only by preceding context (previous non-space char is>/<", e.g.2>&1,>&2,<&-") or an immediately following>(&>/&>>). Everything else falls through to the existing chain-boundary branch, soa &bsplits into two segments whilebun run build 2>&1stays unfragmented.Tests:
splitChainedCommandsegment-count table:a &b,a & b-> 2;a &>f,a 2>&1,a >&2,a <&--> 1;a&&b,a &&b-> 2bun test *does not coverbun test x &touch pwnbun run check: green (6990 pass, 0 fail)Sibling-operator audit (same loop):
&&,||,|,;, newline need no preceding-context rule — they are unconditionally control operators and can never appear inside a redirect token (redirects are built only from digits,>,<,&,-). The lone&was the only operator with dual redirect/control use. Noted pre-existing quirk (unchanged by this fix, out of scope):|&drops the&but still splits, so nothing hides. Heredoc regions untouched (shell-serial branch owns them).Related: CL-7781