Skip to content

fix(5): quarantine workflow — Actions-expression + YAML + shell safe test identifiers (v2) - #472

Merged
Alajmah merged 1 commit into
masterfrom
security/quarantine-yaml-shell-escaping-v2
Nov 21, 2026
Merged

Alajmah merged 1 commit into
masterfrom
security/quarantine-yaml-shell-escaping-v2

Conversation

@Alajmah

@Alajmah Alajmah commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Summary

v2 of the #5 remediation unit — replaces #465. The re-run review of #465 (REQUEST_CHANGES, high confidence, ai_reviews 1442) found a critical gap in v1 plus a medium; both are corrected here. Single commit on master 89d5e51. Merge authority reserved; returned at exact head for clearance.

The v1 review's findings and their corrections

CRITICAL — GitHub Actions expression injection (${{ … }}). The workflow parser evaluates ${{ … }} anywhere in the file, at parse time, regardless of YAML quoting and regardless of shell escaping — v1's $→\$ escape leaves the literal ${{ sequence intact through the backslash, so a test name like ${{ secrets.GITHUB_TOKEN }} would still evaluate. Correction: the sanitizer now breaks the opener first (${{ → ${ {) before any other escaping, so no ${{ sequence survives into the generated document at any interpolation site. Regressions assert (a) the literal sequence is absent from the entire generated YAML, (b) the payload survives as flattened data through the POSIX decoder (secrets / fromJSON / github.actor / env payloads), and (c) the document still parses with intact structure via js-yaml.

MEDIUM — YAML 1.1 line breaks. NEL (U+0085), LS (U+2028), PS (U+2029) and the C1 range (U+0080–U+009F) are YAML 1.1 break/control characters that v1 did not strip. Correction: the control-character class now covers C0 + DEL + full C1 + LS/PS. Regression constructs them via String.fromCharCode (they cannot appear as raw characters in JS source — U+2028/U+2029 are line terminators) and asserts stripping plus document-parse integrity.

LOW — testNamePattern remains regex-interpreted by Jest. Sanitized names containing regex metacharacters can alter matching semantics. This is pre-existing behavior (v0 escaping did not address it either), unchanged by this remediation, and out of scope; recorded here per the review.

