Skip to content

Commit 8af7f4a

Browse files
committed
New sinks and test cases
1 parent ccb3ea4 commit 8af7f4a

File tree

4 files changed

+96
-0
lines changed

4 files changed

+96
-0
lines changed

java/ql/src/semmle/code/java/security/XPath.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ private class DefaultXPathInjectionSinkModel extends SinkModelCsv {
3131
"org.dom4j;DocumentHelper;false;createPattern;;;Argument[0];xpath",
3232
"org.dom4j;DocumentHelper;false;createXPath;;;Argument[0];xpath",
3333
"org.dom4j;DocumentHelper;false;createXPathFilter;;;Argument[0];xpath",
34+
"org.dom4j;DocumentHelper;false;selectNodes;;;Argument[0];xpath",
35+
"org.dom4j;DocumentHelper;false;sort;;;Argument[1];xpath",
3436
"org.dom4j.tree;AbstractNode;true;createXPathFilter;;;Argument[0];xpath",
3537
"org.dom4j.tree;AbstractNode;true;createPattern;;;Argument[0];xpath",
3638
"org.dom4j.util;ProxyDocumentFactory;true;createPattern;;;Argument[0];xpath",

java/ql/test/query-tests/security/CWE-643/A.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import java.io.ByteArrayInputStream;
22
import java.io.StringReader;
3+
import java.util.ArrayList;
34

45
import javax.servlet.http.HttpServletRequest;
56
import javax.xml.namespace.QName;
@@ -11,9 +12,11 @@
1112
import javax.xml.xpath.XPathExpressionException;
1213
import javax.xml.xpath.XPathFactory;
1314

15+
import org.jaxen.pattern.Pattern;
1416
import org.dom4j.DocumentFactory;
1517
import org.dom4j.DocumentHelper;
1618
import org.dom4j.Namespace;
19+
import org.dom4j.Node;
1720
import org.dom4j.io.SAXReader;
1821
import org.dom4j.util.ProxyDocumentFactory;
1922
import org.dom4j.xpath.DefaultXPath;
@@ -58,6 +61,18 @@ public String evaluate(String expression, InputSource source) throws XPathExpres
5861
private static class ProxyDocumentFactoryStub extends ProxyDocumentFactory {
5962
}
6063

64+
private static class PatternStub extends Pattern {
65+
private String text;
66+
67+
PatternStub(String text) {
68+
this.text = text;
69+
}
70+
71+
public String getText() {
72+
return text;
73+
}
74+
}
75+
6176
public void handle(HttpServletRequest request) throws Exception {
6277
String user = request.getParameter("user");
6378
String pass = request.getParameter("pass");
@@ -118,6 +133,7 @@ public void handle(HttpServletRequest request) throws Exception {
118133

119134
new DefaultXPath("/users/user[@name='" + user + "' and @pass='" + pass + "']"); // $hasXPathInjection
120135
new XPathPattern("/users/user[@name='" + user + "' and @pass='" + pass + "']"); // $hasXPathInjection
136+
new XPathPattern(new PatternStub(user)); // Safe
121137

122138
DocumentFactory docFactory = DocumentFactory.getInstance();
123139
docFactory.createPattern("/users/user[@name='" + user + "' and @pass='" + pass + "']"); // $hasXPathInjection
@@ -127,6 +143,8 @@ public void handle(HttpServletRequest request) throws Exception {
127143
DocumentHelper.createPattern("/users/user[@name='" + user + "' and @pass='" + pass + "']"); // $hasXPathInjection
128144
DocumentHelper.createXPath("/users/user[@name='" + user + "' and @pass='" + pass + "']"); // $hasXPathInjection
129145
DocumentHelper.createXPathFilter("/users/user[@name='" + user + "' and @pass='" + pass + "']"); // $hasXPathInjection
146+
DocumentHelper.selectNodes("/users/user[@name='" + user + "' and @pass='" + pass + "']", new ArrayList<Node>()); // $hasXPathInjection
147+
DocumentHelper.sort(new ArrayList<Node>(), "/users/user[@name='" + user + "' and @pass='" + pass + "']"); // $hasXPathInjection
130148

131149
ProxyDocumentFactoryStub proxyDocFactory = new ProxyDocumentFactoryStub();
132150
proxyDocFactory.createPattern("/users/user[@name='" + user + "' and @pass='" + pass + "']"); // $hasXPathInjection

java/ql/test/stubs/dom4j-2.1.1/org/dom4j/xpath/XPathPattern.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public class XPathPattern implements org.dom4j.rule.Pattern {
1919
public XPathPattern(String text) {
2020
}
2121

22+
public XPathPattern(org.jaxen.pattern.Pattern pattern) {
23+
}
24+
2225
public boolean matches(Node node) {
2326
return false;
2427
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* $Header$
3+
* $Revision$
4+
* $Date$
5+
*
6+
* ====================================================================
7+
*
8+
* Copyright 2000-2002 bob mcwhirter & James Strachan.
9+
* All rights reserved.
10+
*
11+
* Redistribution and use in source and binary forms, with or without
12+
* modification, are permitted provided that the following conditions are
13+
* met:
14+
*
15+
* * Redistributions of source code must retain the above copyright
16+
* notice, this list of conditions and the following disclaimer.
17+
*
18+
* * Redistributions in binary form must reproduce the above copyright
19+
* notice, this list of conditions and the following disclaimer in the
20+
* documentation and/or other materials provided with the distribution.
21+
*
22+
* * Neither the name of the Jaxen Project nor the names of its
23+
* contributors may be used to endorse or promote products derived
24+
* from this software without specific prior written permission.
25+
*
26+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
27+
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
29+
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
30+
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37+
*
38+
* ====================================================================
39+
* This software consists of voluntary contributions made by many
40+
* individuals on behalf of the Jaxen Project and was originally
41+
* created by bob mcwhirter <[email protected]> and
42+
* James Strachan <[email protected]>. For more information on the
43+
* Jaxen Project, please see <http://www.jaxen.org/>.
44+
*
45+
* $Id$
46+
*/
47+
48+
package org.jaxen.pattern;
49+
50+
public abstract class Pattern {
51+
public double getPriority() {
52+
return 0;
53+
}
54+
55+
public Pattern[] getUnionPatterns() {
56+
return null;
57+
}
58+
59+
public short getMatchType() {
60+
return 0;
61+
}
62+
63+
public String getMatchesNodeName() {
64+
return null;
65+
}
66+
67+
public Pattern simplify() {
68+
return null;
69+
}
70+
71+
public abstract String getText();
72+
73+
}

0 commit comments

Comments
 (0)