Skip to content

Commit 87bc8ae

Browse files
committed
Python: Don't use UntrustedStringKind in web lib
If I wanted to use my own TaintKind and not have any interaction with `UntrustedStringKind` that wouldn't be possible today since these standard http libraries import it directly. (also, I wouldn't get any sources of my custom TaintKind from turbogears or bottle). I changed them to use the same pattern of `ExternalStringKind` as everything else does.
1 parent ae4f6ed commit 87bc8ae

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

python/ql/src/semmle/python/web/bottle/Request.qll

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import python
22
import semmle.python.dataflow.TaintTracking
3-
import semmle.python.security.strings.Untrusted
3+
import semmle.python.security.strings.External
44
import semmle.python.web.Http
55
import semmle.python.web.bottle.General
66

@@ -13,7 +13,7 @@ class BottleRequestKind extends TaintKind {
1313
result instanceof BottleFormsDict and
1414
(name = "cookies" or name = "query" or name = "form")
1515
or
16-
result instanceof UntrustedStringKind and
16+
result instanceof ExternalStringKind and
1717
(name = "query_string" or name = "url_args")
1818
or
1919
result.(DictKind).getValue() instanceof FileUpload and
@@ -34,27 +34,27 @@ class BottleFormsDict extends TaintKind {
3434
/* Cannot use `getTaintOfAttribute(name)` as it wouldn't bind `name` */
3535
exists(string name |
3636
fromnode = tonode.(AttrNode).getObject(name) and
37-
result instanceof UntrustedStringKind
37+
result instanceof ExternalStringKind
3838
|
3939
name != "get" and name != "getunicode" and name != "getall"
4040
)
4141
}
4242

4343
override TaintKind getTaintOfMethodResult(string name) {
4444
(name = "get" or name = "getunicode") and
45-
result instanceof UntrustedStringKind
45+
result instanceof ExternalStringKind
4646
or
47-
name = "getall" and result.(SequenceKind).getItem() instanceof UntrustedStringKind
47+
name = "getall" and result.(SequenceKind).getItem() instanceof ExternalStringKind
4848
}
4949
}
5050

5151
class FileUpload extends TaintKind {
5252
FileUpload() { this = "bottle.FileUpload" }
5353

5454
override TaintKind getTaintOfAttribute(string name) {
55-
name = "filename" and result instanceof UntrustedStringKind
55+
name = "filename" and result instanceof ExternalStringKind
5656
or
57-
name = "raw_filename" and result instanceof UntrustedStringKind
57+
name = "raw_filename" and result instanceof ExternalStringKind
5858
or
5959
name = "file" and result instanceof UntrustedFile
6060
}
@@ -74,7 +74,7 @@ class BottleRequestParameter extends HttpRequestTaintSource {
7474
exists(BottleRoute route | route.getANamedArgument() = this.(ControlFlowNode).getNode())
7575
}
7676

77-
override predicate isSourceOf(TaintKind kind) { kind instanceof UntrustedStringKind }
77+
override predicate isSourceOf(TaintKind kind) { kind instanceof ExternalStringKind }
7878

7979
override string toString() { result = "bottle handler function argument" }
8080
}

python/ql/src/semmle/python/web/turbogears/Request.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import python
2-
import semmle.python.security.strings.Untrusted
2+
import semmle.python.security.strings.External
33
import semmle.python.web.Http
44
import TurboGears
55

@@ -22,5 +22,5 @@ class UnvalidatedControllerMethodParameter extends HttpRequestTaintSource {
2222
)
2323
}
2424

25-
override predicate isSourceOf(TaintKind kind) { kind instanceof UntrustedStringKind }
25+
override predicate isSourceOf(TaintKind kind) { kind instanceof ExternalStringKind }
2626
}

0 commit comments

Comments
 (0)