Skip to content

Commit 58bcdb3

Browse files
Alvaro MuñozGeekMasher
authored andcommitted
Update CodeQL predicates used by ExternalAPIsQuery
1 parent 68fd949 commit 58bcdb3

File tree

5 files changed

+56
-55
lines changed

5 files changed

+56
-55
lines changed

csharp/lib/codeql-pack.lock.yml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@
22
lockVersion: 1.0.0
33
dependencies:
44
codeql/controlflow:
5-
version: 0.0.3
5+
version: 0.1.16
66
codeql/csharp-all:
7-
version: 0.7.4
7+
version: 0.10.1
88
codeql/dataflow:
9-
version: 0.0.3
9+
version: 0.2.7
1010
codeql/mad:
11-
version: 0.1.4
11+
version: 0.2.16
1212
codeql/ssa:
13-
version: 0.1.4
13+
version: 0.2.16
14+
codeql/threat-models:
15+
version: 0.0.15
1416
codeql/tutorial:
15-
version: 0.1.4
17+
version: 0.2.16
18+
codeql/typetracking:
19+
version: 0.2.16
1620
codeql/util:
17-
version: 0.1.4
21+
version: 0.2.16
22+
codeql/xml:
23+
version: 0.0.3
1824
compiled: false

csharp/lib/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ library: true
22
name: githubsecuritylab/codeql-csharp-libs
33
version: 0.0.1
44
dependencies:
5-
codeql/csharp-all: '*'
5+
codeql/csharp-all: 0.10.1

csharp/src/codeql-pack.lock.yml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,27 @@
22
lockVersion: 1.0.0
33
dependencies:
44
codeql/controlflow:
5-
version: 0.0.3
5+
version: 0.1.16
66
codeql/csharp-all:
7-
version: 0.7.4
7+
version: 0.10.1
88
codeql/csharp-queries:
9-
version: 0.7.4
9+
version: 0.8.16
1010
codeql/dataflow:
11-
version: 0.0.3
11+
version: 0.2.7
1212
codeql/mad:
13-
version: 0.1.4
13+
version: 0.2.16
1414
codeql/ssa:
15-
version: 0.1.4
15+
version: 0.2.16
1616
codeql/suite-helpers:
17-
version: 0.6.4
17+
version: 0.7.16
18+
codeql/threat-models:
19+
version: 0.0.15
1820
codeql/tutorial:
19-
version: 0.1.4
21+
version: 0.2.16
22+
codeql/typetracking:
23+
version: 0.2.16
2024
codeql/util:
21-
version: 0.1.4
25+
version: 0.2.16
26+
codeql/xml:
27+
version: 0.0.3
2228
compiled: false

csharp/src/library_sources/ExternalAPIsQuery.qll

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import csharp
77
private import semmle.code.csharp.commons.QualifiedName
8-
private import semmle.code.csharp.dataflow.flowsources.Remote
8+
private import semmle.code.csharp.security.dataflow.flowsources.FlowSources
99
private import semmle.code.csharp.frameworks.System
1010
private import semmle.code.csharp.dataflow.FlowSummary
1111
// SECLAB: Import CSV utils
@@ -19,9 +19,6 @@ predicate asPartialModel = ExternalFlow::asPartialModel/1;
1919
*/
2020
abstract class SafeExternalApiCallable extends Callable { }
2121

22-
/** DEPRECATED: Alias for SafeExternalApiCallable */
23-
deprecated class SafeExternalAPICallable = SafeExternalApiCallable;
24-
2522
private class SummarizedCallableSafe extends SafeExternalApiCallable instanceof SummarizedCallable {
2623
}
2724

@@ -40,7 +37,7 @@ private class DefaultSafeExternalApiCallable extends SafeExternalApiCallable {
4037
this = any(SystemStringClass s).getIsNullOrWhiteSpaceMethod() or
4138
this.getName().regexpMatch("Count|get_Count|get_Length") or
4239
// SECLAB: Exclude all .NET methods
43-
this.getDeclaringType().getQualifiedName().matches(["System.%", "Microsoft.%", "Azure.%"])
40+
this.getDeclaringType().getFullyQualifiedName().matches(["System.%", "Microsoft.%", "Azure.%"])
4441
}
4542
}
4643

@@ -81,49 +78,41 @@ class ExternalApiDataNode extends DataFlow::Node {
8178

8279
/** Holds if the callable being use has name `name` and has qualifier `qualifier`. */
8380
predicate hasQualifiedName(string qualifier, string name) {
84-
this.getCallable().hasQualifiedName(qualifier, name)
85-
}
86-
87-
/**
88-
* DEPRECATED: Use hasQualifiedName/2 instead.
89-
*
90-
* Gets the description of the callable being called.
91-
*/
92-
deprecated string getCallableDescription() {
93-
exists(string qualifier, string name |
94-
this.hasQualifiedName(qualifier, name) and result = getQualifiedName(qualifier, name)
95-
)
81+
this.getCallable().hasFullyQualifiedName(qualifier, name)
9682
}
9783
}
9884

