How it works
- Source Identification: Marks values from untrusted input as
tainted:input(), everyrequest.<attr>read (such asrequest.args.get(...),request.form[...],request.get_json()andrequest.method),os.environandos.getenv,sys.argv, andread,readlineandrecvcalls. An arbitraryobj.get(), such asdict.get, is not a source. - Flow Propagation: Tracks taint through assignments and inside expressions: concatenation, f-strings,
%andstr.format, nested calls, tuple and starred unpacking, augmented assignment and branches. - Sanitisers per Sink Class: A sanitiser clears only the sink classes it protects, matched by exact name.
int(),float()andbool()clear every class.html.escapeandmarkupsafe.escapeclear only HTML output, such asmark_safe, and only where the value lands in text content.werkzeug.utils.secure_filenameclears only file paths. There is no shell sanitiser:shlex.quotedoes not clear a shell sink. A sanitiser counts only when the code imports it itself (the builtins need no import), uses no reflection, and its result reaches the sink directly. - Sink Validation: If tainted data reaches a sink, such as
eval,os.system,subprocess.run,pickle.loads, a SQLexecute,open,requests.get,mark_safeorrender_template_string, without a sanitiser for that sink’s class, the engine reports a vulnerability. SQL bound parameters (execute(query, params)) are not reported; taint in the query still is. Taint does not follow a call’s arguments into the parameters of the function, method or lambda it calls, so a flow through a parameter is not reported:def deliver(payload): os.system(payload)withdeliver(input())isSAFE.
Usage
RunTaintAnalyzer from the qwed package. CodeVerifier.verify_python_deep also runs it, together with the pattern scan.
When to use
- Code Generation: Verifying code written by LLMs for security vulnerabilities.
- RCE Prevention: Ensuring generated agents don’t execute malicious shell commands.
- XSS Prevention: Ensuring web outputs are properly encoded.