Add fast-check property tests for injection-pattern rules#138
Merged
Conversation
Covers `attribute-injection-sanitize` and `meta-injection-strip`. Both rules consult the shared injection-pattern set, so the new properties exercise that pattern set through every surface each rule scrubs. attribute-injection-sanitize: fuzzes (allowlisted attribute) × (shared injection fixture) × (random non-injection prefix/suffix with explicit whitespace boundaries). Negative properties confirm non-allowlisted attributes (`data-foo`, `name`) and enabled `<input value>` are preserved. meta-injection-strip: removes any `<meta content>` carrying an injection payload regardless of name attribute convention (`name`/`property`/`itemprop`/`http-equiv`), and blanks `<title>` text while keeping the element so `document.title` still returns a string. Benign meta/title content is preserved. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Summary
Property tests for both rules that consume
INJECTION_PATTERNS:attribute-injection-sanitize— fuzzes (allowlisted attribute) × (shared injection fixture) × (random non-injection noise). Negative properties confirm non-allowlisted attributes (data-foo,name) and enabled<input value>are preserved; clean values on allowlisted attributes survive.meta-injection-strip—<meta>is removed regardless of which name convention identifies it (name/property/itemprop/http-equiv);<title>is blanked but the element is kept (sodocument.titlekeeps returning a string); benign content is preserved.Finding worth noting
While building these I hit one shrunk counterexample worth surfacing for a separate discussion (not addressed in this PR): the injection regex set anchors with
\b, so a payload concatenated against a leading/trailing word character (e.g.aria-label="0Ignore all previous instructions...") slips past the regex. Whether that's a sanitizer tightening opportunity or working-as-intended is a separate call — this PR constrains its fuzzer to whitespace-boundary contexts, matching the documented intent. Worth a real-world page sample before deciding.Test plan
bun run preflight— biome, eslint, tsc (src + tests), knip, jest with coverage (1028 tests).🤖 Generated with Claude Code