Skip to content

Commit ff6c338

Browse files
committed
Test where Cookie's constructor takes 2 potentially tainted arguments.
The test case shows a weakness in our rules system. The test defines a class Cookie, whose constructor takes 2 arguments, and each of them can bring tainted data to the created instance. However, our rule allows only for 1 tainted input.
1 parent 1e18b03 commit ff6c338

File tree

4 files changed

+112
-0
lines changed

4 files changed

+112
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<project name="multitaint" basedir="." default="jar">
2+
3+
<property name="root.dir" value="./"/>
4+
<property name="src.dir" value="${root.dir}/src"/>
5+
<property name="classes.dir" value="${root.dir}/build"/>
6+
<property name="install.dir" value="${root.dir}/dist"/>
7+
8+
<target name="jar">
9+
<antcall target="compile" />
10+
<mkdir dir="${install.dir}"/>
11+
<jar destfile="${install.dir}/multitaint.jar" basedir="${classes.dir}" />
12+
</target>
13+
14+
<target name="compile">
15+
<antcall target="clean" />
16+
<mkdir dir="${classes.dir}"/>
17+
<javac srcdir="${src.dir}" destdir="${classes.dir}" includeantruntime="false" debug="on">
18+
</javac>
19+
</target>
20+
21+
<target name="clean">
22+
<delete dir="${classes.dir}"/>
23+
<delete dir="${install.dir}"/>
24+
</target>
25+
26+
27+
</project>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"namespace": "com.diffblue.security",
3+
"rules":
4+
[
5+
{
6+
"comment": "Obtaining tainted data.",
7+
"class": "Main",
8+
"method": "makeTainted:(Ljava/lang/Object;)V",
9+
"result": {
10+
"location": "arg0",
11+
"taint": "Tainted data"
12+
}
13+
},
14+
{
15+
"comment": "Put tainted name to cookie",
16+
"class": "Cookie",
17+
"method": "<init>:(Ljava/lang/Object;Ljava/lang/Object;)V",
18+
"input": {
19+
"location": "arg1",
20+
"taint": "Tainted data"
21+
},
22+
"result": {
23+
"location": "this",
24+
"taint": "Tainted cookie"
25+
}
26+
},
27+
{
28+
"comment": "Writing potentially tainted data to a sink.",
29+
"class": "Main",
30+
"method": "sink:(LCookie;)V",
31+
"sinkTarget": {
32+
"location": "arg0",
33+
"vulnerability": "Tainted cookie"
34+
}
35+
}
36+
]
37+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Cookie {
2+
public Cookie(Object name, Object value) {
3+
}
4+
}
5+
public class Main {
6+
private static void makeTainted(Object o) {}
7+
private static void sink(Cookie o) {}
8+
9+
public static void taint_via_name() {
10+
Object name = new Object();
11+
Object value = new Object();
12+
makeTainted(name);
13+
Cookie c = new Cookie(name, value);
14+
sink(c);
15+
}
16+
17+
public static void taint_via_value() {
18+
Object name = new Object();
19+
Object value = new Object();
20+
makeTainted(value);
21+
Cookie c = new Cookie(name, value);
22+
sink(c);
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import regression.end_to_end.driver as pipeline_executor
2+
import os
3+
import subprocess
4+
import pytest
5+
import regression.utils as utils
6+
7+
8+
@pytest.mark.xfail(strict=True)
9+
def test_multitaint():
10+
"""
11+
The test case shows a weakness in our rules system. The test defines
12+
a class Cookie, whose constructor takes 2 arguments, and each of them
13+
can bring tainted data to the created instance. However, our rule
14+
allows only for 1 tainted input.
15+
"""
16+
with utils.working_dir(os.path.abspath(os.path.dirname(__file__))):
17+
subprocess.call("ant")
18+
traces = pipeline_executor.run_security_analyser_pipeline(
19+
os.path.join("dist", "multitaint.jar"),
20+
"rules.json",
21+
os.path.realpath(os.path.dirname(__file__)))
22+
assert traces.count_traces() == 2
23+
assert traces.trace_exists("java::Main.taint_via_name:()V", 13)
24+
assert traces.trace_exists("java::Main.taint_via_value:()V", 20)

0 commit comments

Comments
 (0)