esm: avoid super-linear data URL MIME regex - #61951
Conversation
|
Review requested:
|
jsumners-nr
left a comment
There was a problem hiding this comment.
Where are tests to assert the undesired behavior is resolved by the changes?
|
Added regression coverage in The test exercises |
| // Flags: --expose-internals | ||
| 'use strict'; | ||
|
|
||
| const common = require('../common'); | ||
| const assert = require('assert'); | ||
| const { defaultGetFormat } = require('internal/modules/esm/get_format'); | ||
|
|
||
| // Regression test for #61904. This malformed data URL path is crafted to | ||
| // stress the MIME regex without triggering URL parsing failures. | ||
| const longPath = `data:a/${'a'.repeat(2 ** 17)}B`; | ||
| const start = process.hrtime.bigint(); | ||
| const format = defaultGetFormat(new URL(longPath), { parentURL: undefined }); | ||
| const elapsedMs = Number(process.hrtime.bigint() - start) / 1e6; | ||
|
|
||
| assert.strictEqual(format, null); | ||
| assert.ok( | ||
| elapsedMs < common.platformTimeout(1000), | ||
| `Expected format detection to complete quickly, took ${elapsedMs}ms`, | ||
| ); |
There was a problem hiding this comment.
This is going to be inherently flaky, could we instead write a benchmark?
|
CI has not started yet on this PR (currently no check runs, and Could a collaborator please add the |
|
There are no official approvals on this PR, so CI cannot be started (it will refuse). |
|
Replaced the timing-based regression test with a benchmark ( Could a collaborator add |
bd04ddd to
3487338
Compare
|
Squashed into a single signed commit and force-pushed — the diff is unchanged (regex fix in Doing this pre-emptively since @trivikr flagged the same missing |
|
check the commit lint |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #61951 +/- ##
==========================================
+ Coverage 88.84% 90.14% +1.30%
==========================================
Files 674 746 +72
Lines 204957 242818 +37861
Branches 39309 45766 +6457
==========================================
+ Hits 182087 218891 +36804
- Misses 15088 15420 +332
- Partials 7782 8507 +725
🚀 New features to boost your workflow:
|
The MIME regex used for data: URLs could backtrack super-linearly on a malformed URL lacking a ',' separator. Make the optional parameter group anchored on ';' so it cannot overlap with the media-type group. Adds a benchmark (esm/get-data-protocol-format) parameterized over path length, so a backtracking regression shows up as an ops/sec cliff instead of a wall-clock assertion in a test, per review. Fixes: nodejs#61904 Signed-off-by: skdas20 <skdas5405@gmail.com>
|
Thanks @mcollina — |
3487338 to
cf0eb3b
Compare
|
Status summary for whoever picks this up: the PR is approved, and the Could a collaborator add |
Fixes: #61904
This updates ESM data URL MIME extraction regexes to remove overlapping quantifiers that allow super-linear backtracking.
(?:[^,]*?)(;base64)?,with(?:;[^,]*)?,in:lib/internal/modules/esm/get_format.jslib/internal/modules/esm/load.jsBehavior is preserved for existing valid/invalid
data:URL shapes while avoiding pathological backtracking on crafted inputs.