Skip to content

Commit 199eabd

Browse files
committed
Java: convert XsltInjection test to .qlref
Also, split off into separate directory from JndiInjectionTest because their $Alerts were interfering with each other.
1 parent 3f9e0fe commit 199eabd

File tree

11 files changed

+287
-57
lines changed

11 files changed

+287
-57
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//semmle-extractor-options: --javac-args -cp ${testdir}/../../../../stubs/springframework-5.8.x:${testdir}/../../../../stubs/shiro-core-1.5.2:${testdir}/../../../../stubs/spring-ldap-2.3.2:${testdir}/../../../../stubs/Saxon-HE-9.9.1-7:${testdir}/../../../../stubs/apache-commons-logging-1.2

java/ql/test/query-tests/security/CWE-074/XsltInjection/XsltInjectionTest.expected

Lines changed: 245 additions & 0 deletions
Large diffs are not rendered by default.

java/ql/test/query-tests/security/CWE-074/XsltInjectionTest.java renamed to java/ql/test/query-tests/security/CWE-074/XsltInjection/XsltInjectionTest.java

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -27,91 +27,91 @@
2727
@Controller
2828
public class XsltInjectionTest {
2929
public void testStreamSourceInputStream(Socket socket) throws Exception {
30-
StreamSource source = new StreamSource(socket.getInputStream());
31-
TransformerFactory.newInstance().newTransformer(source).transform(null, null); // $hasXsltInjection
30+
StreamSource source = new StreamSource(socket.getInputStream()); // $ Source
31+
TransformerFactory.newInstance().newTransformer(source).transform(null, null); // $ Alert
3232
}
3333

3434
public void testStreamSourceReader(Socket socket) throws Exception {
35-
StreamSource source = new StreamSource(new InputStreamReader(socket.getInputStream()));
36-
TransformerFactory.newInstance().newTemplates(source).newTransformer().transform(null, null); // $hasXsltInjection
35+
StreamSource source = new StreamSource(new InputStreamReader(socket.getInputStream())); // $ Source
36+
TransformerFactory.newInstance().newTemplates(source).newTransformer().transform(null, null); // $ Alert
3737
}
3838

3939
@RequestMapping
40-
public void testStreamSourceInjectedParam(@RequestParam String param) throws Exception {
40+
public void testStreamSourceInjectedParam(@RequestParam String param) throws Exception { // $ Source
4141
String xslt = "<xsl:stylesheet [...]" + param + "</xsl:stylesheet>";
4242
StreamSource source = new StreamSource(new StringReader(xslt));
43-
TransformerFactory.newInstance().newTransformer(source).transform(null, null); // $hasXsltInjection
43+
TransformerFactory.newInstance().newTransformer(source).transform(null, null); // $ Alert
4444
}
4545

4646
public void testSAXSourceInputStream(Socket socket) throws Exception {
47-
SAXSource source = new SAXSource(new InputSource(socket.getInputStream()));
48-
TransformerFactory.newInstance().newTemplates(source).newTransformer().transform(null, null); // $hasXsltInjection
47+
SAXSource source = new SAXSource(new InputSource(socket.getInputStream())); // $ Source
48+
TransformerFactory.newInstance().newTemplates(source).newTransformer().transform(null, null); // $ Alert
4949
}
5050

5151
public void testSAXSourceReader(Socket socket) throws Exception {
5252
SAXSource source =
53-
new SAXSource(null, new InputSource(new InputStreamReader(socket.getInputStream())));
54-
TransformerFactory.newInstance().newTransformer(source).transform(null, null); // $hasXsltInjection
53+
new SAXSource(null, new InputSource(new InputStreamReader(socket.getInputStream()))); // $ Source
54+
TransformerFactory.newInstance().newTransformer(source).transform(null, null); // $ Alert
5555
}
5656

5757
public void testStAXSourceEventReader(Socket socket) throws Exception {
5858
StAXSource source =
59-
new StAXSource(XMLInputFactory.newInstance().createXMLEventReader(socket.getInputStream()));
60-
TransformerFactory.newInstance().newTransformer(source).transform(null, null); // $hasXsltInjection
59+
new StAXSource(XMLInputFactory.newInstance().createXMLEventReader(socket.getInputStream())); // $ Source
60+
TransformerFactory.newInstance().newTransformer(source).transform(null, null); // $ Alert
6161
}
6262

6363
public void testStAXSourceEventStream(Socket socket) throws Exception {
6464
StAXSource source = new StAXSource(XMLInputFactory.newInstance().createXMLStreamReader(null,
65-
new InputStreamReader(socket.getInputStream())));
66-
TransformerFactory.newInstance().newTemplates(source).newTransformer().transform(null, null); // $hasXsltInjection
65+
new InputStreamReader(socket.getInputStream()))); // $ Source
66+
TransformerFactory.newInstance().newTemplates(source).newTransformer().transform(null, null); // $ Alert
6767
}
6868

6969
public void testDOMSource(Socket socket) throws Exception {
7070
DOMSource source = new DOMSource(
71-
DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(socket.getInputStream()));
72-
TransformerFactory.newInstance().newTransformer(source).transform(null, null); // $hasXsltInjection
71+
DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(socket.getInputStream())); // $ Source
72+
TransformerFactory.newInstance().newTransformer(source).transform(null, null); // $ Alert
7373
}
7474

