Skip to content

Commit 1aa32b0

Browse files
authored
Merge pull request #7802 from geoffw0/clrtxt8
C++: Recognize password struct fields.
2 parents 7bb11b8 + d864af3 commit 1aa32b0

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

cpp/ql/src/Security/CWE/CWE-311/CleartextTransmission.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class SensitiveNode extends DataFlow::Node {
2727
this.asExpr() = any(SensitiveVariable sv).getInitializer().getExpr() or
2828
this.asExpr().(VariableAccess).getTarget() =
2929
any(SensitiveVariable sv).(GlobalOrNamespaceVariable) or
30+
this.asExpr().(VariableAccess).getTarget() = any(SensitiveVariable v | v instanceof Field) or
3031
this.asUninitialized() instanceof SensitiveVariable or
3132
this.asParameter() instanceof SensitiveVariable or
3233
this.asExpr().(FunctionCall).getTarget() instanceof SensitiveFunction
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The "Cleartext transmission of sensitive information" (`cpp/cleartext-transmission`) query now finds more results, where a password is stored in a struct field or class member variable.

cpp/ql/test/query-tests/Security/CWE/CWE-311/semmle/tests/CleartextTransmission.expected

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
edges
2+
| test2.cpp:63:24:63:31 | password | test2.cpp:63:16:63:20 | call to crypt |
23
| test3.cpp:17:28:17:36 | password1 | test3.cpp:22:15:22:23 | password1 |
34
| test3.cpp:17:51:17:59 | password2 | test3.cpp:26:15:26:23 | password2 |
45
| test3.cpp:45:8:45:15 | password | test3.cpp:47:15:47:22 | password |
@@ -89,11 +90,15 @@ edges
8990
| test3.cpp:398:18:398:25 | password | test3.cpp:400:15:400:23 | & ... |
9091
| test3.cpp:398:18:398:25 | password | test3.cpp:400:16:400:23 | password |
9192
| test3.cpp:398:18:398:25 | password | test3.cpp:400:33:400:40 | password |
93+
| test3.cpp:421:21:421:28 | password | test3.cpp:421:3:421:17 | call to decrypt_inplace |
9294
| test.cpp:41:23:41:43 | cleartext password! | test.cpp:48:21:48:27 | call to encrypt |
9395
| test.cpp:41:23:41:43 | cleartext password! | test.cpp:48:29:48:39 | thePassword |
9496
| test.cpp:66:23:66:43 | cleartext password! | test.cpp:76:21:76:27 | call to encrypt |
9597
| test.cpp:66:23:66:43 | cleartext password! | test.cpp:76:29:76:39 | thePassword |
9698
nodes
99+
| test2.cpp:63:16:63:20 | call to crypt | semmle.label | call to crypt |
100+
| test2.cpp:63:24:63:31 | password | semmle.label | password |
101+
| test2.cpp:63:24:63:31 | password | semmle.label | password |
97102
| test3.cpp:17:28:17:36 | password1 | semmle.label | password1 |
98103
| test3.cpp:17:51:17:59 | password2 | semmle.label | password2 |
99104
| test3.cpp:22:15:22:23 | password1 | semmle.label | password1 |
@@ -208,6 +213,11 @@ nodes
208213
| test3.cpp:400:15:400:23 | & ... | semmle.label | & ... |
209214
| test3.cpp:400:16:400:23 | password | semmle.label | password |
210215
| test3.cpp:400:33:400:40 | password | semmle.label | password |
216+
| test3.cpp:414:17:414:24 | password | semmle.label | password |
217+
| test3.cpp:420:17:420:24 | password | semmle.label | password |
218+
| test3.cpp:421:3:421:17 | call to decrypt_inplace | semmle.label | call to decrypt_inplace |
219+
| test3.cpp:421:21:421:28 | password | semmle.label | password |
220+
| test3.cpp:421:21:421:28 | password | semmle.label | password |
211221
| test.cpp:41:23:41:43 | cleartext password! | semmle.label | cleartext password! |
212222
| test.cpp:48:21:48:27 | call to encrypt | semmle.label | call to encrypt |
213223
| test.cpp:48:29:48:39 | thePassword | semmle.label | thePassword |
@@ -238,3 +248,5 @@ subpaths
238248
| test3.cpp:300:2:300:5 | call to send | test3.cpp:308:58:308:66 | password2 | test3.cpp:300:14:300:17 | data | This operation transmits 'data', which may contain unencrypted sensitive data from $@ | test3.cpp:308:58:308:66 | password2 | password2 |
239249
| test3.cpp:341:4:341:7 | call to recv | test3.cpp:339:9:339:16 | password | test3.cpp:341:16:341:23 | password | This operation receives into 'password', which may put unencrypted sensitive data into $@ | test3.cpp:339:9:339:16 | password | password |
240250
| test3.cpp:388:3:388:6 | call to recv | test3.cpp:386:8:386:15 | password | test3.cpp:388:15:388:22 | password | This operation receives into 'password', which may put unencrypted sensitive data into $@ | test3.cpp:386:8:386:15 | password | password |
251+
| test3.cpp:414:3:414:6 | call to recv | test3.cpp:414:17:414:24 | password | test3.cpp:414:17:414:24 | password | This operation receives into 'password', which may put unencrypted sensitive data into $@ | test3.cpp:414:17:414:24 | password | password |
252+
| test3.cpp:420:3:420:6 | call to recv | test3.cpp:420:17:420:24 | password | test3.cpp:420:17:420:24 | password | This operation receives into 'password', which may put unencrypted sensitive data into $@ | test3.cpp:420:17:420:24 | password | password |

cpp/ql/test/query-tests/Security/CWE/CWE-311/semmle/tests/test3.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,13 +411,13 @@ void test_member_password()
411411
{
412412
packet p;
413413

414-
recv(val(), p.password, 256, val()); // BAD: not encrypted [NOT DETECTED]
414+
recv(val(), p.password, 256, val()); // BAD: not encrypted
415415
}
416416

417417
{
418418
packet p;
419419

420-
recv(val(), p.password, 256, val()); // GOOD: password is encrypted
420+
recv(val(), p.password, 256, val()); // GOOD: password is encrypted [FALSE POSITIVE]
421421
decrypt_inplace(p.password); // proof that `password` was in fact encrypted
422422
}
423423
}

0 commit comments

Comments
 (0)