Skip to content

Commit 5a032d6

Browse files
committed
Python: deprecate old taint-tracking related predicates
1 parent dba6b60 commit 5a032d6

File tree

6 files changed

+29
-29
lines changed

6 files changed

+29
-29
lines changed

python/ql/lib/semmle/python/security/Paths.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import semmle.python.dataflow.Implementation
22

3-
module TaintTrackingPaths {
3+
deprecated module TaintTrackingPaths {
44
predicate edge(TaintTrackingNode src, TaintTrackingNode dest, string label) {
55
exists(TaintTrackingNode source, TaintTrackingNode sink |
66
source.getConfiguration().hasFlowPath(source, sink) and
@@ -11,6 +11,6 @@ module TaintTrackingPaths {
1111
}
1212
}
1313

14-
query predicate edges(TaintTrackingNode fromnode, TaintTrackingNode tonode) {
14+
deprecated query predicate edges(TaintTrackingNode fromnode, TaintTrackingNode tonode) {
1515
TaintTrackingPaths::edge(fromnode, tonode, _)
1616
}

python/ql/lib/semmle/python/security/flow/AnyCall.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import python
22
import semmle.python.security.strings.Basic
33

44
/** Assume that taint flows from argument to result for *any* call */
5-
class AnyCallStringFlow extends DataFlowExtension::DataFlowNode {
5+
deprecated class AnyCallStringFlow extends DataFlowExtension::DataFlowNode {
66
AnyCallStringFlow() { any(CallNode call).getAnArg() = this }
77

88
override ControlFlowNode getASuccessorNode() { result.(CallNode).getAnArg() = this }

python/ql/lib/semmle/python/security/strings/Basic.qll

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ private import Common
33
import semmle.python.dataflow.TaintTracking
44

55
/** An extensible kind of taint representing any kind of string. */
6-
abstract class StringKind extends TaintKind {
6+
abstract deprecated class StringKind extends TaintKind {
77
bindingset[this]
88
StringKind() { this = this }
99

@@ -42,7 +42,7 @@ abstract class StringKind extends TaintKind {
4242
}
4343
}
4444

45-
private class StringEqualitySanitizer extends Sanitizer {
45+
deprecated private class StringEqualitySanitizer extends Sanitizer {
4646
StringEqualitySanitizer() { this = "string equality sanitizer" }
4747

4848
/** The test `if untrusted == "KNOWN_VALUE":` sanitizes `untrusted` on its `true` edge. */
@@ -64,13 +64,13 @@ private class StringEqualitySanitizer extends Sanitizer {
6464
}
6565

6666
/** tonode = ....format(fromnode) */
67-
private predicate str_format(ControlFlowNode fromnode, CallNode tonode) {
67+
deprecated private predicate str_format(ControlFlowNode fromnode, CallNode tonode) {
6868
tonode.getFunction().(AttrNode).getName() = "format" and
6969
tonode.getAnArg() = fromnode
7070
}
7171

7272
/** tonode = codec.[en|de]code(fromnode) */
73-
private predicate encode_decode(ControlFlowNode fromnode, CallNode tonode) {
73+
deprecated private predicate encode_decode(ControlFlowNode fromnode, CallNode tonode) {
7474
exists(FunctionObject func, string name |
7575
not func.getFunction().isMethod() and
7676
func.getACall() = tonode and
@@ -84,7 +84,7 @@ private predicate encode_decode(ControlFlowNode fromnode, CallNode tonode) {
8484
}
8585

8686
/** tonode = str(fromnode) */
87-
private predicate to_str(ControlFlowNode fromnode, CallNode tonode) {
87+
deprecated private predicate to_str(ControlFlowNode fromnode, CallNode tonode) {
8888
tonode.getAnArg() = fromnode and
8989
(
9090
tonode = ClassValue::bytes().getACall()
@@ -94,7 +94,7 @@ private predicate to_str(ControlFlowNode fromnode, CallNode tonode) {
9494
}
9595

9696
/** tonode = fromnode[:] */
97-
private predicate slice(ControlFlowNode fromnode, SubscriptNode tonode) {
97+
deprecated private predicate slice(ControlFlowNode fromnode, SubscriptNode tonode) {
9898
exists(Slice all |
9999
all = tonode.getIndex().getNode() and
100100
not exists(all.getStart()) and
@@ -104,13 +104,13 @@ private predicate slice(ControlFlowNode fromnode, SubscriptNode tonode) {
104104
}
105105

106106
/** tonode = os.path.join(..., fromnode, ...) */
107-
private predicate os_path_join(ControlFlowNode fromnode, CallNode tonode) {
107+
deprecated private predicate os_path_join(ControlFlowNode fromnode, CallNode tonode) {
108108
tonode = Value::named("os.path.join").getACall() and
109109
tonode.getAnArg() = fromnode
110110
}
111111

112112
/** tonode = f"... {fromnode} ..." */
113-
private predicate f_string(ControlFlowNode fromnode, ControlFlowNode tonode) {
113+
deprecated private predicate f_string(ControlFlowNode fromnode, ControlFlowNode tonode) {
114114
tonode.getNode().(Fstring).getAValue() = fromnode.getNode()
115115
}
116116

@@ -119,6 +119,6 @@ private predicate f_string(ControlFlowNode fromnode, ControlFlowNode tonode) {
119119
*
120120
* DEPRECATED: Use `ExternalStringDictKind` instead.
121121
*/
122-
deprecated class StringDictKind extends DictKind {
122+
deprecated deprecated class StringDictKind extends DictKind {
123123
StringDictKind() { this.getValue() instanceof StringKind }
124124
}

python/ql/lib/semmle/python/security/strings/Common.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import python
22

33
/* A call that returns a copy (or similar) of the argument */
4-
predicate copy_call(ControlFlowNode fromnode, CallNode tonode) {
4+
deprecated predicate copy_call(ControlFlowNode fromnode, CallNode tonode) {
55
tonode.getFunction().(AttrNode).getObject("copy") = fromnode
66
or
77
exists(ModuleValue copy, string name | name = "copy" or name = "deepcopy" |

python/ql/lib/semmle/python/security/strings/External.qll

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ private import Common
55
/**
66
* An extensible kind of taint representing an externally controlled string.
77
*/
8-
abstract class ExternalStringKind extends StringKind {
8+
abstract deprecated class ExternalStringKind extends StringKind {
99
bindingset[this]
1010
ExternalStringKind() { this = this }
1111

@@ -30,15 +30,15 @@ abstract class ExternalStringKind extends StringKind {
3030
}
3131

3232
/** A kind of "taint", representing a sequence, with a "taint" member */
33-
class ExternalStringSequenceKind extends SequenceKind {
33+
deprecated class ExternalStringSequenceKind extends SequenceKind {
3434
ExternalStringSequenceKind() { this.getItem() instanceof ExternalStringKind }
3535
}
3636

3737
/**
3838
* An hierachical dictionary or list where the entire structure is externally controlled
3939
* This is typically a parsed JSON object.
4040
*/
41-
class ExternalJsonKind extends TaintKind {
41+
deprecated class ExternalJsonKind extends TaintKind {
4242
ExternalJsonKind() { this = "json[" + any(ExternalStringKind key) + "]" }
4343

4444
/** Gets the taint kind for item in this sequence */
@@ -61,20 +61,20 @@ class ExternalJsonKind extends TaintKind {
6161
}
6262

6363
/** A kind of "taint", representing a dictionary mapping keys to tainted strings. */
64-
class ExternalStringDictKind extends DictKind {
64+
deprecated class ExternalStringDictKind extends DictKind {
6565
ExternalStringDictKind() { this.getValue() instanceof ExternalStringKind }
6666
}
6767

6868
/**
6969
* A kind of "taint", representing a dictionary mapping keys to sequences of
7070
* tainted strings.
7171
*/
72-
class ExternalStringSequenceDictKind extends DictKind {
72+
deprecated class ExternalStringSequenceDictKind extends DictKind {
7373
ExternalStringSequenceDictKind() { this.getValue() instanceof ExternalStringSequenceKind }
7474
}
7575

7676
/** TaintKind for the result of `urlsplit(tainted_string)` */
77-
class ExternalUrlSplitResult extends ExternalStringSequenceKind {
77+
deprecated class ExternalUrlSplitResult extends ExternalStringSequenceKind {
7878
// https://docs.python.org/3/library/urllib.parse.html#urllib.parse.urlsplit
7979
override TaintKind getTaintOfAttribute(string name) {
8080
result = super.getTaintOfAttribute(name)
@@ -103,7 +103,7 @@ class ExternalUrlSplitResult extends ExternalStringSequenceKind {
103103
}
104104

105105
/** TaintKind for the result of `urlparse(tainted_string)` */
106-
class ExternalUrlParseResult extends ExternalStringSequenceKind {
106+
deprecated class ExternalUrlParseResult extends ExternalStringSequenceKind {
107107
// https://docs.python.org/3/library/urllib.parse.html#urllib.parse.urlparse
108108
override TaintKind getTaintOfAttribute(string name) {
109109
result = super.getTaintOfAttribute(name)
@@ -134,20 +134,20 @@ class ExternalUrlParseResult extends ExternalStringSequenceKind {
134134

135135
/* Helper for getTaintForStep() */
136136
pragma[noinline]
137-
private predicate json_subscript_taint(
137+
deprecated deprecated private predicate json_subscript_taint(
138138
SubscriptNode sub, ControlFlowNode obj, ExternalJsonKind seq, TaintKind key
139139
) {
140140
sub.isLoad() and
141141
sub.getObject() = obj and
142142
key = seq.getValue()
143143
}
144144

145-
private predicate json_load(ControlFlowNode fromnode, CallNode tonode) {
145+
deprecated private predicate json_load(ControlFlowNode fromnode, CallNode tonode) {
146146
tonode = Value::named("json.loads").getACall() and
147147
tonode.getArg(0) = fromnode
148148
}
149149

150-
private predicate urlsplit(ControlFlowNode fromnode, CallNode tonode) {
150+
deprecated private predicate urlsplit(ControlFlowNode fromnode, CallNode tonode) {
151151
// This could be implemented as `exists(FunctionValue` without the explicit six part,
152152
// but then our tests will need to import +100 modules, so for now this slightly
153153
// altered version gets to live on.
@@ -166,7 +166,7 @@ private predicate urlsplit(ControlFlowNode fromnode, CallNode tonode) {
166166
)
167167
}
168168

169-
private predicate urlparse(ControlFlowNode fromnode, CallNode tonode) {
169+
deprecated private predicate urlparse(ControlFlowNode fromnode, CallNode tonode) {
170170
// This could be implemented as `exists(FunctionValue` without the explicit six part,
171171
// but then our tests will need to import +100 modules, so for now this slightly
172172
// altered version gets to live on.
@@ -185,7 +185,7 @@ private predicate urlparse(ControlFlowNode fromnode, CallNode tonode) {
185185
)
186186
}
187187

188-
private predicate parse_qs(ControlFlowNode fromnode, CallNode tonode) {
188+
deprecated private predicate parse_qs(ControlFlowNode fromnode, CallNode tonode) {
189189
// This could be implemented as `exists(FunctionValue` without the explicit six part,
190190
// but then our tests will need to import +100 modules, so for now this slightly
191191
// altered version gets to live on.
@@ -211,7 +211,7 @@ private predicate parse_qs(ControlFlowNode fromnode, CallNode tonode) {
211211
)
212212
}
213213

214-
private predicate parse_qsl(ControlFlowNode fromnode, CallNode tonode) {
214+
deprecated private predicate parse_qsl(ControlFlowNode fromnode, CallNode tonode) {
215215
// This could be implemented as `exists(FunctionValue` without the explicit six part,
216216
// but then our tests will need to import +100 modules, so for now this slightly
217217
// altered version gets to live on.
@@ -238,7 +238,7 @@ private predicate parse_qsl(ControlFlowNode fromnode, CallNode tonode) {
238238
}
239239

240240
/** A kind of "taint", representing an open file-like object from an external source. */
241-
class ExternalFileObject extends TaintKind {
241+
deprecated class ExternalFileObject extends TaintKind {
242242
ExternalStringKind valueKind;
243243

244244
ExternalFileObject() { this = "file[" + valueKind + "]" }
@@ -266,7 +266,7 @@ class ExternalFileObject extends TaintKind {
266266
* - `if splitres.netloc == "KNOWN_VALUE"`
267267
* - `if splitres[0] == "KNOWN_VALUE"`
268268
*/
269-
class UrlsplitUrlparseTempSanitizer extends Sanitizer {
269+
deprecated class UrlsplitUrlparseTempSanitizer extends Sanitizer {
270270
// TODO: remove this once we have better support for named tuples
271271
UrlsplitUrlparseTempSanitizer() { this = "UrlsplitUrlparseTempSanitizer" }
272272

python/ql/lib/semmle/python/security/strings/Untrusted.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ import External
55
* A kind of taint representing an externally controlled string.
66
* This class is a simple sub-class of `ExternalStringKind`.
77
*/
8-
class UntrustedStringKind extends ExternalStringKind {
8+
deprecated class UntrustedStringKind extends ExternalStringKind {
99
UntrustedStringKind() { this = "externally controlled string" }
1010
}

0 commit comments

Comments
 (0)