Commit f1e242b
committed
fix(secrets): replace PEM-header regex with linear-time scan
CodeQL's polynomial-ReDoS gate (py/polynomial-redos) flags the
'-----BEGIN PRIVATE KEY' detection regex: the optional ' [A-Z0-9]+' group
makes worst-case matching input-dependent. Replace it with a
case-normalized anchor scan using monotone-cached str.find probes for
both the canonical header and the '-----BEGIN <kind> ' variant
(RSA/EC/DSA/OPENSSH/ENCRYPTED/PGP/PKCS8), verified O(N) on adversarial
shapes (anchor-heavy 3MB: 0.92s; long-token 2MB: 0.24s; late-header
1.5MB: 0.09s) with identical accept/reject behavior across PEM variants
and no change to reject_secrets/redact_secrets contracts.1 parent c11feb0 commit f1e242b
1 file changed
Lines changed: 27 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
51 | 64 | | |
| 65 | + | |
| 66 | + | |
52 | 67 | | |
53 | 68 | | |
54 | | - | |
55 | | - | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
56 | 75 | | |
57 | 76 | | |
58 | 77 | | |
59 | | - | |
| 78 | + | |
| 79 | + | |
60 | 80 | | |
61 | 81 | | |
62 | 82 | | |
| |||
0 commit comments