From 2286113d9154d1016e79c2de6dabdf451ac104f6 Mon Sep 17 00:00:00 2001 From: Brett Bartrum <17114576+bartrumb@users.noreply.github.com> Date: Sun, 29 Nov 2026 16:32:53 -0600 Subject: [PATCH] test(hub): best-of-5 samples for the M7 postExtractHtml ReDoS budgets The M7 Challenger Iteration 2 test timed each hostile postExtractHtml call once against an unscaled 5ms budget while other test files shared the runner's CPUs. On the v2.8.33 release PR, whose diff is only version strings and the changelog, one sample took 9.75ms. These checks now use assertFastUnscaledSync, the shared helper the other unscaled budgets use: same 5ms budget, best of up to 5 samples. The WAF checks in the same test already took the best of 5. A super-linear scan still fails every sample. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Brett Bartrum <17114576+bartrumb@users.noreply.github.com> --- hub/test/m7-core-regressions.test.ts | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/hub/test/m7-core-regressions.test.ts b/hub/test/m7-core-regressions.test.ts index 58a450a..85f41e0 100644 --- a/hub/test/m7-core-regressions.test.ts +++ b/hub/test/m7-core-regressions.test.ts @@ -20,6 +20,7 @@ import { } from '../src/scrape'; import { executeExtractCall } from '../src/search-index'; import { classifyWafAndChallenge } from '../src/waf'; +import { assertFastUnscaledSync } from './perf-budget'; import { postExtractHtml } from './post-fetch-wasm'; test('M7 Task 3: encodeBodyForWire and Hub scrape/extract decode ISO-8859-1 HTML while still rejecting real binary payloads', async () => { @@ -1259,22 +1260,18 @@ test('M7 Challenger Iteration 2: linear ReDoS immunity in unhydratedCsrShell, po ['20k
', hostileDivsClosed], ['BOM JSON + 50k <', bomJsonHostile], ] as const) { - const t0 = performance.now(); - const out = postExtractHtml(payload, 'https://example.com/', ''); - const dt = performance.now() - t0; + // Same 5ms budget (unscaled); best of up to 5 samples, like the WAF checks below, so one sample delayed by the + // other test files sharing the runner's CPUs does not fail it, while a super-linear scan fails every sample. + const out = assertFastUnscaledSync(`postExtractHtml(${label})`, 5, () => + postExtractHtml(payload, 'https://example.com/', ''), + ); assert.equal(out, null, `expected null for ${label}`); - assert.ok(dt < 5, `postExtractHtml(${label}) took ${dt.toFixed(2)}ms (>= 5ms)`); } - const tJson0 = performance.now(); - const sramJsonOut = postExtractHtml( - bomJsonHostile, - 'https://docs.sram.com/en-US/publications/7E6x3h', - '', + const sramJsonOut = assertFastUnscaledSync('postExtractHtml(BOM JSON)', 5, () => + postExtractHtml(bomJsonHostile, 'https://docs.sram.com/en-US/publications/7E6x3h', ''), ); - const dtJson = performance.now() - tJson0; assert.equal(sramJsonOut, null); - assert.ok(dtJson < 5, `postExtractHtml(BOM JSON) took ${dtJson.toFixed(2)}ms (>= 5ms)`); for (const [label, body] of [ ['20k