Skip to content

Commit 9b363ee

Browse files
committed
Make queries use ActiveThreatModelSource, not RemoteFlowSource
This means that these query will respect the threat model that is being used, rather than just using remote flow sources every time. The default threat model is "remote".
1 parent 55705d4 commit 9b363ee

14 files changed

Lines changed: 45 additions & 33 deletions

File tree

‎python/ql/lib/semmle/python/security/dataflow/NoSqlInjectionCustomizations.qll‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import python
88
import semmle.python.dataflow.new.DataFlow
9-
import semmle.python.dataflow.new.RemoteFlowSources
109
import semmle.python.Concepts
1110

1211
/**
@@ -63,8 +62,14 @@ module NoSqlInjection {
6362
abstract DataFlow::Node getOutput();
6463
}
6564

66-
/** A remote flow source considered a source of user controlled strings. */
67-
class RemoteFlowSourceAsStringSource extends RemoteFlowSource, StringSource { }
65+
/**
66+
* DEPRECATED: Use `ActiveThreatModelSource` from Concepts instead!
67+
*/
68+
deprecated class RemoteFlowSourceAsStringSource = ActiveThreatModelSourceAsStringSource;
69+
70+
/** An active threat-model source considered a source of user controlled strings. */
71+
private class ActiveThreatModelSourceAsStringSource extends StringSource instanceof ActiveThreatModelSource
72+
{ }
6873

