[ENG-4059] Screen the scaffolded rule sets in the regex cost gate - #307
Merged
Merged
Conversation
The regex cost gate now screens every regex the package ships: the compiled defaults plus the rule sets the installer scaffolds (`rules.json`, and `demo-rules.json` for `protect --demo`). Each clause has a declared worst case. Two demo patterns did not stay within the budget and are rewritten to stay linear with the same demo behaviour: - the response email pattern now has bounded parts and must start at the beginning of a local part; - the XXE pattern bounds the text between `<!DOCTYPE` and `SYSTEM`. `screenPatternCost` takes `derive: false` for a pattern whose derived candidate matches it; the test checks that each such clause's derived candidate really does match. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Adds derive flag support and screens scaffolded rule sets with thorough tests. 🎯 Quality: 100% Elite · 📦 Size: Medium 📈 This month: Your 158th PR — above team average · Averaging Elite |
daniloradovic
approved these changes
Sep 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The regex cost gate measures how long each pattern takes to reject its worst input at the size it may really be run against. Until now it covered only the compiled-in default rules. It now covers every regex the package ships, including the rule sets the installer scaffolds into an app:
rules.json, the offline starter set;demo-rules.json, the setprotect --demowrites.Every clause has a declared worst case.
Two demo patterns did not stay within the budget, so they are rewritten to stay linear:
<!DOCTYPEandSYSTEMis bounded to 256 characters, and the pattern now scales linearly with input size.Every demo still blocks or redacts its exploit and lets its benign twin through: the demo rule tests and
scripts/run-demos.mjsboth pass. The example bundle and the scaffolded template stay identical.Tool change.
screenPatternCostacceptsderive: false. The heuristic that derives a candidate reads a pattern as one sequence, so for a top-level alternation or a repeated group it can build an input the pattern matches. That would invalidate the screening. The gate lists those clauses explicitly, and a test checks that each listed clause's derived candidate really does match, so the list can't switch off a useful measurement.Validation:
scripts/run-demos.mjs.🤖 Generated with Claude Code