Skip to content

Commit f81878c

Browse files
committed
Updates requested in the review.
Added a test case with no XXE issue in it.
1 parent f518955 commit f81878c

File tree

2 files changed

+45
-10
lines changed

2 files changed

+45
-10
lines changed

regression/end_to_end/xxe02/src/Main.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,23 @@ public class Main {
99
private static String make_tainted(String s) {
1010
return s;
1111
}
12-
13-
public static void main(String[] args) {
14-
if (args.length < 1)
15-
return;
1612

17-
String xml_from_attacker = make_tainted(args[0]);
13+
public static void no_xxe_issue(String input) {
14+
String xml_from_attacker = make_tainted(input);
15+
16+
try {
17+
JAXBContext jc = JAXBContext.newInstance("xxe02.MyClass");
18+
XMLInputFactory xif = XMLInputFactory.newFactory();
19+
xif.setProperty("javax.xml.stream.isSupportingExternalEntities", false);
20+
XMLStreamReader xsr = xif.createXMLStreamReader(new StringReader(xml_from_attacker));
21+
Unmarshaller unmarshaller = jc.createUnmarshaller();
22+
MyClass myClass = (MyClass)unmarshaller.unmarshal(xsr);
23+
} catch (Exception e) {
24+
}
25+
}
26+
27+
public static void xxe_issue(String input) {
28+
String xml_from_attacker = make_tainted(input);
1829

1930
try {
2031
JAXBContext jc = JAXBContext.newInstance("xxe02.MyClass");
@@ -26,5 +37,15 @@ public static void main(String[] args) {
2637
} catch (Exception e) {
2738
}
2839
}
40+
41+
public static void main(String[] args) {
42+
if (args.length < 1)
43+
return;
44+
45+
String xml_from_attacker = make_tainted(args[0]);
46+
47+
no_xxe_issue(xml_from_attacker);
48+
xxe_issue(xml_from_attacker);
49+
}
2950
}
3051

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,39 @@
11
import fasteners
22
import os
33
import subprocess
4-
# import pytest
4+
import pytest
55

66
from regression.end_to_end.driver import run_security_analyser_pipeline
77
import regression.utils as utils
88

99

10-
# @pytest.mark.xfail(strict=True)
10+
@pytest.mark.xfail(strict=True)
1111
@fasteners.interprocess_locked(os.path.join(os.path.dirname(__file__), ".build_lock"))
12-
def test_xxe02(load_strategy):
12+
def test_xxe02_no_xxe_issue(load_strategy):
1313
with utils.working_dir(os.path.abspath(os.path.dirname(__file__))):
1414
subprocess.call(["ant"])
1515
with run_security_analyser_pipeline(
1616
"build",
1717
"rules.json",
1818
os.path.realpath(os.path.dirname(__file__)),
19-
"xxe02.Main.main",
19+
"xxe02.Main.no_xxe_issue",
20+
load_strategy,
21+
extra_args=["--use-xxe-models-library"]) as traces:
22+
assert traces.count_traces() == 0
23+
24+
25+
@fasteners.interprocess_locked(os.path.join(os.path.dirname(__file__), ".build_lock"))
26+
def test_xxe02_xxe_issue(load_strategy):
27+
with utils.working_dir(os.path.abspath(os.path.dirname(__file__))):
28+
subprocess.call(["ant"])
29+
with run_security_analyser_pipeline(
30+
"build",
31+
"rules.json",
32+
os.path.realpath(os.path.dirname(__file__)),
33+
"xxe02.Main.xxe_issue",
2034
load_strategy,
2135
extra_args=["--use-xxe-models-library"]) as traces:
2236
assert traces.count_traces() == 1
2337
assert traces.trace_exists(
24-
"java::xxe02.Main.main:([Ljava/lang/String;)V", 25)
38+
"java::xxe02.Main.xxe_issue:(Ljava/lang/String;)V", 36)
2539

0 commit comments

Comments
 (0)