feat(severity): reduce false positives for lateral refactors within pattern families - #1
Merged
Merged
Conversation
…hin a family Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
vincentbasp
approved these changes
Jun 16, 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.
Summary
When a dependency upgrade refactors code to use a semantically equivalent API (e.g. replacing
__import__()withimportlib.import_module()), lockscan previously flagged the new hits at full severity without considering that the old pattern's count dropped. This produced HIGH findings for what is effectively a code quality improvement with no net increase in attack surface.This PR introduces two improvements:
Pattern family grouping with net-delta severity (severity.ts): Labels that represent the same underlying capability are grouped into families (
dynamic-import,eval,shell,deser). When a delta hit belongs to a family, the effective severity is only escalated if the family's net hit count grew meaningfully — beyondmax(3, 20% of old count). A marginal net increase (as seen whenexec:__import__drops whileexec:importlibrises by roughly the same amount) is treated as a lateral refactor and downgraded tolow.criticalpatterns are never downgraded.Per-label old→new breakdown in the text report (report.ts): The
SECURITY SCANsection now opens with aby pattern (old → new, net):table showing count changes across all labels, making substitution patterns immediately legible without manually diffing the old/new hit lists.Motivation
A
pytest9.0.3 → 9.1.0 upgrade was triggering a HIGH finding due to 6 newexec:importlibhits introduced by an internal refactor that simultaneously reducedexec:__import__from 8 to 3 hits. The family net delta was +1 — well below the threshold — so with this change it correctly resolves to LOW.Test plan
pytestfrom 9.0.3 to 9.1.0 — overall severity should drop from HIGH to LOWpnpm tsc --noEmitpasses🤖 Generated with Claude Code