Commit db4e303
committed
fix(safety): scan all tokens for privilege escalation; loop env-prefix in allowlist; localized redaction
Critical:
- _rules.ProcessRule._check_bash: privilege-escalation detection only
checked tokens[0], so `FOO=bar sudo rm -rf /` and
`echo x | sudo tee /etc/passwd` bypassed the CRITICAL privilege rule
because the line-leading token was `FOO=bar` / `echo`, not `sudo`. The
network-command side already scanned all tokens; privilege now does
the same by collecting basenames of ALL tokens that hit
_PRIVILEGE_CMDS. This closes a real CRITICAL-detection bypass.
Warning:
- _rules.ProcessRule._check_bash: strict_command_allowlist only stripped
ONE leading KEY=VAL env-assignment token, so `FOO=bar A=b sudo ls`
landed on `A=b` (has `=`) and stopped, missing `sudo`. Now loops
through ALL consecutive leading KEY=VAL tokens (excluding subshell
`(...)`). Same root cause as the privilege bypass above.
Suggestion:
- _scanner._redact_evidence: the `len > 80 AND 32+ char run` branch
called redact(keep=8) on the WHOLE line, which truncated evidence to
8 chars whenever a long identifier/URL-path happened to be present.
This destroyed diagnostic context (e.g. requests.get('https://api.
github.com/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa') became `requests`).
Now applies re.sub(r"[A-Za-z0-9_\-]{32,}", "***", ...) so only the
matched long token is replaced; the surrounding diagnostic context
survives. Removed the now-unused `redact` import.
Tests:
- test_process_bash_sudo_with_env_prefix_is_caught: `FOO=bar sudo rm
-rf /` must trigger privilege CRITICAL.
- test_process_bash_sudo_after_pipe_is_caught: `echo x | sudo tee
/etc/passwd` must trigger privilege CRITICAL.
- test_process_bash_sudo_with_multiple_env_prefix_is_caught: `FOO=bar
A=b sudo ls` must trigger privilege CRITICAL.
- test_strict_command_allowlist_multiple_env_prefix_is_fail_closed:
`FOO=bar A=b ls` (whitelisted) passes; `FOO=bar A=b rm` (not
whitelisted) is flagged.
- test_redact_evidence_preserves_diagnostic_context: long-URL evidence
keeps `requests.get` + domain; only the 32-char token is ***.1 parent 0761054 commit db4e303
4 files changed
Lines changed: 103 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
325 | 325 | | |
326 | 326 | | |
327 | 327 | | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
852 | 852 | | |
853 | 853 | | |
854 | 854 | | |
855 | | - | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
856 | 863 | | |
857 | 864 | | |
858 | 865 | | |
859 | 866 | | |
860 | 867 | | |
861 | 868 | | |
862 | 869 | | |
863 | | - | |
864 | | - | |
865 | | - | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
866 | 882 | | |
867 | 883 | | |
868 | 884 | | |
| |||
884 | 900 | | |
885 | 901 | | |
886 | 902 | | |
887 | | - | |
| 903 | + | |
888 | 904 | | |
889 | 905 | | |
890 | 906 | | |
| |||
894 | 910 | | |
895 | 911 | | |
896 | 912 | | |
897 | | - | |
| 913 | + | |
898 | 914 | | |
899 | 915 | | |
900 | 916 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
| |||
209 | 208 | | |
210 | 209 | | |
211 | 210 | | |
212 | | - | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
213 | 219 | | |
214 | 220 | | |
215 | 221 | | |
| |||
219 | 225 | | |
220 | 226 | | |
221 | 227 | | |
222 | | - | |
223 | | - | |
224 | | - | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
225 | 231 | | |
0 commit comments