feat(scan): weak-crypto rules for Python — coverage 65.9% → 71.3% (v0.9.0) - #102
Merged
Conversation
…e seed)
Raises detection coverage against the testbed from 65.9% to 71.3% (85 to 92 of
129), false-positive rate still 0%. The CWE-327/338 cluster was the largest
recoverable gap: primitives threatcrush had generic rules for, but scoped to a
credential on the matched line, so Python's integrity- and confidentiality-use
cases slipped through.
Three Python rules, each keyed on a signal that survives without trusting a
name:
- py-broken-cipher: DES/RC2/RC4/Blowfish construction, and AES in ECB mode.
No safe use, so inherent — flagged wherever it appears. AES matches only on
ECB, leaving GCM/CTR/CBC alone.
- py-weak-hash: hashlib.md5/sha1, unless the line carries Python's own
`usedforsecurity=False` opt-out for a non-security digest.
- py-predictable-random-seed: random.seed() from the clock or pid, which
makes the whole sequence reproducible. A fixed integer seed (reproducible
tests) is left alone.
What is deliberately NOT added: a rule for a `random`-drawn token whose only
signal is the enclosing function name (`generate_session_id`). Guard windows
exclude definition lines on purpose — a name is not evidence, the same reason a
`def sanitize_…` does not count as sanitisation — so there is no line-level
signal to key on. The generic `insecure-randomness-for-secret` still catches
the common `token = …random…` shape. Those name-only cases are the documented
tail, pinned by a test that asserts they stay silent.
The coverage gate floor moves 60 to 68 to lock the gain in; a regression below
the new baseline now fails the job. No new findings on capacitor (10,
unchanged) or the self-scan (67, unchanged) — the rules are Python-only and
precise. 141 tests, up from 134.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
ThreatCrush Security Scan67 finding(s) HIGH/CRITICAL: 11 | MEDIUM: 55 | LOW: 1
…and 17 more. Full results in the Security tab. Snippets are redacted; ThreatCrush never prints matched credential material. |
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.
Release 0.9.0. Raises detection coverage against the testbed from 65.9% → 71.3% (85 → 92 of 129), false-positive rate still 0%.
The gap
The CWE-327/338 cluster was the largest recoverable miss — primitives threatcrush had generic rules for (
weak-hash-on-credential,insecure-randomness-for-secret), but scoped to a credential on the matched line. Python's integrity- and confidentiality-use cases carry the security role in the enclosing function, not on the line, so they slipped through.Three Python rules
Each keyed on a signal that survives without trusting a name:
py-broken-cipherDES/RC2/RC4/Blowfish.new(...),AES.new(..., MODE_ECB)inherent; AES matches only on ECB, GCM/CTR/CBC left alonepy-weak-hashhashlib.md5/sha1(...)usedforsecurity=Falsepy-predictable-random-seedrandom.seed(<clock/pid>)What I deliberately did not add
A rule for a
random-drawn token whose only signal is the enclosing function name (generate_session_id,generate_mfa_code). Guard windows exclude definition lines on purpose — a name is not evidence, the same reason adef sanitize_…doesn't count as sanitisation. There's no line-level signal left to key on, so forcing it would mean either trusting names (a documented regression risk) or shape-heuristics that add false positives for marginal gain.The generic
insecure-randomness-for-secretstill catches the common real shape (token = "".join(random.choice(...))). The name-only cases are the documented tail, pinned by a test asserting they stay silent. Honest boundary, not an oversight.Verification
tsc --noEmitclean.The debugging that shaped this is worth a line: my first attempt keyed the PRNG rule on a credential term in the enclosing
def, and it only "worked" on one line — by a fluke, its trailing comment contained "MFA". Tracing that is what surfaced the deliberate definition-line exclusion, and turned a rule that passed by accident into a boundary I can defend.