@@ -4,55 +4,47 @@ import java
4
4
import semmle.code.java.dataflow.FlowSources
5
5
import semmle.code.java.dataflow.TaintTracking
6
6
7
- /**
8
- * An abstract type representing a call to interpret XPath expressions.
9
- */
10
- class XPathSink extends MethodAccess {
11
- /**
12
- * Gets the argument representing the XPath expressions to be evaluated.
13
- */
14
- abstract Expr getSink ( ) ;
15
- }
16
-
17
7
/** The class `javax.xml.xpath.XPath` */
18
- class XPath extends RefType {
8
+ private class XPath extends RefType {
19
9
XPath ( ) { this .hasQualifiedName ( "javax.xml.xpath" , "XPath" ) }
20
10
}
21
11
22
12
/** A call to `XPath.evaluate` or `XPath.compile` */
23
- class XPathEvaluateOrCompile extends XPathSink {
13
+ private class XPathEvaluateOrCompile extends MethodAccess {
24
14
XPathEvaluateOrCompile ( ) {
25
- exists ( Method m | this .getMethod ( ) = m and m .getDeclaringType ( ) instanceof XPath |
15
+ exists ( Method m |
16
+ this .getMethod ( ) = m and m .getDeclaringType ( ) instanceof XPath
17
+ |
26
18
m .hasName ( [ "evaluate" , "compile" ] )
27
19
)
28
20
}
29
-
30
- override Expr getSink ( ) { result = this .getArgument ( 0 ) }
31
21
}
32
22
33
- /** Any class extending or implementing `org.dom4j.Node` */
34
- class Dom4JNode extends RefType {
35
- Dom4JNode ( ) {
36
- exists ( Interface node | node .hasQualifiedName ( "org.dom4j" , "Node" ) |
37
- this .extendsOrImplements * ( node )
38
- )
39
- }
23
+ /** The interface `org.dom4j.Node` */
24
+ private class Dom4JNode extends Interface {
25
+ Dom4JNode ( ) { this .hasQualifiedName ( "org.dom4j" , "Node" ) }
40
26
}
41
27
42
28
/** A call to `Node.selectNodes` or `Node.selectSingleNode` */
43
- class NodeSelectNodes extends XPathSink {
29
+ private class NodeSelectNodes extends MethodAccess {
44
30
NodeSelectNodes ( ) {
45
- exists ( Method m | this .getMethod ( ) = m and m .getDeclaringType ( ) instanceof Dom4JNode |
31
+ exists ( Method m |
32
+ this .getMethod ( ) = m and m .getDeclaringType ( ) .getASourceSupertype * ( ) instanceof Dom4JNode
33
+ |
46
34
m .hasName ( [ "selectNodes" , "selectSingleNode" ] )
47
35
)
48
36
}
49
-
50
- override Expr getSink ( ) { result = this .getArgument ( 0 ) }
51
- }
52
-
53
- /** A sink that represents a method that interprets XPath expressions. */
54
- class XPathInjectionSink extends DataFlow:: ExprNode {
55
- XPathInjectionSink ( ) { exists ( XPathSink sink | this .getExpr ( ) = sink .getSink ( ) ) }
56
37
}
57
38
39
+ /**
40
+ * A sink that represents a method that interprets XPath expressions.
41
+ * Extend this class to add your own XPath Injection sinks.
42
+ */
43
+ abstract class XPathInjectionSink extends DataFlow:: Node { }
58
44
45
+ private class DefaultXPathInjectionSink extends XPathInjectionSink {
46
+ DefaultXPathInjectionSink ( ) {
47
+ exists ( NodeSelectNodes sink | sink .getArgument ( 0 ) = this .asExpr ( ) ) or
48
+ exists ( XPathEvaluateOrCompile sink | sink .getArgument ( 0 ) = this .asExpr ( ) )
49
+ }
50
+ }
0 commit comments