Skip to content

Commit 19a7566

Browse files
committed
Rewrite TaintAnalysis doc
1 parent f6433bc commit 19a7566

File tree

1 file changed

+163
-48
lines changed

1 file changed

+163
-48
lines changed

docs/TaintAnalysis.md

Lines changed: 163 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,63 +2,178 @@
22

33
## Configuration
44

5-
- Each method description can contain the key `conditions` (optionally).
6-
- Keys like `add-to` or `remove-from` can contain a list of values or only one value.
7-
Possible values:
8-
- this
9-
- arg1
10-
- arg2
11-
- ...
12-
- return
13-
- The `marks` key can also contain a list of marks or only one mark.
14-
- Fully qualified name of the method may be determined in parts.
5+
### Basic
6+
7+
- There are 4 sections: sources, passes, cleaners and sinks. Each of them contains a list of methods descriptions (rules). Fully qualified name of the method can be written in one line, or it can be defined by nested parts — first the package names, then the class name, and finally the method name. Note that, regular expressions in names are not supported.
8+
- Each rule can contain a method signature — a list of argument types (in compile-time): `signature: [<int>, _, <java.lang.String>]`
9+
- name of the type is written in `<>`.
10+
- `_` means any type.
11+
- Also, the rule can contain runtime conditions that must be met for this rule to trigger. Here you can set specific values of method arguments or their runtime types. More details about the `conditions` key below.
12+
- The `signature` and `conditions` fields are optional. If you do not specify them, the rule will be triggered on any method call.
13+
- Если для одного вызова метода выполняется несколько правил, они будут применены все в некотором порядке.
14+
- If several rules are suitable for one method call, they will all be applied in some kind of order.
15+
16+
### Sources
17+
18+
- The `add-to` field specifies which objects the `marks` will be added to. You can specify only one value here or a whole list. Possible values:
19+
- `this`
20+
- `arg1`
21+
- `arg2`
22+
- ...
23+
- `return`
24+
- The `marks` field specifies which `marks` to add to objects from `add-to`. You can also specify only one mark here or a whole list.
1525

1626
**Example:**
1727