7575
public void testDisabledXXE(Socket socket) throws Exception {
76-
StreamSource source = new StreamSource(socket.getInputStream());
76+
StreamSource source = new StreamSource(socket.getInputStream()); // $ Source
7777
TransformerFactory factory = TransformerFactory.newInstance();
7878
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
7979
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "");
80-
factory.newTransformer(source).transform(null, null); // $hasXsltInjection
80+
factory.newTransformer(source).transform(null, null); // $ Alert
8181
}
8282

8383
public void testFeatureSecureProcessingDisabled(Socket socket) throws Exception {
84-
StreamSource source = new StreamSource(socket.getInputStream());
84+
StreamSource source = new StreamSource(socket.getInputStream()); // $ Source
8585
TransformerFactory factory = TransformerFactory.newInstance();
8686
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, false);
87-
factory.newTransformer(source).transform(null, null); // $hasXsltInjection
87+
factory.newTransformer(source).transform(null, null); // $ Alert
8888
}
8989

9090
public void testSaxon(Socket socket) throws Exception {
91-
StreamSource source = new StreamSource(socket.getInputStream());
91+
StreamSource source = new StreamSource(socket.getInputStream()); // $ Source
9292
XsltCompiler compiler = new Processor(true).newXsltCompiler();
9393

94-
compiler.compile(source).load().transform(); // $hasXsltInjection
95-
compiler.compile(source).load30().transform(null, null); // $hasXsltInjection
96-
compiler.compile(source).load30().applyTemplates((Source) null); // $hasXsltInjection
97-
compiler.compile(source).load30().applyTemplates((Source) null, null); // $hasXsltInjection
98-
compiler.compile(source).load30().applyTemplates((XdmValue) null); // $hasXsltInjection
99-
compiler.compile(source).load30().applyTemplates((XdmValue) null, null); // $hasXsltInjection
100-
compiler.compile(source).load30().callFunction(null, null); // $hasXsltInjection
101-
compiler.compile(source).load30().callFunction(null, null, null); // $hasXsltInjection
102-
compiler.compile(source).load30().callTemplate(null); // $hasXsltInjection
103-
compiler.compile(source).load30().callTemplate(null, null); // $hasXsltInjection
94+
compiler.compile(source).load().transform(); // $ Alert
95+
compiler.compile(source).load30().transform(null, null); // $ Alert
96+
compiler.compile(source).load30().applyTemplates((Source) null); // $ Alert
97+
compiler.compile(source).load30().applyTemplates((Source) null, null); // $ Alert
98+
compiler.compile(source).load30().applyTemplates((XdmValue) null); // $ Alert
99+
compiler.compile(source).load30().applyTemplates((XdmValue) null, null); // $ Alert
100+
compiler.compile(source).load30().callFunction(null, null); // $ Alert
101+
compiler.compile(source).load30().callFunction(null, null, null); // $ Alert
102+
compiler.compile(source).load30().callTemplate(null); // $ Alert
103+
compiler.compile(source).load30().callTemplate(null, null); // $ Alert
104104
}
105105

106106
@RequestMapping
107-
public void testSaxonXsltPackage(@RequestParam String param, Socket socket) throws Exception {
107+
public void testSaxonXsltPackage(@RequestParam String param, Socket socket) throws Exception { // $ Source
108108
URI uri = new URI(param);
109-
StreamSource source = new StreamSource(socket.getInputStream());
109+
StreamSource source = new StreamSource(socket.getInputStream()); // $ Source
110110
XsltCompiler compiler = new Processor(true).newXsltCompiler();
111111

112-
compiler.loadExecutablePackage(uri).load().transform(); // $hasXsltInjection
113-
compiler.compilePackage(source).link().load().transform(); // $hasXsltInjection
114-
compiler.loadLibraryPackage(uri).link().load().transform(); // $hasXsltInjection
112+
compiler.loadExecutablePackage(uri).load().transform(); // $ Alert
113+
compiler.compilePackage(source).link().load().transform(); // $ Alert
114+
compiler.loadLibraryPackage(uri).link().load().transform(); // $ Alert
115115
}
116116

117117
public void testOkFeatureSecureProcessing(Socket socket) throws Exception {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
query: Security/CWE/CWE-074/XsltInjection.ql
2+
postprocess:
3+
- utils/test/PrettyPrintModels.ql
4+
- utils/test/InlineExpectationsTestQuery.ql
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//semmle-extractor-options: --javac-args -cp ${testdir}/../../../../stubs/springframework-5.8.x:${testdir}/../../../../stubs/shiro-core-1.5.2:${testdir}/../../../../stubs/spring-ldap-2.3.2:${testdir}/../../../../stubs/Saxon-HE-9.9.1-7:${testdir}/../../../../stubs/apache-commons-logging-1.2

java/ql/test/query-tests/security/CWE-074/XsltInjectionTest.expected

Whitespace-only changes.

java/ql/test/query-tests/security/CWE-074/XsltInjectionTest.ql

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)