Skip to content

Commit 35a9242

Browse files
committed
Model value passing between a setter and a getter call as a value step
1 parent 78630f2 commit 35a9242

File tree

3 files changed

+29
-32
lines changed

3 files changed

+29
-32
lines changed

java/ql/src/experimental/Security/CWE/CWE-073/FilePathInjection.ql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ class InjectFilePathConfig extends TaintTracking::Configuration {
2828
not sink instanceof NormalizedPathNode
2929
}
3030

31+
override predicate isAdditionalTaintStep(DataFlow::Node pred, DataFlow::Node succ) {
32+
any(AdditionalValueStep r).step(pred, succ)
33+
}
34+
3135
override predicate isSanitizer(DataFlow::Node node) {
3236
exists(Type t | t = node.getType() | t instanceof BoxedType or t instanceof PrimitiveType)
3337
}

java/ql/src/experimental/Security/CWE/CWE-073/JFinalController.qll

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,32 +38,25 @@ class SetRequestAttributeMethod extends Method {
3838
}
3939
}
4040

41-
/**
42-
* Holds if the result of an attribute getter call is from a method invocation of remote attribute setter.
43-
* Only values received from remote flow source is to be checked by the query.
44-
*/
45-
predicate isGetAttributeFromRemoteSource(Expr expr) {
46-
exists(MethodAccess gma, MethodAccess sma |
47-
(
48-
gma.getMethod() instanceof GetSessionAttributeMethod and
49-
sma.getMethod() instanceof SetSessionAttributeMethod
50-
or
51-
gma.getMethod() instanceof GetRequestAttributeMethod and
52-
sma.getMethod() instanceof SetRequestAttributeMethod
53-
) and
54-
expr = gma and
55-
gma.getArgument(0).(CompileTimeConstantExpr).getStringValue() =
56-
sma.getArgument(0).(CompileTimeConstantExpr).getStringValue() and
57-
gma.getEnclosingCallable() = sma.getEnclosingCallable() and
58-
TaintTracking::localExprTaint(any(RemoteFlowSource rs).asExpr(), sma.getArgument(1))
59-
)
60-
}
61-
62-
/** Remote flow source of JFinal request or session attribute getters. */
63-
private class JFinalRequestSource extends RemoteFlowSource {
64-
JFinalRequestSource() { isGetAttributeFromRemoteSource(this.asExpr()) }
65-
66-
override string getSourceType() { result = "JFinal session or request attribute source" }
41+
/** Value step from the setter call to the getter call of a session or request attribute. */
42+
private class SetToGetAttributeStep extends AdditionalValueStep {
43+
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
44+
exists(MethodAccess gma, MethodAccess sma |
45+
(
46+
gma.getMethod() instanceof GetSessionAttributeMethod and
47+
sma.getMethod() instanceof SetSessionAttributeMethod
48+
or
49+
gma.getMethod() instanceof GetRequestAttributeMethod and
50+
sma.getMethod() instanceof SetRequestAttributeMethod
51+
) and
52+
gma.getArgument(0).(CompileTimeConstantExpr).getStringValue() =
53+
sma.getArgument(0).(CompileTimeConstantExpr).getStringValue() and
54+
gma.getEnclosingCallable() = sma.getEnclosingCallable()
55+
|
56+
pred.asExpr() = sma.getArgument(1) and
57+
succ.asExpr() = gma
58+
)
59+
}
6760
}
6861

6962
/** Source model of remote flow source with `JFinal`. */
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
edges
22
| FilePathInjection.java:21:21:21:34 | getPara(...) : String | FilePathInjection.java:26:47:26:59 | finalFilePath |
3-
| FilePathInjection.java:66:29:66:55 | getSessionAttr(...) : String | FilePathInjection.java:72:47:72:59 | finalFilePath |
4-
| FilePathInjection.java:89:29:89:48 | getAttr(...) : String | FilePathInjection.java:95:47:95:59 | finalFilePath |
3+
| FilePathInjection.java:64:21:64:34 | getPara(...) : String | FilePathInjection.java:72:47:72:59 | finalFilePath |
4+
| FilePathInjection.java:87:21:87:34 | getPara(...) : String | FilePathInjection.java:95:47:95:59 | finalFilePath |
55
| FilePathInjection.java:205:17:205:44 | getParameter(...) : String | FilePathInjection.java:209:24:209:31 | filePath |
66
nodes
77
| FilePathInjection.java:21:21:21:34 | getPara(...) : String | semmle.label | getPara(...) : String |
88
| FilePathInjection.java:26:47:26:59 | finalFilePath | semmle.label | finalFilePath |
9-
| FilePathInjection.java:66:29:66:55 | getSessionAttr(...) : String | semmle.label | getSessionAttr(...) : String |
9+
| FilePathInjection.java:64:21:64:34 | getPara(...) : String | semmle.label | getPara(...) : String |
1010
| FilePathInjection.java:72:47:72:59 | finalFilePath | semmle.label | finalFilePath |
11-
| FilePathInjection.java:89:29:89:48 | getAttr(...) : String | semmle.label | getAttr(...) : String |
11+
| FilePathInjection.java:87:21:87:34 | getPara(...) : String | semmle.label | getPara(...) : String |
1212
| FilePathInjection.java:95:47:95:59 | finalFilePath | semmle.label | finalFilePath |
1313
| FilePathInjection.java:205:17:205:44 | getParameter(...) : String | semmle.label | getParameter(...) : String |
1414
| FilePathInjection.java:209:24:209:31 | filePath | semmle.label | filePath |
1515
subpaths
1616
#select
1717
| FilePathInjection.java:26:47:26:59 | finalFilePath | FilePathInjection.java:21:21:21:34 | getPara(...) : String | FilePathInjection.java:26:47:26:59 | finalFilePath | External control of file name or path due to $@. | FilePathInjection.java:21:21:21:34 | getPara(...) | user-provided value |
18-
| FilePathInjection.java:72:47:72:59 | finalFilePath | FilePathInjection.java:66:29:66:55 | getSessionAttr(...) : String | FilePathInjection.java:72:47:72:59 | finalFilePath | External control of file name or path due to $@. | FilePathInjection.java:66:29:66:55 | getSessionAttr(...) | user-provided value |
19-
| FilePathInjection.java:95:47:95:59 | finalFilePath | FilePathInjection.java:89:29:89:48 | getAttr(...) : String | FilePathInjection.java:95:47:95:59 | finalFilePath | External control of file name or path due to $@. | FilePathInjection.java:89:29:89:48 | getAttr(...) | user-provided value |
18+
| FilePathInjection.java:72:47:72:59 | finalFilePath | FilePathInjection.java:64:21:64:34 | getPara(...) : String | FilePathInjection.java:72:47:72:59 | finalFilePath | External control of file name or path due to $@. | FilePathInjection.java:64:21:64:34 | getPara(...) | user-provided value |
19+
| FilePathInjection.java:95:47:95:59 | finalFilePath | FilePathInjection.java:87:21:87:34 | getPara(...) : String | FilePathInjection.java:95:47:95:59 | finalFilePath | External control of file name or path due to $@. | FilePathInjection.java:87:21:87:34 | getPara(...) | user-provided value |
2020
| FilePathInjection.java:209:24:209:31 | filePath | FilePathInjection.java:205:17:205:44 | getParameter(...) : String | FilePathInjection.java:209:24:209:31 | filePath | External control of file name or path due to $@. | FilePathInjection.java:205:17:205:44 | getParameter(...) | user-provided value |

0 commit comments

Comments
 (0)