Repository navigation
Taint Tracking
Canonical source: docs/taint-tracking.md.
Taint tracking follows untrusted data from a source through assignments to a dangerous sink. A flow becomes a taint-* finding rated CRITICAL or HIGH, with a trace of the steps. In SARIF the trace becomes a codeFlow, which GitHub code scanning shows step by step.
Turn it off with --no-taint or taint=False.
The table below is current main (these Java and TypeScript rows, and Python's one-level calls, ship in the next release; they are not in v1.4.0):
| Language | Engine | Module |
|---|---|---|
| Python |
ast, inter-statement + one-level intra-file calls |
core/py_taint.py |
| JavaScript, TypeScript, Java, C#, C++, Go, Ruby, Rust | tree-sitter data-flow engine (with [treesitter]) |
core/ts_engine.py, core/ts_specs.py
|
| same, without tree-sitter | line-based fallback | core/taint_fallback.py |
| HTML, SQL | none | — |
The tree-sitter engine handles assignments, augmented assignments, string interpolation and concatenation, out-arguments (fgets(buf, ...), read_line(&mut s), fmt.Scan(&x)), and SQL strings built in a variable and executed later. The fallback works line by line with the same source/sink lists.
Java (on main): the fallback covers servlet and Spring / JAX-RS sources and the JDBC, Runtime.exec / ProcessBuilder, deserialization, file, response-writer, sendRedirect and new URL sinks; the tree-sitter engine also knows JdbcTemplate.query / update, ScriptEngine.eval, RestTemplate and Class.forName. Java's main(String[] args) is not treated as a source. Parameterized queries (? placeholders) and numeric parsing (Integer.parseInt) count as sanitizers.
- In the latest release, v1.4.0, Python taint tracking stays inside one function of one file, and there is no taint tracking for Java.
- On current
main(ships in the next release; PR #8 / issue #1, both merged or closed): Python taint tracking also follows calls one level deep within the same file, using parameter-to-sink summaries. A call that passes untrusted data into a helper is reported with a source, call-site and sink trace that names both functions. -
Java taint tracking is also on
main(PR #18 / issue #6) and ships in the next release. - Deeper call chains (two or more levels), cross-file calls, and the tree-sitter and fallback engines remain intra-procedural. That remaining gap is on the roadmap.
Parameters of recognized route handlers are treated as sources. Containers are coarse: a dict or list that receives tainted data is tainted as a whole. Custom sanitizers are not recognized; use --disable-rule or rename through a known sanitizer.
| Kind | Examples |
|---|---|
| Remote | Flask/Django/FastAPI request.*, route-handler parameters, Express req.* (JavaScript and TypeScript), Java servlet request.getParameter* / getHeader / getCookies, Spring @RequestParam / @PathVariable / @RequestBody (and JAX-RS @QueryParam / @PathParam) parameters, Go *http.Request, C# [Http*] action parameters, Rails params, input(), stdin, gets, cin, fgets, read_line, sockets |
| Local | environment variables (System.getenv, System.getProperty in Java), sys.argv / os.Args / argv / env::args, file contents, command-line flags |
| Rule id | Sinks |
|---|---|
taint-command-injection |
os.system, subprocess with shell=True or a tainted program, exec.Command, Process.Start, system(), backticks, Command::new, Runtime.exec, new ProcessBuilder
|
taint-code-injection |
eval, exec, Function(), instance_eval, ScriptEngine.eval, … |
taint-sql-injection |
execute/query/Exec with a query built from tainted data; JDBC executeQuery / executeUpdate / prepareStatement and Spring JdbcTemplate.query* / update (the query argument only) |
taint-deserialization |
pickle.loads, yaml.load, Marshal.load, BinaryFormatter, new ObjectInputStream, XMLDecoder, … |
taint-template-injection |
render_template_string, Template(...)
|
taint-path-traversal |
open, os.Open, File.ReadAllText, send_file, http.ServeFile, new File, Paths.get, … |
taint-xss |
innerHTML, document.write, Markup, template.HTML, html_safe, servlet response.getWriter().print* (MEDIUM), … |
taint-ssrf |
requests.get, urlopen, fetch, http.Get, HttpClient, new URL, RestTemplate, … |
taint-open-redirect |
redirect(...), res.redirect, http.Redirect, sendRedirect
|
taint-format-string |
printf(user) and friends (C/C++) |
taint-dynamic-dispatch |
getattr(obj, user), send(params[...]), Class.forName(user)
|
Numeric casts (int(), float(), parseInt, Integer.parseInt / Long.valueOf, Number, strconv.Atoi, .parse::<i32>(), …), shlex.quote, HTML escaping, os.path.basename / filepath.Base / File.basename, URL encoding, and parameterized queries (placeholders with a separate argument list) clear taint.
- A remote source reaching a CRITICAL-class sink (command, code, SQL injection) is CRITICAL.
- The same flow from a local source is one level lower (HIGH).
- Deserialization flows are HIGH.
- SSRF, XSS, open-redirect, path-traversal, template and dynamic-dispatch sinks ignore local sources.
- The same sink with only literal arguments keeps the lower non-taint rating (for example
os.system("ls -l")is MEDIUM). -
subprocess.run(["ping", host])(fixed program, no shell) is not a command-injection CRITICAL.
When a taint flow ends on the same line and CWE as an existing finding, that finding is upgraded instead of duplicated.
A short Flask example and the full lists are in docs/taint-tracking.md.
Created by ML / ML Innovations Research Lab. Korg (AI assistant, Grok Bot), contributor. · Repository · Apache License 2.0
Start here
Using Code Cleaner
Contributing