py-ast-taint.py Assign handler never removed a name from the tainted set on reassignment, so a source-then-constant/sanitizer rebind (g=os.getenv(); g='safe'; os.system(g), or x=shlex.quote(x)) kept stale taint and fired false AST-CMD-EXEC findings. Assign now clears taint for target names when the RHS is not a source. No cross-expression propagation added — the f-string/concat/alias recall gap (#27) stays deferred to v8. #28: added fixtures+assertions locking the tainted subprocess/os.system AST-CMD-EXEC sink and the open(...,'w') AST-FILE-WRITE sink. Suite 1931/0. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TcQyMTQfyrsAapaCMPxTtQ
17 lines
544 B
Python
17 lines
544 B
Python
import os
|
|
import shlex
|
|
|
|
# Taint must CLEAR when a name is rebound to a non-source value (#29).
|
|
# Neither function below may produce a finding.
|
|
|
|
|
|
def reassigned_constant():
|
|
g = os.getenv("G") # tainted source
|
|
g = "safe-constant" # rebound to a literal -> taint must clear
|
|
os.system(g) # must NOT be flagged
|
|
|
|
|
|
def sanitized_reassignment():
|
|
x = input("path> ") # tainted source
|
|
x = shlex.quote(x) # rebound to a non-source call -> taint must clear
|
|
os.system(x) # must NOT be flagged
|