18-
```YAML
28+
```yaml
1929
sources:
20-
com:
21-
abc.method1:
22-
add-to: [this, return]
23-
marks: xss
24-
bca.method2:
25-
add-to: return
26-
marks: [sensitive-data, sql-injection]
30+
- com:
31+
- abc:
32+
- method1:
33+
signature: [ _, _, <java.lang.Object> ]
34+
add-to: return
35+
marks: xss
36+
- method1:
37+
signature: [ <int>, _, <java.lang.String> ]
38+
add-to: [ this, return ]
39+
marks: sql-injection
40+
- bca.method2:
41+
add-to: return
42+
marks: [ sensitive-data, xss ]
43+
- org.example.method3:
44+
add-to: [ this, arg1, arg3 ]
45+
marks: sensitive-data
46+
```
2747
48+
### Passes
49+
50+
- The `get-from` field specifies the sources of `marks`.
51+
- The `add-to` field specifies which objects to add a mark to, if any element from `get-from` has one.
52+
- The `marks` field specifies the actual marks that can passed from one object to another.
53+
- For all the keys listed above, there can be only one value or a whole list of values. Also, it's true for similar keys in the sections below.
54+
55+
**Example:**
56+
57+
```yaml
2858
passes:
29-
com.abc.method2:
30-
conditions:
31-
this: "some string" # value: bool, int, float or string
32-
arg0:
33-
not: ""
34-
arg1: <int> # type
35-
arg2: [1, 2, 3] # arg2 should be equal to one of: 1, 2 or 3
36-
arg3:
37-
not: [4, 5, 6]
38-
arg4: [<float>, <java.lang.String>]
39-
arg5:
40-
not: [<int>, <boolean>]
41-
return: false
42-
get-from: [this, arg1, arg3]
43-
add-to: [return]
44-
marks: sensitive-data
59+
- com.abc.method2:
60+
get-from: [ this, arg1, arg3 ]
61+
add-to: [ arg2, return ]
62+
marks: sensitive-data
63+
```
4564

65+
### Cleaners
66+
67+
- The `remove-from` field specifies which objects to remove `marks` from.
68+
- The `marks` field specifies the marks to be removed.
69+
70+
**Example:**
71+
72+
```yaml
4673
cleaners:
47-
java.lang.String.isEmpty:
48-
conditions:
49-
return: true
50-
remove-from: this
51-
marks: [sensitive-data, sql-injection]
52-
com.company.method8:
53-
remove-from: [arg1, return]
54-
marks: xss
74+
- com.example.pack.method7:
75+
remove-from: this
76+
marks: [ sensitive-data, sql-injection ]
77+
```
78+
79+
### Sinks
5580

81+
- The `check` field specifies which objects will be checked for `marks`.
82+
- When one of the `marks` is found in one of the objects from the `check`, the analysis will report the problem found.
83+
84+
**Example:**
85+
86+
```yaml
5687
sinks:
57-
org.example:
58-
log:
59-
check: arg1
88+
- org.example:
89+
- log:
90+
check: arg1
91+
marks: sensitive-data
92+
- method17:
93+
check: [ arg1, arg3 ]
94+
marks: [ sql-injection, xss ]
95+
```
96+
97+
### Conditions
98+
99+
- The `conditions` field specifies runtime conditions for arguments (`arg1`, `arg2`, ...). Conditions can also be specified for `this` and `return` (if that makes sense).
100+
- The rule is triggered if all the specified conditions are met.
101+
- The condition can check a specific value or runtime type.
102+
- Values can be set for the following types: boolean, int, float or string.
103+
- The full name of the type must be specified in triangular brackets `<>`.
104+
105+
**Example:**
106+
107+
```yaml
108+
conditions:
109+
this: <java.lang.String> # this should be java.lang.String
110+
arg1: "test" # the first argument should be equal to "test"
111+
arg2: 227
112+
arg3: 227.001
113+
return: true # return value should be equal to `true`
114+
```
115+
116+
- Values and types can be negated using the `not` key, as well as combined using lists (`or` semantics).
117+
- Nesting is allowed.
118+
119+
**Example:**
120+
121+
```yaml
122+
conditions:
123+
this: [ "in", "out" ] # this should be equal to one of: "in" or "out"
124+
arg1: [ <int>, <float> ] # arg1 should be int or float
125+
arg2: { not: 0 } # arg2 should not be equal to 0
126+
arg3:
127+
not: [ 1, 2, 3, 5, 8 ] # should not be equal to any of the listed numbers
128+
arg4: [ "", { not: <int> } ] # should be empty string or int
129+
```
130+
131+
### Overall example
132+
133+
```yaml
134+
sources:
135+
- com:
136+
- abc:
137+
- method1:
138+
signature: [ _, _, <java.lang.Object> ]
139+
add-to: return
140+
marks: xss
141+
- method1:
142+
signature: [ <int>, _, <java.lang.String> ]
143+
add-to: [ this, return ]
144+
marks: sql-injection
145+
- bca.method2:
146+
conditions:
147+
this:
148+
not: "in"
149+
add-to: return
150+
marks: [ sensitive-data, xss ]
151+
152+
passes:
153+
- com.abc.method2:
154+
get-from: [ this, arg1, arg3 ]
155+
add-to: return
60156
marks: sensitive-data
61-
sink0:
62-
check: [arg1, arg3]
63-
marks: [sql-injection, xss]
157+
- org.example.method3:
158+
conditions:
159+
arg1: { not: "" }
160+
get-from: arg1
161+
add-to: [ this, return ]
162+
marks: sql-injection
163+
164+
cleaners:
165+
- com.example.pack.method7:
166+
conditions:
167+
return: true
168+
remove-from: this
169+
marks: [ sensitive-data, sql-injection ]
170+
171+
sinks:
172+
- org.example:
173+
- log:
174+
check: arg1
175+
marks: sensitive-data
176+
- method17:
177+
check: [ arg1, arg3 ]
178+
marks: [ sql-injection, xss ]
64179
```

0 commit comments

Comments
 (0)