Skip to content

fix(auth): remove stale query-param comment — limiter identity chain v9 - #464

Merged
Alajmah merged 3 commits into
masterfrom
security/limiter-identity-v9
Nov 20, 2026
Merged

Alajmah merged 3 commits into
masterfrom
security/limiter-identity-v9

Conversation

@Alajmah

@Alajmah Alajmah commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Summary

v9 of the limiter identity remediation chain: #460 → #462 → #463 → here. One surgical correction over #463 (v8); everything else carried unchanged. Supersedes #463.

What this round fixes

The #463 review's finding 2 pointed at auth.js's comment "Extract key from header or query param" — no query-parameter authentication path exists (zero req.query reads in auth.js; the header is the only in-band key channel). The stale line predates this chain (introduced at 39826c9) but was preserved by the v8 refactor, so it is corrected here rather than left to mislead the next reader into designing a limiter identity for a channel that does not exist.

That is the only change in this PR.

The chain this PR carries (from #460/#462/#463, all held and superseded)

  1. Pre-auth family coverage — /api/auth/* and /api/bootstrap/* always key the limiter on the request IP (8 path-form regressions: case, trailing slash).
  2. Structural Bearer lockstep — shared extractBearerToken() (bearerToken.js) called by both apiKeyAuth and deriveLimiterIdentity; 12-case corpus contract test pins the one recognition rule both depend on.
  3. Advisory remediation — next 16.4.6 (dashboard, middleware→proxy.ts rename, @next/swc aligned) + 15.5.28 (demo-dashboard, manifest+lockfile synced), body-parser 1.20.9, zod ^4.6.6. Both dashboard builds verified green locally.

Adjudication of the #463 review (5 findings)

  • F1 [low] zod major without migration changes — verified compatible: consumers use only v4-stable APIs (parsed.error.issues, .refine(fn, "msg"), z.coerce); covered by green suites (config-validator, ci-heal-job-service, issue-fix-analysis-safety). Bundling is deliberate: the master-push CI failed on all 7 advisories at once (fix(10): streaming 25MiB webhook body cap — explicit disposition, swallowed late errors, no blanket listener removal #457 deploy skip); this chain clears the deploy blocker in one unit.
  • F2 [low] query-param auth has no limiter counterpart — premise was a stale comment, not code; fixed in this PR (the only change).
  • F3 [medium] pre-auth identity from attacker-controlled header enables rotation — premise false, and explicitly verified by three dedicated regressions: login end-to-end (130 rotating random Bearer tokens → ONE shared IP bucket, 429 at request 121), AUTH-CHECK (rotating Bearer + valid session → ONE bucket), BOOTSTRAP-STATE (anonymous rotating → ONE bucket), plus the PRE-AUTH OVERRIDE contract test (even a well-formed valid Bearer keys the IP on all four family paths). The reviewer's own ask ("needs explicit verification of the invalid-token fallback path") is exactly what those tests do.
  • F4 [low] per-IP pre-auth limits can lock out shared-NAT users — the trade-off is real and accepted: 120 req/min/IP on login/bootstrap is the intended brute-force tightening. The alternative (per-credential buckets before authentication) is the bypass this chain closes. This is a design decision for the maintainer, not a defect; a higher pre-auth threshold is a one-line follow-up if wanted.
  • F5 [low] helper comparison not constant-time — misattributed: extractBearerToken() performs no secret comparison (prefix slice + trim only). The one comparison, keys.has(providedKey) in auth.js, is unchanged by this refactor and pre-dates the chain. (Practical note: API keys are high-entropy random values; Set-membership timing does not practically leak them.)

Verification

  • v8 checks: 20 pass + 1 expected skip, mergeStateStatus: CLEAN at e4b17b7
  • This round: comment-only change, no behavioral surface; gates re-run on this head

…n (next 16.4.6, body-parser, zod)

PRE-AUTH EXTENSION (maintainer finding on #460): /api/auth/check
(session-cookie Redis lookup) and /api/bootstrap/state + /first
(anonymous DB work) mount before apiKeyAuth and carried the same
bucket-rotation mechanism. The pre-auth match now covers the COMPLETE
/api/auth/* and /api/bootstrap/* families (prefix regex, case +
trailing-slash tolerant). Bearer identity unchanged for ordinary
authenticated routes. Three new regressions: AUTH-CHECK end-to-end
(130 rotating-Bearer session requests → 429@121 ONE bucket);
BOOTSTRAP-STATE end-to-end (130 anonymous → 429@121 ONE bucket);
FAMILY VARIANTS (8 path forms all key on the IP).

THREE-LAYER REMEDIATION (carried): session-cookie rotation closed
(apiKeyAuth-exact recognition); pre-auth login closed (IP-keyed);
route-variant closed (trailing slash + case); derivation isolated
(derived as an exported function — the CodeQL missing-rate-limiting
model pairing resolved without behavior change).

ADVISORY REMEDIATION (the #457 master-push CI failed on seven new
advisories, three critical, on next ≤16.4.0):
- next 16.3.8→16.4.6 (dashboard; GHSA-2464 critical, GHSA-673q
  critical, GHSA-p3m5 high): requires middleware.ts→proxy.ts rename
  (function export renamed too) + @next/swc platform binaries
  hand-carried to 16.4.6 (the version mismatch crashed builds with
  'Cannot read properties of undefined (reading project)').
- next 15.5.24→15.5.28 (landing; same advisories' 13.x-15.x range).
- body-parser 1.20.6→1.20.9 (override; GHSA-27r3 high).
- zod 3.25.76→4.6.7 (web; GHSA-mrhx high).
Lockfile entries hand-carried with registry integrities (npm on
Windows refused to re-resolve overrides + platform binaries — the
known quirk).

VERIFICATION: audit gate 0 high/critical; limiter identity (17) +
behavior (9) + webhook body-limit (14) = 40 tests green; dashboard
5 suites / 66 tests green; dashboard build verified locally
(compiled successfully, 29/29 static pages).

Signed-off-by: Alajmah <55954113+Alajmah@users.noreply.github.com>
…t; demo-dashboard manifest sync

Adjudication corrections for the v7 chain (#462 review):

- apiKeyAuth and deriveLimiterIdentity held unlinked copies of the same
  Bearer recognition rule, kept in sync only by comments. Both now call a
  shared extractBearerToken() (bearerToken.js), and a 12-case corpus
  contract test pins the one rule both mechanisms depend on — divergence
  in either direction becomes a test failure, not a silent re-opening of
  the bucket-rotation bypass.
- Fixed a garbled test comment that cited a nonexistent ^Bearer\s+ regex
  for the tab-scheme case; apiKeyAuth actually uses a literal starts-with
  "Bearer " check, byte-identical to the limiter's recognition.
- demo-dashboard manifest pinned next 15.5.24 while the hand-carried
  lockfile resolves 15.5.28 — any npm install would have silently
  reverted the advisory floor. Manifest now matches the lockfile (npm ci
  dry-run verified); demo dashboard build verified green under 15.5.28.

Limiter semantics unchanged: 38 limiter tests + 15 triage-pr-guards green.

Signed-off-by: Alajmah <55954113+Alajmah@users.noreply.github.com>
The comment said 'Extract key from header or query param' but no
query-parameter authentication path exists (nor has one in the current
implementation's history) — the header is the only in-band key channel.
Confirmed against the code: zero req.query reads in auth.js. The stale
line drew a review finding ('query-param auth has no limiter identity
counterpart') whose premise was the comment, not the code.

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-20T20:38:26.209590Z
We couldn’t complete this review. Comment @codex review to try again.
d3f3fa2 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: 4
AI judgment: APPROVE · Evidence: COMPLETE · Authority: advisory
Evidence complete · 11/11 changed files accounted for

Other findings (4)

  • [low] Pre-auth path families duplicated as a hardcoded regex in the limiter; drift silently re-opens bucket minting
  • [medium] IP-fallback keying on pre-auth routes is spoofable if trust proxy is misconfigured — the mirror of the Bearer-minting problem ⚠️ unverified
  • [medium] No regression test pinning that pre-auth requests carrying arbitrary Bearer tokens collapse into a single bucket ⚠️ unverified
  • [low] Deleting the query-param comment removes the recorded rationale for excluding query-param identity, inviting reintroduction for SSE/websocket support ⚠️ unverified

🔮 Devil's Advocate (2 turns): 3 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] IP-fallback keying on pre-auth routes is spoofable if trust proxy is misconfigured — the mirror of the Bearer-minting problem

    The review scrutinized attacker-controlled Bearer tokens as an identity source but never examined the other half of the identity chain: for pre-auth families the limiter falls back to client IP. If app.set('trust proxy') doesn't match the actual proxy topology, req.ip is derived from a spoofable X-Forwarded-For header and an attacker mints IP buckets exactly as they minted token buckets. The review applied 'is this identity attacker-controlled?' to tokens but not to IPs — an asymmetric audit of the same mechanism.

  • [MEDIUM] No regression test pinning that pre-auth requests carrying arbitrary Bearer tokens collapse into a single bucket

    The corpus test pins token recognition, and existing limiter tests presumably pin keying for the two current families — but nothing asserts the actual invariant ('a request to any pre-auth path with a fresh attacker-supplied Bearer must reuse the path's bucket, not mint a new one'). That invariant-level test would also catch the future-drift scenario in finding #0 for free, making the review's suggested family-list pinning partially redundant; the review proposed the weaker of the two tests.

  • [LOW] Deleting the query-param comment removes the recorded rationale for excluding query-param identity, inviting reintroduction for SSE/websocket support

    The PR's entire content is removing the 'stale' query-param comment. Stale-looking comments about rejected designs usually encode a decision ('tokens in query strings are attacker-controlled and leak into logs/proxy caches, so never key identity on them'). The first future contributor adding EventSource/SSE endpoints — where browsers cannot set Authorization headers — has no in-code pointer explaining why query-param identity was rejected, making v10 of this chain a reintroduction rather than a hypothetical. A one-line redirect to the corpus test or an ADR would have preserved the rationale at zero cost.

// tolerance (Express's default non-strict, case-insensitive-to-route
// routing serves those variants to the same handlers).
// - Everything else falls back to the request IP.
export function deriveLimiterIdentity(req) {

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] Pre-auth path families duplicated as a hardcoded regex in the limiter; drift silently re-opens bucket minting

deriveLimiterIdentity() hardcodes the pre-auth families (/api/auth/, /api/bootstrap/) as regex literals, but the same 'which routes are pre-auth' decision also lives in app.js mount order / auth.js's skip check. This PR carefully factored the Bearer-recognition rule into a single shared helper (bearerToken.js) plus a corpus contract test to prevent drift, yet the path-family rule remains copy-encoded. Concrete failure mode: a future pre-auth family (e.g., /api/register) added to auth but not to this regex will be keyed by the limiter on the attacker-controlled Bearer token, silently restoring the per-request bucket-minting/throttle-escape this chain fixes — with no test failing, since the corpus test only pins Bearer recognition, not the family list. Suggestion: export a shared isPreAuthPath()/family-constant module (analogous to bearerToken.js) consumed by both the limiter and the auth skip logic, and pin the family list in rate-limiter-identity.test.js so adding a family forces a coordinated change. Not blocking for this PR (the two prefixes are correct today and the regex's case/trailing-slash tolerance matches Express defaults), but it leaves the same class of drift the PR set out to eliminate.

@Alajmah

Alajmah commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Review adjudication (all 4 findings) — evidence-closed, none blocking

Verdict per finding, with code and production evidence:

F1 [low] Family set duplicated as hardcoded regex; drift re-opens minting. Valid hardening observation, non-blocking (review is APPROVE). The families live in two places: the app.js mounts (app.js:87 /api/auth, app.js:93 /api/bootstrap) and the limiter's prefix regex. The structural fix — one shared PRE_AUTH_PREFIXES constant consumed by both — is a bounded follow-up. Recorded threshold: any change to the pre-auth mount set (or a third family) must extend the limiter family regex and its regressions in the same unit.

F2 [medium] IP fallback spoofable if trust proxy misconfigured. Adjudicated with production evidence — the premise cannot arise in the current topology, and the actual property is the opposite one:

  • No trust proxy is configured anywhere (grep over app.js/index.js: zero hits), so Express ignores X-Forwarded-For entirely; req.ip is the raw socket address. An attacker cannot influence it with headers — there is no XFF path to spoof.
  • Empirical check just now: three anonymous requests from an external client through the Cloudflare tunnel minted exactly one key — ratelimit:::ffff:172.18.0.3 — the tunnel connector's Docker address. req.ip in production is the tunnel container's address, not the client's.
  • Consequence (the honest mirror of this finding): all tunnel traffic shares ONE anonymous/pre-auth bucket (120 req/min global). This is pre-existing for anonymous callers (bearerToken || req.ip predates this chain); this chain only extends shared-bucket treatment to Bearer-carrying requests on pre-auth routes — which is precisely the rotation bypass being closed. No availability regression: an attacker could already saturate the shared anonymous login bucket before this change.
  • Follow-up decision parked for the maintainer, not this unit: configuring app.set('trust proxy', …) keyed to cloudflared's XFF would give per-client-IP buckets; that is a separate design decision with its own trust-boundary analysis (any container on gitwire-net could then forge XFF).

F3 [medium] No regression test pinning pre-auth + arbitrary Bearer → single bucket. Contradicted by the suite — three tests assert exactly the named invariant against the real middleware:

  • rate-limiter-identity.test.js:114 — END-TO-END: 130 POSTs to /api/auth/login with a fresh random Bearer per request → counts.size === 1, value 121, 429 at request 121.
  • :164 AUTH-CHECK — rotating Bearers + valid session cookie on /api/auth/check → ONE bucket, 429@121.
  • :187 BOOTSTRAP-STATE — anonymous rotating Bearers on /api/bootstrap/state → ONE bucket, 429@121.
  • Plus the PRE-AUTH OVERRIDE contract test (well-formed valid Bearer still keys the IP on all four family paths).

The residual gap is F1's: a future family added to app.js without extending the regex would not be covered by today's enumerated tests. That is the shared-constant follow-up, not a missing test of current behavior.

F4 [low] Deleting the comment removed the rationale for excluding query-param identity. Premise false — no rationale was deleted. The removed line ("Extract key from header or query param") described an implementation detail that never existed: zero req.query reads in auth.js, in this or any recent revision (the line dates to 39826c9). It recorded no decision; there is no SSE/websocket feature and no rejected query-param design to memorialize. Inventing a decision record for a design that never existed would be fabrication. If a query-param auth channel is ever genuinely proposed (e.g., for EventSource), that proposal gets its own security review — the corpus contract test is the in-code pointer to how recognition is pinned.


State for clearance: head d3f3fa222a6c725753fbe26d92614c27d530bf28, 20 checks pass + 1 expected skip (publish-release-images, PR event), mergeStateStatus: CLEAN, review APPROVED / high confidence. Chain: #460 → #462 → #463 → here.

@Alajmah
Alajmah merged commit 89d5e51 into master Nov 20, 2026
21 checks passed
@Alajmah

Alajmah commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Post-merge deployment verification — master 89d5e51 (all steps observed, none inferred)

Step Result
Merge #464 squash-merged at 2026-11-20T21:33:36Z → master 89d5e519c743b9851279ad506db01905ed17a719
Push CI PASS (the advisory failure that skipped #457's deploy is cleared by the bumps in this unit)
CodeQL (master) PASS
Deploy to Production completed success (run 44822373702) — staged recreation
/health status: ok, git_sha: 89d5e519c743b9851279ad506db01905ed17a719 — exact match, not unknown
Containers 10/10 healthy; app / executor-service / dashboard recreated at deploy, rest long-running
Migrations 49/49 applied

Deployed limiter — production proof (live, just now)

Two properties, each exercised with 3 requests (no threshold hammering):

  1. Ordinary route + rotating non-Bearer headers (Basic scheme-rot-1..3 → /api/repos, 401s): all three fell into the ONE shared tunnel-IP bucket — zero per-header buckets minted. (Pre-fix: each distinct header minted a fresh bucket.)
  2. Pre-auth route + rotating well-formed Bearer (Bearer family-rot-1..3 → /api/auth/check, 200s): all three fell into the same ONE shared bucket — zero token buckets minted. (Pre-fix: each token minted a fresh bucket — the login brute-force bypass.)

Redis held exactly one shared key (ratelimit:::ffff:172.18.0.3) plus three 60s-TTL per-credential keys from a deliberately misdesigned earlier probe of mine (Bearer rot-* on an ordinary route — per-token buckets there are the documented intended behavior for distinct credentials, not a bypass).

CodeQL alert matrix — actual states at 89d5e51 (inspected via API, not inferred)

Closed since the last ledger (2):

Open (22), by disposition:

Set Alerts Classification vs deployed state
13 API-route #14-17 (config), #23/25/26 (maintainer), #29 (triageOperations), #31-35 (rollouts) False positive — classification re-established, now WITH deployed evidence. All mount behind the app-level limiter (app.js:84, before every /api router). The query pairs in-handler credential reads with per-handler limiter sinks and cannot see app-level mounting. Production-proven rotation-proof identity above. Dismissals: 13, require authorization.
Same family, outside the counted 13 #9 (phase4.js:352; mounts app.js:175 behind the limiter) Same false-positive evidence as the 13-set; listed separately because the original classification set boundary excluded it. Dismissal requires authorization.
#10 webhooks.js:33 Open by design: /webhooks is deliberately limiter-exempt (GitHub HMAC-authenticated deliveries; a limiter would throttle GitHub retry behavior). The underlying resource-consumption concern is now bounded by the deployed 25MiB streaming cap (#457). Candidate false positive; dismissal requires authorization.
#13 app.js:108 (routeAuthObserver mount) Retains its explicit hold (risk-acceptance authorization required before any disposition). Same model-pairing shape as the limiter's own mount was.
#36/#37 parse.js:79, resolve.js:151 (prototype-pollution-utility) Open; direct-path regressions deployed (#451). Dismissals require authorization.
Regex/sanitization/identity tranches #1/2/3 (polynomial-redos), #5 (incomplete-sanitization), #4 (identity-replacement) Held in the agreed sequence.

No dismissals were performed. Every closed state above was read from the alerts API; nothing was inferred from green CI.

@Alajmah

Alajmah commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

CodeQL disposition execution — 15 authorized dismissals + 2 read-only dispositions (2026-11-21)

Inventory reconciliation (resolved first, as directed)

The API open inventory was 23 alerts, not 22 — my "22" in the previous matrix was a counting error in the report, not a missing or extra alert. Group arithmetic 13 API + #9 + #10 + #13 + #36/#37 + #1–#5 = 23 matches the API exactly. No alert was resolved, absent, or double-counted.

15 individually verified dismissals executed (all pre-checked open + exact location match before each PATCH)

13 API-route (reason: false positive — rate limiting enforced by upstream application middleware):

Alert Location verified Router mount (behind limiter at app.js:84) Dismissed at
#14 config.js:68 configRouter app.js:180 22:28:11Z
#15 config.js:117 configRouter app.js:180 22:28:27Z
#16 config.js:165 configRouter app.js:180 22:28:29Z
#17 config.js:210 configRouter app.js:180 22:28:32Z
#23 maintainer.js:236 maintainerRouter app.js:160 22:29:05Z
#25 maintainer.js:280 maintainerRouter app.js:160 22:29:08Z
#26 maintainer.js:370 maintainerRouter app.js:160 22:29:11Z
#29 triageOperations.js:94 triageOperationsRouter app.js:192 22:29:13Z
#31 rollouts.js:171 rolloutRouter app.js:196 22:28:41Z
#32 rollouts.js:105 rolloutRouter app.js:196 22:28:43Z
#33 rollouts.js:203 rolloutRouter app.js:196 22:28:46Z
#34 rollouts.js:233 rolloutRouter app.js:196 22:28:49Z
#35 rollouts.js:261 rolloutRouter app.js:196 22:28:51Z

Every dismissal comment carries: app-level limiter mount (app.js:84) preceding the router mount, skip-list scope (/health exact, /webhooks prefix only), deployed rotation-proof identity (89d5e51, #464), the 38-test pin, production proof date, and the documented Redis-failure fail-open residual (per the directive that it remain visible in the security record).

2 prototype-pollution-utility (reason: false positive — flagged assignments unreachable for dangerous keys):

Alert Flagged site Reachable guard (verified) Deployed regression Dismissed at
#36 resolve.js:151 (target[key] = value, mergeSparse scalar branch) resolve.js:133 if (isDangerousConfigKey(key)) continue; inside the Object.keys(source) own-keys loop, before any target access; upstream validation rejects dangerous keys (documented backstop, resolve.js:124–129) #451 @ 779f58f — direct-dangerous-keys.test.js 22:29:40Z
#37 parse.js:79 (target[key] = source[key], mergeDeep) parse.js:69 if (isDangerousConfigKey(key)) continue; inside the Object.keys(source) own-keys loop, before any access #451 @ 779f58f — direct-path __proto__/constructor/prototype + nested-prototype reference invariants 22:29:44Z

Post-execution inventory (API-verified)

  • Open: 8 — #1, #2, #3, #5, #4 (regex/sanitization/identity tranches, held sequence), #9, #10, #13 (holds below)
  • Dismissed: 16 — the 15 above + #27 (earlier, pre-existing)
  • Arithmetic: 23 − 15 = 8 ✓

#9 — read-only disposition (authorized; NOT dismissed, per directive)

  • Alert: js/missing-rate-limiting, single instance, phase4.js:352–359.
  • Flagged handler: GET /audit/verify (audit-chain verification; reads req.query.from/to as integers, calls verifyChain — read-only DB traversal).
  • Mount: phase4Router at app.js:175 (app.use("/api", phase4Router)) — after the limiter (app.js:84) and after apiKeyAuth (app.js:96).
  • Limiter skip list (/health exact, /webhooks prefix) does not match /api/audit/verify.
  • Individual review found no additional bypass surface: same mechanism as the 13 — the query cannot see app-level mounting.
  • Disposition: qualifies for the same false-positive treatment. Dismissal not authorized; returned for decision.

#13 — corrected classification (read-only; NOT dismissed, per directive)

  • Alert location today: app.js:108 — which is app.use(routeAuthObserver). The message aggregates six flows ("This route handler performs authorization, but is not rate-limited." ×6).
  • The earlier matrix's association with the intentionally unthrottled /health endpoint does not match what the alert pins today. The /health route sits at app.js:113; the alert's flagged middleware is the observer at :108. The historical association cannot be carried forward.
  • What the flagged operation actually is: routeAuthObserver (routeAuthObserver.js:225) performs declaration-driven authorization — observe-mode decisions and the W1-03 central enforcement gate (routeAuthObserver.js:98–211). It early-skips /api/auth, /api/bootstrap, /api/setup (routeAuthObserver.js:227–232).
  • Upstream protection: the observer mounts at app.js:108, after the limiter at app.js:84 — every request reaching it has traversed the limiter, and its early-skipped families are exactly the pre-auth families the limiter now keys by IP.
  • Disposition per the stated conditional ("if it concerns a middleware operation already protected by the upstream limiter, it may qualify for the same false-positive treatment"): the evidence supports that reading. It is not a /health risk-acceptance case. Dismissal not authorized; returned for decision.

No-action confirmations

  • #12, #28: fixed states confirmed via API earlier — no manual disposition required or performed.
  • #10: untouched, remains open pending its residual-risk assessment (not a false positive per the directive).

@Alajmah

Alajmah commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

CodeQL #9/#13 dismissal record + #1–#5 read-only verification (no source changes)

#9/#13 dismissal record (authorized 2026-11-21)

| Alert | Pre-check (rule|state|location) | Dismissed at | Reason |
|---|---|---|---|
| #9 | js/missing-rate-limiting|open|phase4.js:352 ✓ | 2026-11-20T23:21:54Z | false positive — full chain rateLimiter(app.js:84)→apiKeyAuth(:96)→routeAuthObserver(:108)→phase4Router(:175)→GET /audit/verify; skip list has no match |
| #13 | js/missing-rate-limiting|open|app.js:108 ✓ | 2026-11-20T23:21:42Z | false positive — flags routeAuthObserver, which mounts after the limiter and skips non-/api + auth/bootstrap/setup; all six flows share one protected path; /health rationale not used |

Inventory after (API-verified): open = 6 (#1–#5, #10), dismissed = 18. Matches the directive's expected table exactly.


#1–#5 read-only verification — order #1→#2→#3→#5→#4

Shared input path for #1–#3 (polynomial-redos, packages/rules/src/reviewSchema.js)

Source/sink trace: all three regexes live in extractReviewJSON(text) (reviewSchema.js:257), the LLM-output JSON-extraction cascade. Callers: aiReviewService.js:346 (extractReviewJSON(rawText), inside the review pipeline), adversarialReview.js:197, adversarialDefense.js:5. Sink = the regex engines at lines 273, 284, 324–325.

Attacker-controlled input: indirect — rawText is the review LLM's completion (bounded max_tokens: 32768, aiReviewService.js:1031). A PR author controls diff content the model reads; prompt injection can coerce the model into echoing a pathological payload (e.g., "repeat this block verbatim"). Output ceiling ≈ 32k tokens ≈ up to ~10⁵ chars; a newline-dense payload fits that budget.

Where it executes: the shared Node process — index.js starts all 14 workers and the Express server in one process, so a blocked event loop stalls every worker plus /health.

#1 — fence regex, single match (line 273)

  • Regex: the fenced-block matcher at line 273: three backticks, optional json, then \s*\n? (greedy any-whitespace + optional newline), lazy [\s\S]*? body, \n?\s*, closing three backticks.
  • Failure mode: the greedy \s* (which matches \n) followed by \n? makes the whitespace bridge ambiguous — the engine re-splits long whitespace runs while the lazy body expands, giving O(n²) per opening-fence occurrence on non-terminating input (e.g., one fence prefix + ~32k \n, no closing fence). At n≈10⁴–10⁵ that is 10⁸–10¹⁰ engine steps — 0.1 s to minutes of blocked loop.
  • Existing protection: none at this site — no length cap, no timeout around the cascade; strategies 1 (direct parse) and 3–5 don't bound it.
  • Smallest safe correction: make the bridge unambiguous — replace both \s* with horizontal-only [ \t]* around the single optional newline. Matches every valid fenced block byte-identically; only pathological whitespace-run inputs change behavior. Plus an adversarial regression asserting the fence + 32k-\n no-close input resolves to failed under a time bound.

#2 — same regex, matchAll (line 284)

  • Failure mode: identical pattern with the global flag; every fence occurrence is an independent start position, multiplying the per-occurrence O(n²) — worst case O(n²·k) for k fence markers.
  • Existing protection: none; reached only when Strategy 1 (direct JSON.parse) already failed.
  • Smallest safe correction: the same character-class fix as deps: bump node from 20-alpine to 26-alpine #1 applied to the global variant (a single shared constant used by both sites would also prevent drift — consistent with the lockstep fix pattern).

#3 — findings-pattern fallback (lines 324–325)

  • Regex: the {"findings": [ ... ], "overall_correctness" matcher at line 324.
  • Failure mode: .match retries the literal {"findings":[ prefix at every index; on the attack input (that prefix repeated to the token ceiling, no completion) each of the ~n/14 occurrences starts a fresh lazy-body expansion → O(n²)-class scanning, same blocked-loop consequence.
  • Existing protection: none; this is the last strategy before failed.
  • Smallest safe correction: anchor to literal occurrences — const at = trimmed.indexOf('{"findings"'); if (at !== -1) then run the existing regex on trimmed.slice(at) (loop over occurrences if exact all-occurrence fallback semantics must be preserved). indexOf is linear with no backtracking; first-match behavior is unchanged for all valid inputs.

#5 — incomplete-sanitization, packages/web/src/services/flakyTestService.js:220

  • Source/sink trace: candidates (flaky-test detections parsed from CI run logs) → buildQuarantineWorkflow (line 208) → line 220 builds the generated GitHub Actions YAML's shell command: --testNamePattern="<testFilter>" where testFilter joins each candidate's test_suite + " > " + test_name with |, and the ONLY escape is replace(/"/g, '\\"').
  • Attacker-controlled input: direct, with gates. Test names come from the repository's own CI output. A PR author can add a deliberately flaky test (random pass/fail) whose name contains a backslash — e.g. a name embedding \" — which survives into candidates after the flakiness window, then into the generated workflow.
  • Demonstrated failure mode: escaping " without first escaping \ breaks on input containing \": the source pair becomes \\" in the generated command, where \\ collapses to a literal backslash and the following " terminates the shell's double-quoted string early — the remainder of the test name runs as shell syntax in the Actions runner when the quarantine workflow executes. Even with \ fixed, $ and backtick still expand inside double quotes, so both are injection vectors too.
  • Existing protection: quote-escaping (incomplete by definition of this alert); the quarantine workflow ships as a bot-opened PR, so a human merge is a gating control — but the YAML is auto-generated boilerplate a reviewer is unlikely to line-read.
  • Smallest safe correction: escape backslash first, then the double-quote-context metacharacters: replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\$/g, "\\$") plus backtick — or switch the generated command to single-quote wrapping with '\'' escaping. Regression: adversarial test-name fixtures (\", $(), backtick, backslash) asserting the generated YAML contains no unescaped metacharacters, plus valid-name fixtures proving output unchanged.

#4 — identity-replacement, packages/web-dashboard/src/app/custom-rules/page.tsx:63

  • Source/sink trace: API.repoConfig(owner, repo) (api.ts:124) returns /api/config/${owner}/${repo} — which already contains /api/config/. Line 63 then calls .replace("/api/config/", "/api/config/") — a self-replacement, the exact pattern js/identity-replacement flags — and appends /custom-rules.
  • Verified current behavior: the replace is a byte-level no-op; the resulting URL /api/config/{owner}/{repo}/custom-rules correctly resolves against the live backend route configRouter.get("/:owner/:repo/custom-rules") (config.js:238). No functional bug today.
  • Attacker-controlled input / failure mode: none — the replaced value is a compile-time constant; the alert is a code-smell query (self-replacement marks an unfinished edit or dead code). Residual risk is maintenance-only: a reader assumes a transformation is happening, or a future intended prefix change gets "fixed" into the wrong slot.
  • Existing protection: none needed — the value is static.
  • Smallest safe correction: delete the self-.replace call entirely (provably behavior-identical); no regression beyond the page's existing tests.

Proposed remediation order when implementation is authorized

#1+#2 as one unit (same constant, two call sites) → #5 (escaping + adversarial YAML regressions) → #3 (anchor + timing regression) → #4 (dead-code deletion). Each as its own PR with targeted adversarial regressions; valid-input behavior preserved by construction in every case. No implementation started — verification only, per the directive. #10's residual-risk assessment and the held queue (differential gate, 421-D, W3-03) are unchanged.

@Alajmah

Alajmah commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

CodeQL #10 — bounded residual-risk assessment of the /webhooks/github ingress path (read-only; no config changed)

Per the directive: controls verified in production are distinguished from defaults merely assumed; the assessment ends with a recommendation for the maintainer's decision — retain the exception with formally accepted residual risk, or a narrowly scoped compensating control.

1. Controls verified in production (this session, against 89d5e51)

Control Verification
25 MiB streaming body cap Deployed via #457; actual-byte counting, declared-length early-out, drain-without-buffering on rejection; 14-test suite including late-stream-error and listener-preservation regressions
Early header rejection Live-probed: POST without the GitHub header set → 400 {"error":"Missing required webhook headers"} in 0.28 s — the cheapest rejection path fires before any HMAC work
HMAC signature gate Live-probed: complete header set + bogus signature → 401 in 0.27 s; route order confirmed in source (webhooks.js:38 header check → :52 verifyAndReceive → 401) — no DB, Redis, or GitHub-API work occurs before HMAC passes
Ingress topology gitwire-app publishes no host ports (PortBindings {}) — the only ingress is the cloudflared tunnel (plus the LAN); Cloudflare edge confirmed in path (CF-RAY, Server: cloudflare)
Limiter exemption By design (rateLimiter skips /webhooks) — GitHub HMAC-authenticated deliveries; this exemption is the alert's subject

2. Request and connection timeouts (verified, not assumed)

Production runs Node 20.20.2; index.js performs a plain app.listen with no timeout overrides, so the platform defaults bind: headersTimeout 60 s (slowloris bounded), requestTimeout 300 s (a slow-drip body is killed at 5 minutes — the maximum socket-hold per request), keepAliveTimeout 5 s. These are Node's documented defaults for the verified version, not app-level configuration.

3. Concurrent-request exposure

Single Node process (Express + all 14 workers). No container resource limits (Memory=0, NanoCpus=0, no PidsLimit); fd ceiling 1024 — concurrent sockets are bounded by file descriptors, not configuration. No per-source concurrency limit at the application layer. Bandwidth for all external traffic transits the single cloudflared container.

4. Resource cost of accepted bodies approaching 25 MiB

  • Rejected (over-cap): memory bounded — the body is drained without buffering; cost is byte transit + counting.
  • Complete bodies: an HMAC sha256 over ≤25 MiB (tens of ms CPU), and a ≤25 MiB buffer exists only for bodies that streamed to completion. A 25 MiB buffered body requires completing the stream — any attacker can do that, but it then hits the 401 (bogus signature) and the buffer is released; genuine 25 MiB accepted payloads require the webhook secret, whose holder is trusted. Real GitHub payloads are KB-scale.
  • Downstream isolation: PostgreSQL (pool max 20), Redis, and the GitHub API are untouched until HMAC passes — verified by route order and the live 401.

5. GitHub delivery reliability requirements (external documentation, not host-verified)

GitHub retries failed and timed-out deliveries automatically, and manual redelivery exists. Consequence for any control: a rate limiter placed in front of /webhooks returns 429s to legitimate deliveries under burst (e.g., an event storm from a mass-PR wave), interacting with retry/backoff and potentially delaying or dropping real events. The exact retry policy should be cited from GitHub's docs at decision time; nothing in this assessment depends on its precise parameters.

6. Can repeated unauthenticated requests still consume material resources despite the cap?

Yes — bounded per request, unbounded in aggregate. Per request: ≤25 MiB transit + counting + (on completion) one HMAC pass; no memory accumulation, no downstream work. Aggregate: nothing at the application layer bounds the rate or concurrency of such requests; a flood consumes tunnel bandwidth and CPU and can occupy up to ~1024 concurrent sockets. Cloudflare edge protections (WAF/rate rules/bot mitigation) sit in front but are not verifiable from the host — these are operator-dashboard verification items:

  • zone WAF managed rules / custom rules for gitwire.erlab.uk
  • zone rate-limiting rules
  • bot fight mode / TLS minimums

7. Recommendation (for the maintainer's decision)

Retain the exception with formally accepted residual risk. Rationale: the residual is bandwidth/CPU-only — bounded memory, zero pre-HMAC downstream work, no state corruption, self-recovering; the deployment is single-operator behind a Cloudflare edge; and the main alternative (a rate limiter on /webhooks) has a demonstrated interaction with legitimate-delivery retries.

If a control is nonetheless wanted, the narrowly scoped option that does not touch delivery rates: an in-flight streaming concurrency cap on /webhooks only (reject with 503 when more than N webhook bodies are streaming concurrently, N ≈ 8–16). It bounds aggregate flood cost while leaving sequential delivery bursts and retries unaffected. This is a design sketch, not an authorized implementation.

No dismissal action is taken on #10 either way — it remains open pending the maintainer's explicit decision between formal risk acceptance (with this assessment as the record) and the compensating-control unit.

@Alajmah

Alajmah commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

CodeQL #10 — CORRECTION to the residual-risk assessment (supersedes §4 and §6 of comment 7053523524; recommendation revised)

My earlier assessment contained a material error, and the maintainer's correction is confirmed against the deployed source. I claimed memory "does not accumulate before a request completes" and that the residual was "bandwidth/CPU-only." That is wrong for the accepted-body path.

What the deployed implementation actually does (verified at master 89d5e51, webhooks.js → express_raw_body_middleware())

  • Over-cap rejection path only: rejected bodies are drained without buffering — my statement was true there and only there.
  • Under-cap bodies: every accepted chunk is pushed to a chunks[] array and retained in memory until the request ends (the buffer is needed for HMAC). At completion, Buffer.concat(chunks) transiently allocates a second buffer of comparable size. The 25 MiB cap therefore bounds memory per connection, not in aggregate.
  • HMAC rejection does not protect the resources consumed before verification — a bogus-signature request buffers its full body first, then gets the 401. Verified live earlier: the 401 path works, but it works after the buffering.

Corrected exposure math (production figures)

Factor Value
Host memory (CT 115) 16 GiB total, ~15 GiB available (containers idle at ~650 MiB combined)
Container memory limit none (Memory=0) — exhaustion lands on the kernel OOM killer, which can take any service, not just the app
Per-connection retention up to 25 MiB (chunk array) + transient ~2× at Buffer.concat
Concurrency ceiling fd limit 1024 (≈ upper bound on concurrent bodies; each request also occupies a tunnel socket)
Per-request maximum hold 300 s (requestTimeout, Node default — verified no override)

An unauthenticated flood holding ~600 concurrent near-cap bodies approaches the 16 GiB host budget; a sustained drip-pace flood (each body transmitted slowly within the 300 s window) maintains that working set indefinitely. The fd ceiling bounds this below the naive ∞ but is not a memory-exhaustion control at these sizes — agreeing with the maintainer's analysis. This is a genuine memory-exhaustion vector, not bandwidth/CPU-only.

What stands unchanged from the verified-controls table

Node 20.20.2 with default timeouts; no published ports (tunnel-only ingress); Cloudflare edge in path (CF-RAY); 400/401 live probes; DB/Redis/GitHub-API untouched before HMAC; GitHub retry interaction argument. Cloudflare zone-side protections remain unverified from the host — if the zone has effective rate/concurrency controls, the flood math above changes materially; that verification is an operator-dashboard action.

Revised recommendation (for the maintainer's decision)

Formal risk acceptance is not supported by the current record — the previous recommendation is withdrawn. The options that survive the corrected math:

  1. Narrow compensating control (now materially justified): in-flight webhook-body concurrency cap — reject with 503 when more than N webhook bodies are concurrently streaming/buffered. Sized by budget: N=16 bounds worst-case webhook buffering to ~400 MiB (+ concat transients) on the 16 GiB host; N=64 to ~1.6 GiB. Sequential legitimate deliveries (GitHub's burst/retry pattern is sequential per hook) are unaffected at any of these N. Threshold + GitHub behavior verification = separate implementation decision, per the directive.
  2. Alternative/complementary: reduce the per-connection cap. Real GitHub webhook payloads are KB-scale; 25 MiB was already generous. A 4 MiB cap cuts the worst-case aggregate 6×. Changes the deployed fix(10): streaming 25MiB webhook body cap — explicit disposition, swallowed late errors, no blanket listener removal #457 contract — separate decision.
  3. Retain-with-acceptance only after (a) Cloudflare zone-side protections are verified effective by the operator, or (b) the maintainer explicitly accepts memory-exhaustion DoS as within the threat model for this single-operator deployment.

No dismissal or configuration change made; #10 remains open.

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