The sanitizer (three layers, one function, every interpolation site)

  1. Actions expressions: ${{ → ${ { (opener broken; nothing else in the file can re-form it — the join separators are ours).
  2. YAML: C0 + DEL + C1 + LS/PS → space (the only characters that can escape a command: | block scalar or a # comment line into structure).
  3. Shell (double-quoted argument): backslash first, then ", $, ` — the complete expansion/substitution surface of POSIX double quotes.

Regressions (16 tests, all green alongside the existing flaky suite)

Real js-yaml document parses with structure pins (one job, four steps, injected runs-on:/on:/jobs: keys survive only as data — via \n, \r\n, and now NEL); POSIX double-quote decoder proving the closing quote is the intended one (post-close remainder is exactly 2>&1) for \", $(), backtick, ${IFS}, and multi-candidate | joins; expression-injection absence at unit and document level; benign names byte-identical.

… Actions-expression, YAML, and shell layers

CodeQL js/incomplete-sanitization #5 remediation (flakyTestService.js:220),
v2 with two corrections from the REQUEST_CHANGES review (ai_reviews 1442):

v1: testFilter escaped only double quotes. A test name containing a
backslash defeats that escaping in the generated Actions command; dollar
signs and backticks also expand inside double quotes; newlines escape the
YAML block scalar and comment lines. Boundary sanitizer introduced (C0+DEL
to space; backslash-first, then quote/dollar/backtick), uniform at both
interpolation sites.

v2 corrections:
- CRITICAL, GitHub Actions expression injection: the workflow parser
  evaluates the ${{ ... }} sequence anywhere in the file at parse time —
  YAML quoting and shell escaping do not stop it (an escaped dollar sign
  still leaves the literal ${{ intact). The sanitizer now breaks the opener
  FIRST (${{ becomes "${ {"), so no ${{ sequence survives into the
  generated document. Regressions assert the literal is absent from the
  whole YAML and the payload remains data (secrets/fromJSON/github.actor/env
  payloads).
- MEDIUM, YAML 1.1 line breaks: NEL U+0085, LS U+2028, PS U+2029 and the
  full C1 range are now stripped alongside C0+DEL (the characters that
  cannot appear in JS regex/string literals here are constructed via
  fromCharCode in tests).

LOW finding (testNamePattern remains regex-interpreted by Jest — sanitized
names can alter matching semantics) is PRE-EXISTING behavior, unchanged by
this remediation and out of scope; noted in the PR.

Regressions: 16 tests — real js-yaml document parse with structure pins,
POSIX double-quote decoder proving the closing quote is the intended one
(rest === 2>&1), expression-injection absence, YAML-1.1-break stripping,
newline/CR structure injection, benign-name byte identity.

Signed-off-by: Alajmah <55954113+Alajmah@users.noreply.github.com>
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-21T00:24:50.792129Z
We couldn’t complete this review. Comment @codex review to try again.
bddb197 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@gitwire-hq gitwire-hq Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Code Review — ✅ Approved

Confidence: high · Findings: 2
AI judgment: APPROVE · Evidence: COMPLETE · Authority: advisory
Evidence complete · 2/2 changed files accounted for

Other findings (2)

  • [low] Test-file header comment says identifiers are interpolated at "two layers", omitting the Actions-expression layer the suite tests
  • [medium] Escaping tests verify injection-safety, not matching semantics of quoted identifiers used as regex/pattern arguments ⚠️ unverified

🔮 Devil's Advocate (2 turns): 1 missed risk found · 1 upheld


GitWire AI Review Gate (bundle-driven v2) · Structured schema · Scope-validated · Devil's Advocate · AI recommendation — maintainers and repository policy retain authority

Finding details (not annotatable inline)

  • [MEDIUM] Escaping tests verify injection-safety, not matching semantics of quoted identifiers used as regex/pattern arguments

    Quarantine workflows typically locate the flaky test by matching its identifier in a shell pattern (grep, pytest -k, jest -t). Proper quoting/escaping prevents injection (all three layers the review focused on), but if the identifier is still consumed as a regex, metacharacters appearing in legitimate test names — e.g. 'foo (bar)', 'a+b', 'x.y' — silently change matching behavior: the workflow can fail to match the intended flaky test (quarantine is a no-op and the flaky test keeps running in CI) or match unrelated tests (over-quarantine, masking healthy tests). This equivalence property is orthogonal to injection-safety and is easy to miss when the test suite is organized around escape layers. The review should verify the workflow consumes identifiers as fixed strings (-F / --fixed-strings / exact-name filters) and/or that the suite includes a round-trip assertion that the escaped identifier matches its original and only its original.

@@ -0,0 +1,201 @@
// tests/unit/flaky-quarantine-escaping.test.js
// CodeQL #5 remediation regressions: untrusted test identifiers (suite and
// test names parsed from repository CI output) are interpolated into the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[LOW] Test-file header comment says identifiers are interpolated at "two layers", omitting the Actions-expression layer the suite tests

The header comment in flaky-quarantine-escaping.test.js states the identifiers are interpolated "at two layers and must remain DATA at both", enumerating only YAML and shell. However, the suite contains dedicated ACTIONS EXPRESSION INJECTION tests asserting the ${{ sequence never survives, and the service-file comment (and the PR description) correctly describe THREE layers, with the Actions-expression layer flagged as the critical one. The stale/incomplete header could mislead a future maintainer into believing the expression layer is untested or unaddressed here. Fix: update the header to list all three layers (Actions expressions, YAML, shell), matching the sanitizer's documentation.

@Alajmah

Alajmah commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Review adjudication — APPROVED unit; both findings evidence-closed, neither blocking

LOW — test-file header comment says "two layers" but the suite now tests three. Valid — the header predates the v2 expression layer. Non-substantive (comment-only), head preserved per the execution boundary; recorded in the post-merge cleanup batch.

MEDIUM — escaping tests verify injection-safety, not matching semantics of --testNamePattern. Valid and real, and pre-existing: v0 interpolated raw test names into the same regex-interpreted Jest flag, so names with regex metacharacters (foo (bar), a+b, x.y) already had altered matching before this remediation — the failure mode is functional (quarantine no-op or over-quarantine), not an injection vector, and every layer of the injection surface is closed by this unit.

Why it is not corrected in this head: the authorized scope for this unit was the sanitization boundary with existing valid-input behavior preserved; changing matching semantics (regex-escaping the name before shell-escaping, or switching the generated command to a fixed-string filter — note Jest's --testNamePattern has no fixed-string mode, so this means regex-escaping testFilter, which changes which names match for metacharacter-bearing legitimate names) is a behavior change to the quarantine workflow's contract and needs its own authorization.

Proposed follow-up (parked, needs authorization): regex-escape each identifier before the existing sanitizer chain (order: regex-escape → expression-break → control-strip → shell-escape), plus a round-trip regression asserting the generated pattern matches its original test name and only it (jest -t semantics simulated in-test). This closes both the reviewer's "matches its original and only its original" ask and the LOW finding from the previous review round.

State: head bddb197528f3474e0c35294d2ddefb497ee1582f unchanged; review APPROVED at high confidence.

@Alajmah
Alajmah merged commit 075318d into master Nov 21, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant