Taint Analysis

Research
Introduced by
James Newsome
Year
2005
Type
data flow tracking technique
Family
Program analysis for security

What does it do?

Taint analysis is a data flow analysis technique that tracks how untrusted (tainted) input moves through a program, to find cases where that data reaches sensitive operations (sinks) such as SQL queries or system calls.

Newsome and Song (2005) presented dynamic taint analysis for the automatic detection, analysis and signature generation of exploits in commodity software, and Schwartz, Avgerinos and Brumley (2010) later described its algorithms precisely. The technique is most often associated with detecting injection vulnerabilities.

The intuition behind the method

Taint analysis marks untrusted input (the sources) with a taint label and follows that label as the program runs or as the code is analysed. Operations that read or combine tainted values pass the label on to their results, according to the propagation rules the analysis defines. When tainted data reaches a designated sink, such as a SQL query, the analysis reports a flow from source to sink, so each report comes with an explicit data path. How many reports are false alarms depends largely on how conservative the propagation rules are, so the rules matter as much as the marking.

History

Newsome and Song (2005) presented dynamic taint analysis for automatic detection, analysis and signature generation of exploits on commodity software. Schwartz, Avgerinos and Brumley (2010) later noted that little effort had been made to formally define these algorithms, and then described dynamic taint analysis and forward symbolic execution as extensions to the run-time semantics of a general language.

When to use it

Choose taint analysis when the question is whether untrusted input can reach sensitive operations without passing through validation or sanitisation, as in web applications, network services and other programs that process external input. It is most directly applicable to injection-type vulnerabilities such as SQL injection, cross-site scripting and command injection. Dynamic taint analysis requires that the program can be run and only covers the executions and inputs that are actually exercised, so it suits cases where representative inputs are available. Do not rely on it for logic errors or authorisation flaws, which do not involve data moving from an untrusted source to a dangerous operation.

Limitations and considerations

  • Implicit flows, where tainted data influences which branch is taken without being copied into the value used at the sink, are hard to track with ordinary data flow propagation rules.
  • Instrumentation and taint bookkeeping add runtime overhead, and the cost depends on how finely taint is tracked; binary-level tracking is generally more expensive than source-level tracking.
  • Taint can be lost through transformations such as encryption or hashing, while conservative propagation rules can mark values as tainted even when the source does not really influence them, producing false positives.
  • The analysis needs explicitly defined sources and sinks, and an incomplete specification leaves some vulnerabilities undetected.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Each reported alert corresponds to a concrete source-to-sink flow with an explicit data path, which makes results easier to inspect than a bare warning.
  • In its dynamic form it works on running programs, so source code is not required when the program can be executed and instrumented.
  • It suits checks of whether a value was validated before reaching a sink, which is the typical question in security-critical code.

Applications

  • Web application security testing, where tainted request parameters are traced to database queries, shell commands or rendered output.
  • Intrusion and exploit detection, where taint tracking flags attempts to use attacker-controlled input to redirect program execution.
  • Malware analysis, where tracking input-derived data helps show how a sample uses external data.
  • Test case and input filter generation, where tainted input paths guide the choice of inputs.
  • Binary-level vulnerability discovery in compiled programs for which source code is unavailable.

How it works

How it works

1

Identify the sources of untrusted input, such as network data, user-supplied values and file contents, and attach a taint label to the values they produce.

2

As the program executes, taint labels are carried through data assignments, arithmetic, string concatenation and function calls according to the propagation rules. In dynamic taint analysis these rules extend the run-time semantics of the program, so only data actually processed on an executed path is tracked.

3

Monitor the designated sinks, such as SQL queries, command execution and memory accesses, and flag any sink that receives a tainted value.

4

Report each source-to-sink flow together with the chain of operations that carried the taint, so that a reviewer can see the data path behind the alert.

Common pitfalls

  • Missing a source of untrusted input leaves a gap in coverage that the analysis cannot report on.
  • Propagation rules that are too loose spread taint to values the source does not influence, producing alert volumes that are hard to triage.
  • Dynamic analysis observes only the executed paths and the inputs used during testing, so a clean result does not show that no tainted flow exists.
  • Source and sink lists must be updated as the application changes. Schwartz et al. (2010) highlight implementation choices and common pitfalls that affect results in security contexts.

Frequently asked questions

What is the difference between static and dynamic taint analysis?

Static taint analysis examines code without executing it and may over-approximate data flows, reporting flows that cannot occur at runtime. Dynamic taint analysis tracks actual data flows during execution, so the flows it reports occurred for the inputs used, but it only covers the paths that were run.

How does taint analysis handle implicit flows?

Implicit flows arise when tainted data influences which branch is taken. Tracking them requires analysing which branches depend on tainted conditions, which adds considerable complexity and is one reason they are often not tracked.

What is the performance overhead of dynamic taint analysis?

Instrumentation adds runtime cost, and its size depends on the granularity of tracking: binary-level tracking is generally slower than source-level tracking. Sampling reduces overhead but gives incomplete coverage. This page does not give a reliable general figure for the slowdown.

How do I define sources and sinks for taint analysis?

Sources are input vectors (network, files, user input). Sinks are dangerous operations (SQL queries, system calls). Comprehensive source/sink specification requires domain knowledge and application understanding.

Can taint analysis detect all injection vulnerabilities?

Taint analysis detects cases where untrusted data reaches a sink without adequate validation, but it may miss vulnerabilities where tainted data is used in context-specific ways, such as format string attacks or second-order SQL injection.

Related methods

Sources

  1. Newsome, J., & Song, D. X. (2005). Dynamic taint analysis for automatic detection, analysis, and signature generation of exploits on commodity software. In Network and Distributed System Security Symposium (NDSS 2005).

    Open publication reference
  2. Schwartz, E. J., Avgerinos, T., & Brumley, D. (2010). All you ever wanted to know about dynamic taint analysis and forward symbolic execution (but might have been afraid to ask). In IEEE Symposium on Security and Privacy (SP), 2010, pp. 317-331.

    Open DOI reference