6974
/** A NoSQL query that is vulnerable to user controlled strings. */
7075
class NoSqlExecutionAsStringSink extends StringSink {

‎python/ql/lib/semmle/python/security/dataflow/XmlBombCustomizations.qll‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
private import python
88
private import semmle.python.dataflow.new.DataFlow
99
private import semmle.python.Concepts
10-
private import semmle.python.dataflow.new.RemoteFlowSources
1110

1211
/**
1312
* Provides default sources, sinks and sanitizers for detecting "XML bomb"
@@ -29,8 +28,14 @@ module XmlBomb {
2928
*/
3029
abstract class Sanitizer extends DataFlow::Node { }
3130

32-
/** A source of remote user input, considered as a flow source for XML bomb vulnerabilities. */
33-
class RemoteFlowSourceAsSource extends Source instanceof RemoteFlowSource { }
31+
/**
32+
* DEPRECATED: Use `ActiveThreatModelSource` from Concepts instead!
33+
*/
34+
deprecated class RemoteFlowSourceAsSource = ActiveThreatModelSourceAsSource;
35+
36+
/** An active threat-model source, considered as a flow source. */
37+
private class ActiveThreatModelSourceAsSource extends Source instanceof ActiveThreatModelSource {
38+
}
3439

3540
/**
3641
* A call to an XML parser that is vulnerable to XML bombs.

‎python/ql/lib/semmle/python/security/dataflow/XxeCustomizations.qll‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
private import python
88
private import semmle.python.dataflow.new.DataFlow
99
private import semmle.python.Concepts
10-
private import semmle.python.dataflow.new.RemoteFlowSources
1110

1211
/**
1312
* Provides default sources, sinks and sanitizers for detecting "XML External Entity (XXE)"
@@ -29,8 +28,14 @@ module Xxe {
2928
*/
3029
abstract class Sanitizer extends DataFlow::Node { }
3130

32-
/** A source of remote user input, considered as a flow source for XXE vulnerabilities. */
33-
class RemoteFlowSourceAsSource extends Source instanceof RemoteFlowSource { }
31+
/**
32+
* DEPRECATED: Use `ActiveThreatModelSource` from Concepts instead!
33+
*/
34+
deprecated class RemoteFlowSourceAsSource = ActiveThreatModelSourceAsSource;
35+
36+
/** An active threat-model source, considered as a flow source. */
37+
private class ActiveThreatModelSourceAsSource extends Source instanceof ActiveThreatModelSource {
38+
}
3439

3540
/**
3641
* A call to an XML parser that is vulnerable to XXE.

‎python/ql/src/Security/CWE-020-ExternalAPIs/ExternalAPIs.qll‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
private import python
77
import semmle.python.dataflow.new.DataFlow
88
private import semmle.python.dataflow.new.TaintTracking
9-
private import semmle.python.dataflow.new.RemoteFlowSources
9+
private import semmle.python.Concepts
1010
private import semmle.python.ApiGraphs
1111
private import semmle.python.dataflow.new.internal.DataFlowPrivate as DataFlowPrivate
1212
private import semmle.python.dataflow.new.internal.TaintTrackingPrivate as TaintTrackingPrivate
@@ -168,7 +168,7 @@ class ExternalApiDataNode extends DataFlow::Node {
168168
}
169169

170170
private module UntrustedDataToExternalApiConfig implements DataFlow::ConfigSig {
171-
predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
171+
predicate isSource(DataFlow::Node source) { source instanceof ActiveThreatModelSource }
172172

173173
predicate isSink(DataFlow::Node sink) { sink instanceof ExternalApiDataNode }
174174

@@ -177,7 +177,7 @@ private module UntrustedDataToExternalApiConfig implements DataFlow::ConfigSig {
177177
}
178178
}
179179

180-
/** Global taint-tracking from `RemoteFlowSource`s to `ExternalApiDataNode`s. */
180+
/** Global taint-tracking from active threat-model sources to `ExternalApiDataNode`s. */
181181
module UntrustedDataToExternalApiFlow = TaintTracking::Global<UntrustedDataToExternalApiConfig>;
182182

183183
/** A node representing untrusted data being passed to an external API. */

‎python/ql/src/experimental/Security/CWE-176/UnicodeBypassValidationQuery.qll‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import semmle.python.Concepts
99
import semmle.python.dataflow.new.internal.DataFlowPublic
1010
import semmle.python.dataflow.new.TaintTracking
1111
import semmle.python.dataflow.new.internal.TaintTrackingPrivate
12-
import semmle.python.dataflow.new.RemoteFlowSources
1312
import UnicodeBypassValidationCustomizations::UnicodeBypassValidation
1413

1514
abstract private class ValidationState extends string {
@@ -37,7 +36,7 @@ private module UnicodeBypassValidationConfig implements DataFlow::StateConfigSig
3736
class FlowState = ValidationState;
3837

3938
predicate isSource(DataFlow::Node source, FlowState state) {
40-
source instanceof RemoteFlowSource and state instanceof PreValidation
39+
source instanceof ActiveThreatModelSource and state instanceof PreValidation
4140
}
4241

4342
predicate isAdditionalFlowStep(

‎python/ql/src/experimental/Security/CWE-346/CorsBypass.ql‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import python
1212
import semmle.python.ApiGraphs
13+
import semmle.python.Concepts
1314
import semmle.python.dataflow.new.TaintTracking
1415
import semmle.python.Flow
1516
import semmle.python.dataflow.new.RemoteFlowSources
@@ -62,7 +63,7 @@ class CherryPyRequest extends RemoteFlowSource::Range {
6263
}
6364

6465
module CorsBypassConfig implements DataFlow::ConfigSig {
65-
predicate isSource(DataFlow::Node node) { node instanceof RemoteFlowSource }
66+
predicate isSource(DataFlow::Node node) { node instanceof ActiveThreatModelSource }
6667

6768
predicate isSink(DataFlow::Node node) {
6869
exists(StringStartswithCall s |

‎python/ql/src/experimental/Security/CWE-770/UnicodeDoS.ql‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import semmle.python.ApiGraphs
1515
import semmle.python.Concepts
1616
import semmle.python.dataflow.new.TaintTracking
1717
import semmle.python.dataflow.new.internal.DataFlowPublic
18-
import semmle.python.dataflow.new.RemoteFlowSources
1918

2019
// The Unicode compatibility normalization calls from unicodedata, unidecode, pyunormalize
2120
// and textnorm modules. The use of argIdx is to constraint the argument being normalized.
@@ -86,7 +85,7 @@ predicate underAValue(DataFlow::GuardNode g, ControlFlowNode node, boolean branc
8685
}
8786

8887
private module UnicodeDoSConfig implements DataFlow::ConfigSig {
89-
predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
88+
predicate isSource(DataFlow::Node source) { source instanceof ActiveThreatModelSource }
9089

9190
predicate isBarrier(DataFlow::Node sanitizer) {
9291
// underAValue is a check to ensure that the length of the user-provided value is limited to a certain amount

‎python/ql/src/experimental/Security/UnsafeUnpackQuery.qll‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import semmle.python.dataflow.new.internal.DataFlowPublic
88
import semmle.python.ApiGraphs
99
import semmle.python.dataflow.new.TaintTracking
1010
import semmle.python.frameworks.Stdlib
11-
import semmle.python.dataflow.new.RemoteFlowSources
1211

1312
/**
1413
* Handle those three cases of Tarfile opens:
@@ -41,8 +40,8 @@ class AllTarfileOpens extends API::CallNode {
4140

4241
module UnsafeUnpackConfig implements DataFlow::ConfigSig {
4342
predicate isSource(DataFlow::Node source) {
44-
// A source coming from a remote location
45-
source instanceof RemoteFlowSource
43+
// A source enabled by the active threat model
44+
source instanceof ActiveThreatModelSource
4645
or
4746
// A source coming from a CLI argparse module
4847
// see argparse: https://docs.python.org/3/library/argparse.html

‎python/ql/src/experimental/semmle/python/security/DecompressionBomb.qll‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import python
22
import semmle.python.dataflow.new.TaintTracking
33
import semmle.python.ApiGraphs
4-
import semmle.python.dataflow.new.RemoteFlowSources
54
import semmle.python.dataflow.new.internal.DataFlowPublic
5+
import semmle.python.Concepts
66
import FileAndFormRemoteFlowSource::FileAndFormRemoteFlowSource
77
import codeql.util.Unit
88

@@ -426,7 +426,7 @@ predicate isAdditionalTaintStepTextIOWrapper(DataFlow::Node nodeFrom, DataFlow::
426426

427427
module BombsConfig implements DataFlow::ConfigSig {
428428
predicate isSource(DataFlow::Node source) {
429-
source instanceof RemoteFlowSource
429+
source instanceof ActiveThreatModelSource
430430
or
431431
source instanceof FastApi
432432
}

‎python/ql/src/experimental/semmle/python/security/LdapInsecureAuth.qll‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import python
66
import semmle.python.dataflow.new.DataFlow
77
import semmle.python.dataflow.new.TaintTracking
8-
import semmle.python.dataflow.new.RemoteFlowSources
8+
import semmle.python.Concepts
99
import experimental.semmle.python.Concepts
1010

1111
string getFullHostRegex() { result = "(?i)ldap://.+" }
@@ -90,7 +90,7 @@ class LdapStringVar extends BinaryExpr {
9090
*/
9191
private module LdapInsecureAuthConfig implements DataFlow::ConfigSig {
9292
predicate isSource(DataFlow::Node source) {
93-
source instanceof RemoteFlowSource or
93+
source instanceof ActiveThreatModelSource or
9494
source.asExpr() instanceof LdapFullHost or
9595
source.asExpr() instanceof LdapBothStrings or
9696
source.asExpr() instanceof LdapBothVar or

0 commit comments

Comments
 (0)