xgrep-rule-creator: the cost model for taint rules - #13
Merged
Conversation
A rule can pass every test and still be a defect. The skill covered correctness
thoroughly and said nothing about what a rule costs to run, so "Step 5: Optimize"
was about simplifying patterns rather than about runtime.
Adds the one thing a rule author can act on at authoring time: engines pre-filter
candidate files using the literal tokens in the SINK pattern, and that gate dies
silently when the sink is punctuation or a short type keyword. When it cannot
engage, cost is driven entirely by how often the SOURCE matches — so the
pathological shape needs both halves:
a source that matches everywhere + a sink with no distinctive literal
Either alone is fine. A broad source is cheap when the sink gates; a syntax-only
sink is cheap when the source is rare.
- SKILL.md: a new anti-pattern showing the shape (`& $V` into `*((int*)$P)`,
whose sink yields no usable token), and a new rationalization to reject —
"it passes the tests, so it's done".
- workflow.md Step 5: how to measure with `--time`, why seconds-per-finding is
the sort key rather than total time, and three questions to ask before
shipping a taint rule.
Also records the guardrail that matters when acting on this: a rule that finds
nothing may be CORRECT — the flaw may simply be absent. What is wrong is the cost
of reaching that answer, so the fix is to make the negative answer cheap, never
to delete or weaken the rule.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Review feedback on #13. The snippet used a chained conditional whose None branch worked only by accident of evaluation order: per = 'INF' if n == 0 else ('%.2fs' % (...) if n else '-') For n=None the first test is False and the second is falsy, so it printed '-' — the right answer, reached by luck rather than intent, and it breaks the moment someone reorders the branches. Made explicit, and the distinction named in a comment: a missing findings count means the binary did not report one; zero means the rule ran and found nothing. Those are different answers and the whole point of the ranking is to notice the second. Verified for all three inputs (5 / 0 / absent). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
chris-rock
force-pushed
the
docs/taint-rule-cost-model
branch
from
August 23, 2026 10:51
107b1d5 to
bd67c07
Compare
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 skill covers correctness thoroughly and says nothing about what a rule costs to run — "Step 5: Optimize" is about simplifying patterns, not runtime. So a rule can pass every test in the workflow and still be a defect.
What's added
The one thing an author can act on at authoring time: engines pre-filter candidate files using the literal tokens in your sink pattern, and that gate dies silently when the sink is punctuation or a short type keyword. When it can't engage, cost is driven entirely by how often the source matches.
So the pathological shape needs both halves:
Either alone is fine — a broad source is cheap when the sink gates, and a syntax-only sink is cheap when the source is rare. That conjunction is the part that isn't obvious.
SKILL.md& $Vflowing into*((int*)$P)— a sink whose only token isint, too short and common to filter onreferences/workflow.md(Step 5)--timeand a snippet that ranks rules by seconds-per-findingThe guardrail
Recorded explicitly, because acting on this data invites the wrong fix:
Notes
main(has xgrep-rule-creator: document the silent-failure anti-patterns #11) and applied surgically rather than overwriting, since my working copy predated that work.🤖 Generated with Claude Code