Skip to content

fix(4): remove self-replacing no-op in custom-rules URL (CodeQL #4) - #468

Closed
Alajmah wants to merge 4 commits into
masterfrom
security/identity-replace-removal
Closed

Alajmah wants to merge 4 commits into
masterfrom
security/identity-replace-removal

Conversation

@Alajmah

@Alajmah Alajmah commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Unit 4 (final) of the authorized #425 remediation sequence (#5 → #1+#2 → #3 → #4). Removal of the identity-replacement no-op flagged by CodeQL js/identity-replacement #4 at packages/web-dashboard/src/app/custom-rules/page.tsx:63. Merge authority reserved; returned at exact head for clearance.

The change

.replace("/api/config/", "/api/config/") replaced a value with itself — dead code the query flags as an unfinished edit. The generated URL was and remains /api/config/{owner}/{repo}/custom-rules, which resolves against the live backend route configRouter.get("/:owner/:repo/custom-rules") (config.js:238) — verified in the tranche report (PR #464 comment 7053127297). The no-op is deleted; nothing else changes.

Regression

Per the directive ("a regression verifies that the generated URL remains unchanged"): tests/api-urls.test.ts now pins API.repoConfig(owner, repo) + "/custom-rules" === /api/config/o/r/custom-rules — the exact construction the page performs post-fix — so the URL cannot drift silently as a result of the removal.

Verification

  • Full dashboard suite 67/67 green (66 pre-existing + the new regression).

… 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>
…nce regexes

CodeQL js/polynomial-redos #1/#2 remediation (reviewSchema.js:273/284). The
fence regex pair's greedy \s* (matches newlines) interacting with the
following \n? made the whitespace bridge ambiguous: O(n^2) per fence
occurrence on unclosed-fence + long-whitespace inputs, multiplied by
matchAll per fence. Input is the review LLM completion (max_tokens 32768) —
reachable via prompt-injection echo — and extraction runs on the shared
worker event loop, so pathological output blocked all 14 workers plus /health.

Replacement: scanFencedBlocks() — monotonic indexOf pairing of opening and
closing fences, linear worst case regardless of whitespace shape. Semantics
preserved from the regex pair: sequential pairing (matchAll continuation),
immediate-json label stripping (the (?:json)? branch; JSON never starts
with the letters json), unclosed trailing fence yields no block, caller-side
trim unchanged, strategy identifiers fenced/fenced_multi unchanged.

Regressions (review-schema-fence-scanner.test.js, 22 tests):
- EQUIVALENCE: old regexes reproduced verbatim in-tree; 13-member corpus
  (labels, label-not-immediate, multi-fence, adjacency, unclosed,
  mid-line) asserts identical strategy+json outcomes
- BOUNDEDNESS (maintainer-specified shapes, all under 500ms):
  unclosed fence + 200k spaces (the maintainer's reproduced 2.06s case,
  scaled), + 200k newlines (CodeQL's stated shape), 30k repeated opening
  fences, 5k-fence valid multi-fence response, 150k-space run inside a
  valid fence
- Pre-existing reviewSchema suite (60 tests) unchanged and green; full
  rules suite 328/328.

Signed-off-by: Alajmah <55954113+Alajmah@users.noreply.github.com>
CodeQL js/polynomial-redos #3 remediation (reviewSchema.js:324-325). The
strategy-5 regex retried its literal prefix at every index and rescanned
the remaining suffix per candidate via the lazy body — quadratic on inputs
repeating {"findings":[ without completion, on the shared worker event loop.

Replacement: findFindingsPatternStart() — two monotonic indexOf passes with
O(1) shape checks: (1) every literal "overall_correctness" occurrence is
walked LEFT to collect valid ]-closes (ws* , ws* ], no suffix rescans);
(2) every {"findings" occurrence gets the deterministic \s*:\s*\[ shape
check and an existence test against the sorted close list. Linear total
work. First-match-start semantics preserved (incl. empty-array [] closes —
the lazy body may be zero-length; pinned by regression); the old
indexOf(matchText) was provably redundant (an earlier occurrence of the
full match text would itself be an earlier match, contradicting
first-match selection) — noted in the scanner doc.

Strategy 5's downstream flow (slice from match start, findMatchingBrace,
JSON.parse, pattern_match identifier) unchanged.

Regressions (review-schema-findings-pattern.test.js, 11 tests):
- EQUIVALENCE: old regex + old strategy-5 flow reproduced verbatim
  (findMatchingBrace replicated); 7-member corpus (firing shapes, first
  candidate completing via later text, invalid-JSON tails, no-array
  candidates, later-partial candidates) asserts fire/no-fire agreement;
  tab-spread whitespace tolerance; first-candidate precedence
- BOUNDEDNESS (<500ms): 30k repeated prefixes no completion (linear, falls
  through); 30k prefixes + one completion (shape completes, brace balance
  cannot close 30k opens — old flow identical terminal result); 1k-member
  single-candidate scale-up resolving pattern_match

Full rules suite 342/342 (fence-scanner + pre-existing suites unchanged).

Signed-off-by: Alajmah <55954113+Alajmah@users.noreply.github.com>
CodeQL js/identity-replacement #4 remediation (custom-rules/page.tsx:63):
.replace("/api/config/", "/api/config/") replaced a value with itself —
dead code flagged by the identity-replacement query as an unfinished edit.
The generated URL was and remains
/api/config/{owner}/{repo}/custom-rules, resolving against the live backend
route configRouter.get('/:owner/:repo/custom-rules') (config.js:238).

Regression (api-urls.test.ts): pins repoConfig(owner, repo) + '/custom-rules'
=== '/api/config/o/r/custom-rules' so the URL cannot drift silently when the
no-op is removed. Full dashboard suite green.

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-20T23:47:35.476757Z
We couldn’t complete this review. Comment @codex review to try again.
fd41683 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: 3
AI judgment: APPROVE · Evidence: COMPLETE · Authority: advisory
Evidence complete · 7/7 changed files accounted for

Other findings (3)

  • [low] Fence equivalence helper silently skips comparison when the old fence stage yields no parseable outcome
  • [medium] Production change (custom-rules URL no-op removal) has no pinned regression test ⚠️ unverified
  • [low] No corpus coverage for language-tag case/whitespace normalization divergence ⚠️ unverified

🔮 Devil's Advocate (2 turns): 2 missed risks 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] Production change (custom-rules URL no-op removal) has no pinned regression test

    The review's only finding addresses the fence-scanner test file, leaving the PR's actual production change — removing the self-replacing expression in the custom-rules URL path — completely unpinned. CodeQL 'self-assignment/no-op' alerts occasionally flag code with subtle side effects (e.g., String.replace with a regex carrying state, or a re-parse that normalized/encoded the URL). If the removed expression incidentally normalized or validated the URL, its removal could silently change the emitted URL (encoding, query composition, trailing behavior) with no test asserting the exact output string. A golden-value test on the constructed custom-rules URL should accompany this fix.

  • [LOW] No corpus coverage for language-tag case/whitespace normalization divergence

    The corpus examples surfaced in the review cover space-before-label and a missing label, but the classic divergence point between a strict regex parser and a hand-rolled scanner like scanFencedBlocks is normalization of the language tag itself: 'JSON' vs 'json', trailing whitespace after the label ('```json '), or tabs vs spaces. If the old regex and the new scanner disagree on any of these (e.g., one uppercases the tag, the other preserves it, affecting downstream grammar dispatch), neither the equivalence helper's non-null branch nor the current corpus examples would catch it. Worth one cheap corpus entry to pin.

const extracted = extractReviewJSON(input);
if (oldOutcome === null) {
// Old code fell through to strategies 3-5; the new code must reach the
// SAME subsequent strategies. For corpus members designed to be decided

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] Fence equivalence helper silently skips comparison when the old fence stage yields no parseable outcome

In assertFenceEquivalence, the oldOutcome === null branch returns extracted without any assertion, despite the comment claiming 'the extraction result must then still agree, so compare full results'. Corpus members designed to fail fence parsing on both sides (e.g. ' json\n{"e": 5}\n' with the space-before-label, 'unclosed ``` json body without end') therefore pin nothing about the fence stage: if scanFencedBlocks ever diverged by parsing a body the old regex rejected, these cases would still pass silently. The direct label-stripping assertions on scanFencedBlocks partially mitigate this, but the null branch should assert the negative invariant for fence-decided corpus entries: expect(extracted.strategy).not.toBe('fenced') and .not.toBe('fenced_multi'). Suggested fix: add those two assertions in the null branch (optionally gated per corpus entry with a flag for inputs genuinely decided by later strategies).

@Alajmah

Alajmah commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #471: stacked branch (four units in the diff) — its APPROVED review (ai_reviews 1445) covered all seven files of the union, not this unit alone. #471 is this unit as a single commit on master; it gets its own review there.

@Alajmah Alajmah closed this Nov 21, 2026
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