Skip to content

Commit cd661f1

Browse files
committed
Refactor SensitiveResultReceiver
1 parent 735a738 commit cd661f1

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

java/ql/lib/semmle/code/java/security/SensitiveResultReceiverQuery.qll

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,45 +17,44 @@ private class ResultReceiverSendCall extends MethodAccess {
1717
Expr getSentData() { result = this.getArgument(1) }
1818
}
1919

20-
private class UntrustedResultReceiverConf extends TaintTracking2::Configuration {
21-
UntrustedResultReceiverConf() { this = "UntrustedResultReceiverConf" }
20+
private module UntrustedResultReceiverConfig implements DataFlow::ConfigSig {
21+
predicate isSource(DataFlow::Node node) { node instanceof RemoteFlowSource }
2222

23-
override predicate isSource(DataFlow::Node node) { node instanceof RemoteFlowSource }
24-
25-
override predicate isSink(DataFlow::Node node) {
23+
predicate isSink(DataFlow::Node node) {
2624
node.asExpr() = any(ResultReceiverSendCall c).getReceiver()
2725
}
2826
}
2927

28+
private module UntrustedResultReceiverFlow = TaintTracking::Global<UntrustedResultReceiverConfig>;
29+
3030
private predicate untrustedResultReceiverSend(DataFlow::Node src, ResultReceiverSendCall call) {
31-
any(UntrustedResultReceiverConf c).hasFlow(src, DataFlow::exprNode(call.getReceiver()))
31+
UntrustedResultReceiverFlow::flow(src, DataFlow::exprNode(call.getReceiver()))
3232
}
3333

34-
private class SensitiveResultReceiverConf extends TaintTracking::Configuration {
35-
SensitiveResultReceiverConf() { this = "SensitiveResultReceiverConf" }
36-
37-
override predicate isSource(DataFlow::Node node) { node.asExpr() instanceof SensitiveExpr }
34+
private module SensitiveResultReceiverConfig implements DataFlow::ConfigSig {
35+
predicate isSource(DataFlow::Node node) { node.asExpr() instanceof SensitiveExpr }
3836

39-
override predicate isSink(DataFlow::Node node) {
37+
predicate isSink(DataFlow::Node node) {
4038
exists(ResultReceiverSendCall call |
4139
untrustedResultReceiverSend(_, call) and
4240
node.asExpr() = call.getSentData()
4341
)
4442
}
4543

46-
override predicate allowImplicitRead(DataFlow::Node node, DataFlow::ContentSet c) {
47-
super.allowImplicitRead(node, c)
48-
or
49-
this.isSink(node)
50-
}
44+
predicate allowImplicitRead(DataFlow::Node node, DataFlow::ContentSet c) { isSink(node) }
5145
}
5246

53-
/** Holds if there is a path from sensitive data at `src` to a result receiver at `sink`, and the receiver was obtained from an untrusted source `recSrc`. */
47+
module SensitiveResultReceiverFlow = TaintTracking::Global<SensitiveResultReceiverConfig>;
48+
49+
/**
50+
* Holds if there is a path from sensitive data at `src` to a result receiver at `sink`, and the receiver was obtained from an untrusted source `recSrc`.
51+
*/
5452
predicate sensitiveResultReceiver(
55-
DataFlow::PathNode src, DataFlow::PathNode sink, DataFlow::Node recSrc
53+
SensitiveResultReceiverFlow::PathNode src, SensitiveResultReceiverFlow::PathNode sink,
54+
DataFlow::Node recSrc
5655
) {
57-
exists(ResultReceiverSendCall call, SensitiveResultReceiverConf conf |
58-
conf.hasFlowPath(src, sink) and
56+
exists(ResultReceiverSendCall call |
57+
SensitiveResultReceiverFlow::flowPath(src, sink) and
5958
sink.getNode().asExpr() = call.getSentData() and
6059
untrustedResultReceiverSend(recSrc, call)
6160
)

java/ql/src/Security/CWE/CWE-927/SensitiveResultReceiver.ql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313

1414
import java
1515
import semmle.code.java.security.SensitiveResultReceiverQuery
16-
import DataFlow::PathGraph
16+
import SensitiveResultReceiverFlow::PathGraph
1717

18-
from DataFlow::PathNode src, DataFlow::PathNode sink, DataFlow::Node recSrc
18+
from
19+
SensitiveResultReceiverFlow::PathNode src, SensitiveResultReceiverFlow::PathNode sink,
20+
DataFlow::Node recSrc
1921
where sensitiveResultReceiver(src, sink, recSrc)
2022
select sink, src, sink, "This $@ is sent to a ResultReceiver obtained from $@.", src,
2123
"sensitive information", recSrc, "this untrusted source"

0 commit comments

Comments
 (0)