| Field | Description |
|---|---|
source |
Input or expression where tracking begins. |
sanitizer |
Operation the rule assumes stops taint propagation. Check that the function is safe for this use. |
validator |
Condition for treating a value as validated. It must still hold when the value is used. |
sink |
Location where the rule reports a finding if the tracked value reaches it. |
sink.context |
Additional condition for reporting at this sink. The input remains tracked. |
method |
Selects calls by method name in a sanitizer or sink. Add conditions for argument position or call form when they matter. |
This Java rule reports a finding when the return value of getInput() reaches the first argument of unsafeSink and the second argument is "unsafe_option". The rule stops tracking the return value of sanitizerValue. Before using this rule, verify that the function handles input safely for this use.
rule:
taint:
source:
pattern: getInput()
sanitizer:
method:
- sanitizerValue
sink:
pattern: unsafeSink($IN, "unsafe_option")
Only the call in unsafe() matches this rule. Assessing the other calls requires checking how they are used and how the omitted helper functions work.
public class TaintExample {
public void unsafe() {
String userInput = getInput();
unsafeSink(userInput, "unsafe_option"); // Reported: the input and option match
}
public void safe_1() {
String userInput = getInput();
unsafeSink(userInput, "safe_option"); // Not reported: the second argument does not match
}
public void safe_2() {
String userInput = getInput();
userInput = sanitizerValue(userInput);
unsafeSink(userInput,"unsafe_option"); // Not reported: uses the sanitizer's return value
}
public void safe_3() {
String userInput = getInput();
unsafeSink("something", userInput); // Not reported: the input is not the first argument
}
}
Conditional validation
taint.validator describes validation of an existing input. The following rule protects useInput(value) only on paths where the value equals "approved". Ignoring a helper's result, checking another value, or reassigning the value after validation provides no protection.
id: validated-input-example
language: Java
message: Unvalidated input
rule:
taint:
source: {pattern: getInput()}
validator:
condition: {pattern: '$IN.equals("approved")'}
infer: true
sink: {pattern: useInput($IN)}
infer: true also analyzes helpers whose implementations can be resolved in the project. A function's name alone does not establish safety. Every accepting path must prove the condition; catching a validation failure and continuing leaves that failure path unprotected. Unresolved calls, unsupported control flow, and exhausted analysis bounds provide no safety proof.
| Expression | Meaning |
|---|---|
condition |
An ordinary condition matcher that checks $IN. when defaults to true and also accepts false. infer defaults to false. |
method |
An explicit validation contract using a fully qualified method name and an argument selector, such as pos: 0. Requires when: true, when: false, or when: returns; does not accept infer. |
value |
Checks construction using a value or assignment matcher. Does not accept when or infer. |
fact |
Queries a name declared by an attachFact barrier in the containing taint rule. Does not accept when or infer. |
all / any |
Requires all child conditions or at least one child condition for the same value. Shared captures, such as $BASE, must agree. |
Use exactly one of these six keys in each expression. when: returns is an explicit contract that normal completion means successful validation. Do not apply that contract to calls whose error codes or return values are ignored. Conditional validation must remain valid on every path reaching the sink. Reassignment, changes to a checked collection or base path, and mutations through aliases can invalidate earlier evidence.
Reusable validation
validator is also an ordinary matcher. This utility queries whether the selected value is protected by the condition at its current use.
id: approved-value
language: Java
rule:
validator:
condition: {pattern: '$IN.equals("approved")'}
infer: true
Other rules can reference it with matches: approved-value. The query's $IN applies only to the selected value and does not overwrite the outer matcher's $IN or other captures. Under taint.validator, wrap an ordinary utility in value: {matches: approved-value}. Preserve the original all/any structure when combining conditions.
Named facts and sink context
Use attachFact and detachFact barriers for rules that establish and clear object state. The following example explicitly models html() and text() as APIs that change the output mode. The rule applies only to output with confirmed html-output state.
id: output-context-example
language: Java
message: Untrusted HTML output
rule:
taint:
source: {pattern: getInput()}
barriers:
- id: html-output
effect: attachFact
focus: $IN
rule: {pattern: $IN.html()}
- id: clear-html
effect: detachFact
removesBarrier: html-output
focus: $IN
rule: {pattern: $IN.text()}
sink:
ast: {pattern: $OUT.send($IN)}
context:
metavar:
name: OUT
eq: {validator: {fact: html-output}}
fact checks the state of the selected object where the value is used. Following an earlier assignment still checks the state at the use site. State recorded on another object does not apply.
sink.context uses the values captured at the sink to decide which paths to report. One path must satisfy all its conditions. Facts from different paths cannot be combined, and the input remains tainted. A validator requires validation to hold on every path that reaches the sink.
Servlet XSS rules link a response object to its writers and streams. Setting Content-Type replaces the previous state, so changes after writer acquisition affect the query at output time. HTML paths remain reportable. Proven JSON/plain-text output, or an unknown type alone, does not activate the HTML output rule.
Ordinary sanitizer, addTaint, killTaint, attachFact, detachFact, barrier composition, and sink.requiresBarriers remain supported. focus: $IN attaches a fact to the input; focus: $MATCH attaches it only to the complete matched output expression. Keep this distinction so evidence about newly produced safe output does not validate the original input.
Migrating older syntax
Update the engine and rule pack together to use the new validation syntax. If you run v2.0.11, check which syntax it supports first. An error for a removed key lists the rule ID, the old key, and its replacement. You can keep existing vulnerability rule IDs and messages.
| Removed syntax | Replacement |
|---|---|
guard: {condition: ...} |
validator: {condition: ...} |
taint.guard-sanitizer |
taint.validator; wrap ordinary matchers in value and preserve composition. |
Same-class helper lookup with predicate |
validator: {condition: ..., infer: true} |
# Previous dedicated entry using an ordinary utility
# guard-sanitizer: {matches: approved-value}
# Replacement entry under taint
validator:
value: {matches: approved-value}
After migration, test protected and unprotected uses, reassignment, alias mutation, and branch joins together. For XSS context, include HTML-to-JSON and JSON-to-HTML transitions, different response objects, and unknown Content-Type values.