fix(prettify): replace regex-based query parsing to avoid ReDoS #2447
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Checklist (per Contribution Guidelines)
Target branch is master
Only source files are modified (st/prettify/run_prettify.js)
No build artifacts are committed (builds will be generated on release)
Local setup: npm i completed
Verified locally that the change works as expected
Background
In st/prettify/run_prettify.js, the query string was parsed via a global regex replace:
This pattern can suffer from catastrophic backtracking on crafted inputs (e.g. '?'.repeat(100000) + '=') and leads to a potential ReDoS risk if the query is attacker-controlled.
Solution
Replace the regex-based parsing with a linear, index-based split that preserves behavior but avoids backtracking:
Why safer: No backtracking hotspots; runtime grows linearly with input length.
Behavior: Keys handled are unchanged (autorun, lang, skin, callback); invalid pairs are ignored just like before; decodeURIComponent preserved.
Screenshots
before:


after:
Type of change
Bug fix (non-breaking change which fixes an issue)
Notes
If the project prefers tests to be in its existing framework only, I can adjust or remove the accompanying regression test.