99-
/** DEPRECATED: Alias for ExternalApiDataNode */
100-
deprecated class ExternalAPIDataNode = ExternalApiDataNode;
101-
102-
/** A configuration for tracking flow from `RemoteFlowSource`s to `ExternalApiDataNode`s. */
103-
class UntrustedDataToExternalApiConfig extends TaintTracking::Configuration {
85+
/**
86+
* DEPRECATED: Use `RemoteSourceToExternalApi` instead.
87+
*
88+
* A configuration for tracking flow from `RemoteFlowSource`s to `ExternalApiDataNode`s.
89+
*/
90+
deprecated class UntrustedDataToExternalApiConfig extends TaintTracking::Configuration {
10491
UntrustedDataToExternalApiConfig() { this = "UntrustedDataToExternalAPIConfig" }
10592

106-
override predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
93+
override predicate isSource(DataFlow::Node source) { source instanceof ThreatModelFlowSource }
10794

10895
override predicate isSink(DataFlow::Node sink) { sink instanceof ExternalApiDataNode }
10996
}
11097

111-
/** DEPRECATED: Alias for UntrustedDataToExternalApiConfig */
112-
deprecated class UntrustedDataToExternalAPIConfig = UntrustedDataToExternalApiConfig;
98+
/** A configuration for tracking flow from `ThreatModelFlowSource`s to `ExternalApiDataNode`s. */
99+
private module RemoteSourceToExternalApiConfig implements DataFlow::ConfigSig {
100+
predicate isSource(DataFlow::Node source) { source instanceof ThreatModelFlowSource }
101+
102+
predicate isSink(DataFlow::Node sink) { sink instanceof ExternalApiDataNode }
103+
}
104+
105+
/** A module for tracking flow from `ThreatModelFlowSource`s to `ExternalApiDataNode`s. */
106+
module RemoteSourceToExternalApi = TaintTracking::Global<RemoteSourceToExternalApiConfig>;
113107

114108
/** A node representing untrusted data being passed to an external API. */
115109
class UntrustedExternalApiDataNode extends ExternalApiDataNode {
116-
private UntrustedDataToExternalApiConfig c;
117-
118-
UntrustedExternalApiDataNode() { c.hasFlow(_, this) }
110+
UntrustedExternalApiDataNode() { RemoteSourceToExternalApi::flow(_, this) }
119111

120112
/** Gets a source of untrusted data which is passed to this external API data node. */
121-
DataFlow::Node getAnUntrustedSource() { c.hasFlow(result, this) }
113+
DataFlow::Node getAnUntrustedSource() { RemoteSourceToExternalApi::flow(result, this) }
122114
}
123115

124-
/** DEPRECATED: Alias for UntrustedExternalApiDataNode */
125-
deprecated class UntrustedExternalAPIDataNode = UntrustedExternalApiDataNode;
126-
127116
/** An external API which is used with untrusted data. */
128117
private newtype TExternalApi =
129118
/** An untrusted API method `m` where untrusted data is passed at `index`. */
@@ -148,13 +137,13 @@ class ExternalApiUsedWithUntrustedData extends TExternalApi {
148137

149138
/** Gets a textual representation of this element. */
150139
string toString() {
151-
exists(Callable m, int index |
140+
exists(Callable m, int index, string indexString, string qualifier, string name |
141+
if index = -1 then indexString = "qualifier" else indexString = "param " + index
142+
|
152143
this = TExternalApiParameter(m, index) and
144+
m.getDeclaringType().hasFullyQualifiedName(qualifier, name) and
153145
// SECLAB: use the CSV library to get the 6 first columns
154146
result = asPartialModel(m.getUnboundDeclaration()) + index.toString()
155147
)
156148
}
157149
}
158-
159-
/** DEPRECATED: Alias for ExternalApiUsedWithUntrustedData */
160-
deprecated class ExternalAPIUsedWithUntrustedData = ExternalApiUsedWithUntrustedData;

csharp/src/qlpack.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ version: 0.0.4
44
suites: suites
55
defaultSuiteFile: suites/csharp.qls
66
dependencies:
7-
codeql/csharp-all: "*"
8-
codeql/csharp-queries: "*" # Required for Dependencies.ql
7+
codeql/csharp-all: 0.10.1
8+
codeql/csharp-queries: 0.8.16 # Required for Dependencies.ql
99
githubsecuritylab/codeql-csharp-libs: 0.0.1

0 commit comments

Comments
 (0)