Skip to content

Commit 7d32f66

Browse files
committed
fix(antigravity): drop the backtracking trailing-slash regex
The final audit of this campaign found a high-severity CodeQL alert the campaign itself introduced: js/polynomial-redos at antigravity-models.ts:273, from 93694a3 via lidge-jun#1897, already promoted to main. baseUrl.trim().replace(/\/+$/, ) backtracks polynomially on a long run of trailing slashes. The input is provider config rather than hostile traffic, so the practical risk is low - but not-hostile-today is a property of the caller rather than of this function, and a linear scan costs nothing. stripTrailingSlashes is byte-identical to the regex across the edge cases: empty string, all slashes, no trailing slash, interior slashes. Also corrects the closeout: lidge-jun#1899 is a pull request closed unmerged, not an issue, so this campaign closed two issues rather than three. The root cause is worth keeping. lidge-jun#1897 merged on local focused tests plus tsc, which substitutes for CI on behavior and silently skips static analysis. Gating once at the end is a reasonable trade for speed, but the end-gate I ran does not include CodeQL, so this class of finding was exactly what the trade gave up.
1 parent 8c2b5ed commit 7d32f66

2 files changed

Lines changed: 41 additions & 3 deletions

File tree

‎devlog/_plan/260817_wave5_execution/090_wave6_closeout.md‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ Promoted through PRs, since `preview` and `main` both carry protection rulesets:
197197
| 5C | #1900, #1895 (via #1951), #1953 |
198198
| 5D | #1897, #1891, #1955, #1960, #1961 |
199199

200-
Issues closed: **#1894, #1843, #1899**.
200+
Issues closed: **#1894 and #1843**. (#1899 is a *pull request* closed unmerged, superseded by
201+
#1923 — it belongs in the PR column, not the issue count. Two issues closed, not three.)
201202

202203
Four of those PRs did not exist when the campaign started. They came out of auditing the plan
203204
rather than executing it: #1951 and #1953 (code mode decided by tool semantics rather than the
@@ -242,3 +243,26 @@ That is a real gap in the local-verification substitute, not a one-off.
242243
Severity in context: the input is a configured `baseUrl`, so exploitation needs a hostile or
243244
careless config rather than attacker-controlled traffic. Worth fixing, not urgent. Separately,
244245
the repository carries **71** open alerts that genuinely predate this work.
246+
### CodeQL alert this campaign introduced — found post-promotion, fixed
247+
248+
The final audit found a high-severity CodeQL alert that **this campaign added and promoted**:
249+
alert #87, `js/polynomial-redos`, at `src/providers/antigravity-models.ts:273`, introduced by
250+
`0be660a2e` via #1897 and now on `main`.
251+
252+
`baseUrl.trim().replace(/\/+$/, "")` backtracks polynomially on a long run of trailing slashes.
253+
The input is provider config rather than hostile traffic, so the practical risk is low — but
254+
"not hostile today" is a property of the caller, not of the function, and a linear scan costs
255+
nothing. Replaced with `stripTrailingSlashes`, verified byte-identical to the regex across the
256+
edge cases (empty string, all-slashes, no trailing slash, interior slashes).
257+
258+
**The root cause is a process one and belongs in the record.** #1897 merged on local focused
259+
tests plus `tsc`. That substitutes for CI on the axis it covers — behavior — and silently skips
260+
the axis it does not: static analysis. Waiting for full CI would have surfaced this before it
261+
reached `main`. The instruction for this run was to stop waiting on per-PR CI and gate once at
262+
the end, which is a reasonable trade for speed; the honest accounting is that it traded away
263+
exactly this class of finding, and the end-gate I ran (`bun test`, `typecheck`, `privacy:scan`)
264+
does not include CodeQL.
265+
266+
For context rather than excuse: the repository carries 71 open alerts, 65 of them high or
267+
critical. This is one of many — but it is one this campaign put there, so it gets fixed here
268+
rather than added to the pile.

‎src/providers/antigravity-models.ts‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,28 @@ interface DiscoveredWireModelMapping {
268268

269269
const discoveredWireModelsByBaseUrl = new Map<string, DiscoveredWireModelMapping>();
270270

271+
/**
272+
* Strip trailing slashes without a backtracking regex.
273+
*
274+
* `/\/+$/` is polynomial-ReDoS on attacker-influenceable input (CodeQL js/polynomial-redos):
275+
* a long run of slashes makes the engine retry every suffix. The base URL comes from provider
276+
* config, which is not hostile in the ordinary case — but "not hostile today" is a property of
277+
* the caller, not of this function, and a linear scan costs nothing.
278+
*/
279+
function stripTrailingSlashes(value: string): string {
280+
let end = value.length;
281+
while (end > 0 && value.charCodeAt(end - 1) === 47) end -= 1;
282+
return end === value.length ? value : value.slice(0, end);
283+
}
284+
271285
function antigravityBaseUrlKey(baseUrl: string | undefined): string | undefined {
272286
if (typeof baseUrl !== "string" || !baseUrl.trim()) return undefined;
273-
const trimmed = baseUrl.trim().replace(/\/+$/, "");
287+
const trimmed = stripTrailingSlashes(baseUrl.trim());
274288
try {
275289
const url = new URL(trimmed);
276290
url.hash = "";
277291
url.search = "";
278-
return url.toString().replace(/\/+$/, "").toLowerCase();
292+
return stripTrailingSlashes(url.toString()).toLowerCase();
279293
} catch {
280294
return trimmed.toLowerCase();
281295
}

0 commit comments

Comments
 (0)