Skip to content

Commit 3f740d6

Browse files
committed
Python: Update CWE-312 queries to use new taint-tracking configuration.
1 parent 811815a commit 3f740d6

File tree

6 files changed

+31
-23
lines changed

6 files changed

+31
-23
lines changed

python/ql/src/Security/CWE-312/CleartextLogging.ql

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ class CleartextLoggingConfiguration extends TaintTracking::Configuration {
2424

2525
CleartextLoggingConfiguration() { this = "ClearTextLogging" }
2626

27-
override predicate isSource(TaintSource src) {
28-
src instanceof SensitiveData::Source
27+
override predicate isSource(DataFlow::Node src, TaintKind kind) {
28+
src.asCfgNode().(SensitiveData::Source).isSourceOf(kind)
2929
}
3030

31-
override predicate isSink(TaintSink sink) {
32-
sink instanceof ClearTextLogging::Sink
31+
override predicate isSink(DataFlow::Node sink, TaintKind kind) {
32+
sink.asCfgNode() instanceof ClearTextLogging::Sink and
33+
kind instanceof SensitiveData
3334
}
3435

3536
}

python/ql/src/Security/CWE-312/CleartextStorage.ql

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ class CleartextStorageConfiguration extends TaintTracking::Configuration {
2323

2424
CleartextStorageConfiguration() { this = "ClearTextStorage" }
2525

26-
override predicate isSource(TaintSource src) {
27-
src instanceof SensitiveData::Source
26+
override predicate isSource(DataFlow::Node src, TaintKind kind) {
27+
src.asCfgNode().(SensitiveData::Source).isSourceOf(kind)
2828
}
2929

30-
override predicate isSink(TaintSink sink) {
31-
sink instanceof ClearTextStorage::Sink
30+
override predicate isSink(DataFlow::Node sink, TaintKind kind) {
31+
sink.asCfgNode() instanceof ClearTextStorage::Sink and
32+
kind instanceof SensitiveData
3233
}
3334

3435
}

python/ql/src/semmle/python/dataflow/Files.qll

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@ class OpenFile extends TaintKind {
1010

1111
}
1212

13+
class OpenFileConfiguration extends TaintTracking::Configuration {
1314

14-
class OpenFileSource extends TaintSource {
15+
OpenFileConfiguration() { this = "Open file configuration" }
1516

16-
OpenFileSource() {
17-
theOpenFunction().(FunctionObject).getACall() = this
17+
override predicate isSource(DataFlow::Node src, TaintKind kind) {
18+
theOpenFunction().(FunctionObject).getACall() = src.asCfgNode() and
19+
kind instanceof OpenFile
1820
}
1921

20-
override predicate isSourceOf(TaintKind kind) {
21-
kind instanceof OpenFile
22+
override predicate isSink(DataFlow::Node sink, TaintKind kind) {
23+
none()
2224
}
2325

24-
}
26+
}
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
edges
2-
| password_in_cookie.py:7:16:7:27 | dict of externally controlled string | password_in_cookie.py:7:16:7:43 | externally controlled string |
3-
| password_in_cookie.py:7:16:7:43 | a password | password_in_cookie.py:9:33:9:40 | a password |
4-
| password_in_cookie.py:7:16:7:43 | externally controlled string | password_in_cookie.py:9:33:9:40 | externally controlled string |
52
| test.py:7:16:7:29 | a password | test.py:8:35:8:42 | a password |
63
#select
7-
| test.py:8:35:8:42 | Taint sink | test.py:7:16:7:29 | a password | test.py:8:35:8:42 | a password | Sensitive data returned by $@ is logged here. | test.py:7:16:7:29 | Taint source | a call returning a password |
8-
| test.py:14:30:14:39 | Taint sink | test.py:14:30:14:39 | a certificate or key | test.py:14:30:14:39 | a certificate or key | Sensitive data returned by $@ is logged here. | test.py:14:30:14:39 | Taint source | a call returning a certificate or key |
4+
| test.py:8:35:8:42 | password | test.py:7:16:7:29 | a password | test.py:8:35:8:42 | a password | Sensitive data returned by $@ is logged here. | test.py:7:16:7:29 | get_password() | a call returning a password |
5+
| test.py:14:30:14:39 | get_cert() | test.py:14:30:14:39 | a certificate or key | test.py:14:30:14:39 | a certificate or key | Sensitive data returned by $@ is logged here. | test.py:14:30:14:39 | get_cert() | a call returning a certificate or key |
6+
| test.py:17:11:17:24 | get_password() | test.py:17:11:17:24 | a password | test.py:17:11:17:24 | a password | Sensitive data returned by $@ is logged here. | test.py:17:11:17:24 | get_password() | a call returning a password |
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
edges
2-
| password_in_cookie.py:7:16:7:27 | dict of externally controlled string | password_in_cookie.py:7:16:7:43 | externally controlled string |
32
| password_in_cookie.py:7:16:7:43 | a password | password_in_cookie.py:9:33:9:40 | a password |
4-
| password_in_cookie.py:7:16:7:43 | externally controlled string | password_in_cookie.py:9:33:9:40 | externally controlled string |
5-
| test.py:7:16:7:29 | a password | test.py:8:35:8:42 | a password |
3+
| test.py:20:12:20:21 | a certificate or key | test.py:22:20:22:23 | a certificate or key |
64
#select
7-
| password_in_cookie.py:9:33:9:40 | Taint sink | password_in_cookie.py:7:16:7:43 | a password | password_in_cookie.py:9:33:9:40 | a password | Sensitive data from $@ is stored here. | password_in_cookie.py:7:16:7:43 | Taint source | a request parameter containing a password |
5+
| password_in_cookie.py:9:33:9:40 | password | password_in_cookie.py:7:16:7:43 | a password | password_in_cookie.py:9:33:9:40 | a password | Sensitive data from $@ is stored here. | password_in_cookie.py:7:16:7:43 | Attribute() | a request parameter containing a password |
6+
| test.py:22:20:22:23 | cert | test.py:20:12:20:21 | a certificate or key | test.py:22:20:22:23 | a certificate or key | Sensitive data from $@ is stored here. | test.py:20:12:20:21 | get_cert() | a call returning a certificate or key |

python/ql/test/query-tests/Security/CWE-312/test.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,10 @@ def get_cert():
1313
def log_cert():
1414
logging.debug("Cert=%s", get_cert())
1515

16+
def print_password():
17+
print(get_password())
18+
19+
def write_cert(filename):
20+
cert = get_cert()
21+
with open(filename, "w") as file:
22+
file.write(cert)

0 commit comments

Comments
 (0)