Commit 4e848e2
Add content secret-regex scan + non-dry-run gate test + fix stale wording
R3 review on PR #421 (4th round on the codex-surface security finding):
P1: Reviewer wanted the preflight to also catch secrets stored under
innocuous filenames (notes.txt with API keys, etc.), not just the
filename-pattern matches. Implements the recommended fix:
- SECRET_CONTENT_PATTERN: same canonical regex used by the api
backend's pre-upload scan in skill-doc Step 3b (AKIA*, ghp_*,
sk-*, gho_*, api_key=, secret_key=, password=, token=, bearer
*, PRIVATE_KEY).
- _scan_sensitive_content(): walks the repo, applies the regex to
text-suffix files (_SCAN_CONTENT_SUFFIXES) under 1MB, returns
matched paths.
- _preflight_codex_secrets(): combines filename + content scans
into the single check used by the codex gate.
False-positive control: _SCAN_SKIP_CONTENT_PREFIXES skips tests/,
test/, __tests__/, .github/, docs/, examples/, fixtures/ from the
CONTENT scan only — those locations legitimately contain literal
pattern matches as test fixtures, regex definitions, or documented
examples (NOT real secrets). Filename scan still applies there, so
a real .env in tests/ is still caught. Smoke-tested in this repo:
before prefix skip, 4 hits (1 real + 3 false positives in test
file + 2 workflow files); after prefix skip, 1 hit (real only).
P3: Two doc-consistency drifts fixed:
- Removed stale "gitignore-aware" / "git ls-files" wording from
test class docstring, --allow-secrets help text, and skill doc
bullet (we deliberately do NOT respect .gitignore so we catch
gitignored .env files).
P3: Added TestMainCodexSecretGate (4 tests) — drives main() WITHOUT
--dry-run so the secret gate actually runs:
- aborts on .env (filename match) → exit 1, codex NOT called
- aborts on AKIA in notes.txt (content match) → exit 1, codex NOT called
- --allow-secrets converts ABORT → WARNING, codex IS called
- clean repo → no warning, codex called normally
Skill doc updated to describe both scan layers and the prefix-skip
behavior with rationale.
Tests: 230 pass (16 new across content scan + prefix skip + main() gate).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 20e6aab commit 4e848e2
3 files changed
Lines changed: 373 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
51 | 68 | | |
52 | 69 | | |
53 | 70 | | |
54 | 71 | | |
55 | 72 | | |
56 | 73 | | |
57 | 74 | | |
58 | | - | |
| 75 | + | |
| 76 | + | |
59 | 77 | | |
60 | 78 | | |
61 | 79 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1198 | 1198 | | |
1199 | 1199 | | |
1200 | 1200 | | |
1201 | | - | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
1202 | 1205 | | |
1203 | 1206 | | |
1204 | 1207 | | |
| 1208 | + | |
1205 | 1209 | | |
1206 | 1210 | | |
| 1211 | + | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
1207 | 1265 | | |
1208 | 1266 | | |
1209 | 1267 | | |
| |||
1249 | 1307 | | |
1250 | 1308 | | |
1251 | 1309 | | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
1252 | 1361 | | |
1253 | 1362 | | |
1254 | 1363 | | |
| |||
1264 | 1373 | | |
1265 | 1374 | | |
1266 | 1375 | | |
1267 | | - | |
| 1376 | + | |
| 1377 | + | |
1268 | 1378 | | |
1269 | 1379 | | |
1270 | 1380 | | |
| |||
1725 | 1835 | | |
1726 | 1836 | | |
1727 | 1837 | | |
1728 | | - | |
| 1838 | + | |
| 1839 | + | |
1729 | 1840 | | |
1730 | 1841 | | |
1731 | 1842 | | |
| |||
2069 | 2180 | | |
2070 | 2181 | | |
2071 | 2182 | | |
2072 | | - | |
| 2183 | + | |
2073 | 2184 | | |
2074 | 2185 | | |
2075 | 2186 | | |
| |||
0 commit comments