taint_intrafile
- Value
trueorfalse- Default
false
By default, a taint rule analyzes each function on its own. Taint passed as an argument to another function is not followed into that function. With taint_intrafile: true, Opengrep computes a summary of each function in the file, recording how taint flows from its parameters to its result and to sinks. It applies these summaries at call sites. The finding is reported at the sink, inside the called function.
The flag --taint-intrafile turns this on for every taint rule of the scan. The option can turn it on for one rule, but it cannot turn off the flag. With --enable-interfile, a rule that sets taint_interfile is analyzed this way as well.
The supported languages are Apex, C, C++, C#, Clojure, Dart, Elixir, Go, Java, JavaScript, Julia, Kotlin, Lua, Python, Ruby, Rust, Scala, Swift, TypeScript and Visual Basic. For other languages, Opengrep logs a warning and analyzes each function on its own.
Examples
Taint through a helper function
rules: - id: user-input-to-system mode: taint pattern-sources: - pattern: input(...) pattern-sinks: - pattern: os.system(...) message: user input reaches os.system languages: [python] severity: ERROR options: taint_intrafile: trueimport osdef run(cmd): # ruleid: user-input-to-system os.system(cmd)run(input())$ opengrep test .
1/1: ✓ All tests passed
No tests for fixes found.The flag instead of the option
rules: - id: user-input-to-system mode: taint pattern-sources: - pattern: input(...) pattern-sinks: - pattern: os.system(...) message: user input reaches os.system languages: [python] severity: ERRORimport osdef run(cmd): os.system(cmd)run(input())$ opengrep scan -q --config rule.yaml app.py
$ opengrep scan -q --config rule.yaml --taint-intrafile app.py
app.py
error user-input-to-system
user input reaches os.system
4: os.system(cmd)The first command prints nothing: without the option or the flag, taint does not follow the call into run, so there is no finding.