Skip to content

Commit d94b11b

Browse files
committed
C#: Re-factor ExtertalApisQuery to use the new API.
1 parent d049b11 commit d94b11b

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

csharp/ql/lib/semmle/code/csharp/security/dataflow/ExternalAPIsQuery.qll

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,26 +90,38 @@ class ExternalApiDataNode extends DataFlow::Node {
9090
/** DEPRECATED: Alias for ExternalApiDataNode */
9191
deprecated class ExternalAPIDataNode = ExternalApiDataNode;
9292

93-
/** A configuration for tracking flow from `RemoteFlowSource`s to `ExternalApiDataNode`s. */
94-
class UntrustedDataToExternalApiConfig extends TaintTracking::Configuration {
93+
/**
94+
* DEPRECATED: Use `RemoteSourceToExternalApi` instead.
95+
*
96+
* A configuration for tracking flow from `RemoteFlowSource`s to `ExternalApiDataNode`s.
97+
*/
98+
deprecated class UntrustedDataToExternalApiConfig extends TaintTracking::Configuration {
9599
UntrustedDataToExternalApiConfig() { this = "UntrustedDataToExternalAPIConfig" }
96100

97101
override predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
98102

99103
override predicate isSink(DataFlow::Node sink) { sink instanceof ExternalApiDataNode }
100104
}
101105

106+
/** A configuration for tracking flow from `RemoteFlowSource`s to `ExternalApiDataNode`s. */
107+
private module RemoteSourceToExternalApiConfig implements DataFlow::ConfigSig {
108+
predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
109+
110+
predicate isSink(DataFlow::Node sink) { sink instanceof ExternalApiDataNode }
111+
}
112+
113+
/** A module for tracking flow from `RemoteFlowSource`s to `ExternalApiDataNode`s. */
114+
module RemoteSourceToExternalApi = TaintTracking::Global<RemoteSourceToExternalApiConfig>;
115+
102116
/** DEPRECATED: Alias for UntrustedDataToExternalApiConfig */
103117
deprecated class UntrustedDataToExternalAPIConfig = UntrustedDataToExternalApiConfig;
104118

105119
/** A node representing untrusted data being passed to an external API. */
106120
class UntrustedExternalApiDataNode extends ExternalApiDataNode {
107-
private UntrustedDataToExternalApiConfig c;
108-
109-
UntrustedExternalApiDataNode() { c.hasFlow(_, this) }
121+
UntrustedExternalApiDataNode() { RemoteSourceToExternalApi::flow(_, this) }
110122

111123
/** Gets a source of untrusted data which is passed to this external API data node. */
112-
DataFlow::Node getAnUntrustedSource() { c.hasFlow(result, this) }
124+
DataFlow::Node getAnUntrustedSource() { RemoteSourceToExternalApi::flow(result, this) }
113125
}
114126

115127
/** DEPRECATED: Alias for UntrustedExternalApiDataNode */

csharp/ql/src/Security Features/CWE-020/UntrustedDataToExternalAPI.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
import csharp
1313
import semmle.code.csharp.commons.QualifiedName
1414
import semmle.code.csharp.security.dataflow.ExternalAPIsQuery
15-
import DataFlow::PathGraph
15+
import RemoteSourceToExternalApi::PathGraph
1616

1717
from
18-
UntrustedDataToExternalApiConfig config, DataFlow::PathNode source, DataFlow::PathNode sink,
18+
RemoteSourceToExternalApi::PathNode source, RemoteSourceToExternalApi::PathNode sink,
1919
string qualifier, string name
2020
where
21-
config.hasFlowPath(source, sink) and
21+
RemoteSourceToExternalApi::flowPath(source, sink) and
2222
sink.getNode().(ExternalApiDataNode).hasQualifiedName(qualifier, name)
2323
select sink, source, sink,
2424
"Call to " + getQualifiedName(qualifier, name) + " with untrusted data from $@.", source,

0 commit comments

Comments
 (0)