1
1
import java
2
- import semmle.code.java.dataflow.FlowSources
3
- import semmle.code.java.dataflow.TaintTracking2
4
- import DataFlow:: PathGraph
5
2
6
3
/** A call to `XQConnection.prepareExpression`. */
7
4
class XQueryParserCall extends MethodAccess {
@@ -14,77 +11,25 @@ class XQueryParserCall extends MethodAccess {
14
11
m .hasName ( "prepareExpression" )
15
12
)
16
13
}
17
- /** Returns the first parameter of the `bindString` method. */
18
- Expr getInput ( ) { result = this .getArgument ( 0 ) }
19
- }
20
-
21
- /** A call to `XQDynamicContext.bindString`. */
22
- class XQueryBindStringCall extends MethodAccess {
23
- XQueryBindStringCall ( ) {
24
- exists ( Method m |
25
- this .getMethod ( ) = m and
26
- m .getDeclaringType ( )
27
- .getASourceSupertype * ( )
28
- .hasQualifiedName ( "javax.xml.xquery" , "XQDynamicContext" ) and
29
- m .hasName ( "bindString" )
30
- )
31
- }
32
- /** Returns the second parameter of the `bindString` method. */
33
- Expr getInput ( ) { result = this .getArgument ( 1 ) }
34
- }
35
-
36
- /** Used to determine whether to call the `prepareExpression` method, and the first parameter value can be remotely controlled. */
37
- class ParserParameterRemoteFlowConf extends TaintTracking2:: Configuration {
38
- ParserParameterRemoteFlowConf ( ) { this = "ParserParameterRemoteFlowConf" }
39
14
40
- override predicate isSource ( DataFlow:: Node src ) { src instanceof RemoteFlowSource }
41
-
42
- override predicate isSink ( DataFlow:: Node sink ) {
43
- exists ( XQueryParserCall xqpc | xqpc .getSink ( ) = sink .asExpr ( ) )
44
- }
45
- }
46
-
47
- /** Used to determine whether to call the `bindString` method, and the second parameter value can be controlled remotely. */
48
- class BindParameterRemoteFlowConf extends TaintTracking2:: Configuration {
49
- BindParameterRemoteFlowConf ( ) { this = "BindParameterRemoteFlowConf" }
50
-
51
- override predicate isSource ( DataFlow:: Node src ) { src instanceof RemoteFlowSource }
52
-
53
- override predicate isSink ( DataFlow:: Node sink ) {
54
- exists ( XQueryBindStringCall xqbsc | xqbsc .getSink ( ) = sink .asExpr ( ) )
55
- }
15
+ /**
16
+ * Returns the first parameter of the `prepareExpression` method, which provides
17
+ * the string, stream or reader to be compiled into a prepared expression.
18
+ */
19
+ Expr getInput ( ) { result = this .getArgument ( 0 ) }
56
20
}
57
21
58
- /**
59
- * A data flow source for XQuery injection vulnerability.
60
- * 1. `prepareExpression` call as sink.
61
- * 2. Determine whether the `var1` parameter of `prepareExpression` method can be controlled remotely.
62
- */
63
- class XQueryInjectionSource extends DataFlow:: ExprNode {
64
- XQueryInjectionSource ( ) {
65
- exists ( MethodAccess ma , Method m , ParserParameterRemoteFlowConf conf , DataFlow:: Node node |
66
- m = ma .getMethod ( )
67
- |
68
- m .hasName ( "prepareExpression" ) and
69
- m .getDeclaringType ( )
70
- .getASourceSupertype * ( )
71
- .hasQualifiedName ( "javax.xml.xquery" , "XQConnection" ) and
72
- asExpr ( ) = ma and
73
- node .asExpr ( ) = ma .getArgument ( 0 ) and
74
- conf .hasFlowTo ( node )
22
+ /** A call to `XQPreparedExpression.executeQuery`. */
23
+ class XQueryExecuteCall extends MethodAccess {
24
+ XQueryExecuteCall ( ) {
25
+ exists ( Method m | this .getMethod ( ) = m and
26
+ m .hasName ( "executeQuery" ) and
27
+ m .getDeclaringType ( )
28
+ .getASourceSupertype * ( )
29
+ .hasQualifiedName ( "javax.xml.xquery" , "XQPreparedExpression" )
75
30
)
76
31
}
77
- }
78
32
79
- /** A data flow sink for XQuery injection vulnerability. */
80
- class XQueryInjectionSink extends DataFlow:: Node {
81
- XQueryInjectionSink ( ) {
82
- exists ( MethodAccess ma , Method m | m = ma .getMethod ( ) |
83
- m .hasName ( "executeQuery" ) and
84
- m .getDeclaringType ( )
85
- .getASourceSupertype * ( )
86
- .hasQualifiedName ( "javax.xml.xquery" , "XQPreparedExpression" ) and
87
- asExpr ( ) = ma .getQualifier ( )
88
- )
89
- }
33
+ /** Return this prepared expression. */
34
+ Expr getPreparedExpression ( ) { result = this .getQualifier ( ) }
90
35
}
0 commit comments