Skip to content

test(v4): stop redos tests failing on CPU contention - #6360

Open
irfanfandi wants to merge 1 commit into
colinhacks:mainfrom
irfanfandi:fix-redos-flake
Open

test(v4): stop redos tests failing on CPU contention#6360
irfanfandi wants to merge 1 commit into
colinhacks:mainfrom
irfanfandi:fix-redos-flake

Conversation

@irfanfandi

Copy link
Copy Markdown

Fixes #6359.

Both tests in redos.test.ts decide pass/fail from wall-clock timing, so CPU contention from parallel test files flips them. On ead9fcb3 the file failed in 2 of 6 full-suite runs and passed every time it ran alone, which also makes the pre-push hook reject unrelated pushes.

no built-in pattern is ReDoS-vulnerable treated any non-safe status as a failure. unknown only means the checker gave up, and recheck's fuzz checker derives vulnerable from how long an attack string runs — so the verdict tracks available CPU rather than the pattern. Squeezing attackTimeout reproduces it on an idle machine, non-monotonically:

fuzz  extendedDuration  10000ms=unknown  1000ms=vulnerable  100ms=vulnerable  10ms=vulnerable
auto  email             10000ms=safe     1000ms=vulnerable  100ms=vulnerable  10ms=safe

The flagged patterns are fine — matched against adversarial input they scale linearly and stay under a millisecond out to 6.4KB. So this now ignores unknown and re-confirms a vulnerable verdict with a generous budget before failing. A genuinely exponential pattern exhausts any budget, so detection is unchanged: ^(a+)+$, ^(a|a)*$, ^([a-zA-Z0-9]+)*@x$ and ^(\w+\s?)*$ are all still caught.

emoji rejects a backtracking payload in linear time asserted a 100ms budget on a single cold call. The fixed pattern matches that payload in ~0.2ms and stays flat out to 200 emoji, so the threshold sat in JIT and scheduler noise while the regression it guards against took ~1.9s. It now warms up, takes the best of three, and allows 500ms — still three orders of magnitude below the exponential case.

Both tests in redos.test.ts decided pass/fail from wall-clock timing, so
load from parallel test files flipped them. The file failed in 2 of 6
full-suite runs on a clean main and passed every time it ran alone.

The pattern sweep treated any non-"safe" status as a failure. "unknown"
only means the checker gave up, and recheck's fuzz checker derives
"vulnerable" from how long an attack string runs, so the verdict tracked
available CPU rather than the pattern. Ignore "unknown" and re-confirm a
"vulnerable" verdict with a generous attackTimeout before failing; a
genuinely exponential pattern exhausts any budget, so detection is
unchanged.

The emoji test asserted a 100ms budget on a single cold call, which sat
in JIT noise given the pattern matches in ~0.2ms. Warm up, take the best
of three, and allow 500ms.
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.

redos.test.ts is flaky: both tests decide from wall-clock timing

1 participant