Skip to content

Commit e8f7e3f

Browse files
committed
Refactor ExternalAPIs.qll
1 parent ac8dec7 commit e8f7e3f

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,26 +98,39 @@ class ExternalApiDataNode extends DataFlow::Node {
9898
/** DEPRECATED: Alias for ExternalApiDataNode */
9999
deprecated class ExternalAPIDataNode = ExternalApiDataNode;
100100

101-
/** A configuration for tracking flow from `RemoteFlowSource`s to `ExternalApiDataNode`s. */
102-
class UntrustedDataToExternalApiConfig extends TaintTracking::Configuration {
101+
/**
102+
* DEPRECATED: Use `UntrustedDataToExternalApiFlow` instead.
103+
*
104+
* A configuration for tracking flow from `RemoteFlowSource`s to `ExternalApiDataNode`s.
105+
*/
106+
deprecated class UntrustedDataToExternalApiConfig extends TaintTracking::Configuration {
103107
UntrustedDataToExternalApiConfig() { this = "UntrustedDataToExternalAPIConfig" }
104108

105109
override predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
106110

107111
override predicate isSink(DataFlow::Node sink) { sink instanceof ExternalApiDataNode }
108112
}
109113

114+
private module UntrustedDataToExternalApiConfig implements DataFlow::ConfigSig {
115+
predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
116+
117+
predicate isSink(DataFlow::Node sink) { sink instanceof ExternalApiDataNode }
118+
}
119+
120+
/**
121+
* Tracks flow from untrusted data to external APIs.
122+
*/
123+
module UntrustedDataToExternalApiFlow = TaintTracking::Global<UntrustedDataToExternalApiConfig>;
124+
110125
/** DEPRECATED: Alias for UntrustedDataToExternalApiConfig */
111126
deprecated class UntrustedDataToExternalAPIConfig = UntrustedDataToExternalApiConfig;
112127

113128
/** A node representing untrusted data being passed to an external API. */
114129
class UntrustedExternalApiDataNode extends ExternalApiDataNode {
115-
UntrustedExternalApiDataNode() { any(UntrustedDataToExternalApiConfig c).hasFlow(_, this) }
130+
UntrustedExternalApiDataNode() { UntrustedDataToExternalApiFlow::flow(_, this) }
116131

117132
/** Gets a source of untrusted data which is passed to this external API data node. */
118-
DataFlow::Node getAnUntrustedSource() {
119-
any(UntrustedDataToExternalApiConfig c).hasFlow(result, this)
120-
}
133+
DataFlow::Node getAnUntrustedSource() { UntrustedDataToExternalApiFlow::flow(result, this) }
121134
}
122135

123136
/** DEPRECATED: Alias for UntrustedExternalApiDataNode */

java/ql/src/Security/CWE/CWE-020/UntrustedDataToExternalAPI.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import java
1313
import semmle.code.java.dataflow.FlowSources
1414
import semmle.code.java.dataflow.TaintTracking
1515
import semmle.code.java.security.ExternalAPIs
16-
import DataFlow::PathGraph
16+
import UntrustedDataToExternalApiFlow::PathGraph
1717

18-
from UntrustedDataToExternalApiConfig config, DataFlow::PathNode source, DataFlow::PathNode sink
19-
where config.hasFlowPath(source, sink)
18+
from UntrustedDataToExternalApiFlow::PathNode source, UntrustedDataToExternalApiFlow::PathNode sink
19+
where UntrustedDataToExternalApiFlow::flowPath(source, sink)
2020
select sink, source, sink,
2121
"Call to " + sink.getNode().(ExternalApiDataNode).getMethodDescription() +
2222
" with untrusted data from $@.", source, source.toString()

0 commit comments

Comments
 (0)