Skip to content

Commit 20ad92a

Browse files
committed
C++: Filter noisiest sources.
1 parent 7b5b2fd commit 20ad92a

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

cpp/ql/src/Security/CWE/CWE-497/ExposedSystemData.ql

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ abstract class SystemData extends Element {
3232
* Data originating from the environment.
3333
*/
3434
class EnvData extends SystemData {
35-
EnvData() { this instanceof EnvironmentRead }
35+
EnvData() {
36+
// identify risky looking environment variables only
37+
this.(EnvironmentRead)
38+
.getEnvironmentVariable()
39+
.toLowerCase()
40+
.regexpMatch(".*(user|host|admin|root|home|path|http|ssl|snmp|sock|port|proxy|pass|token|crypt|key).*")
41+
}
3642

3743
override Expr getAnExpr() { result = this }
3844
}
@@ -64,11 +70,6 @@ class SQLConnectInfo extends SystemData {
6470
}
6571

6672
private predicate posixSystemInfo(FunctionCall source, Element use) {
67-
// long sysconf(int name)
68-
// - various OS / system values and limits
69-
source.getTarget().hasName("sysconf") and
70-
use = source
71-
or
7273
// size_t confstr(int name, char *buf, size_t len)
7374
// - various OS / system strings, such as the libc version
7475
// int statvfs(const char *__path, struct statvfs *__buf)

cpp/ql/test/query-tests/Security/CWE/CWE-497/semmle/tests/ExposedSystemData.expected

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ nodes
88
| tests2.cpp:63:13:63:18 | call to getenv | semmle.label | call to getenv |
99
| tests2.cpp:64:13:64:18 | call to getenv | semmle.label | call to getenv |
1010
| tests2.cpp:65:13:65:18 | call to getenv | semmle.label | call to getenv |
11-
| tests2.cpp:66:13:66:18 | call to getenv | semmle.label | call to getenv |
1211
| tests2.cpp:76:18:76:38 | call to mysql_get_client_info | semmle.label | call to mysql_get_client_info |
1312
| tests2.cpp:78:14:78:34 | call to mysql_get_client_info | semmle.label | call to mysql_get_client_info |
1413
| tests2.cpp:79:14:79:19 | buffer | semmle.label | buffer |
@@ -22,7 +21,6 @@ subpaths
2221
| tests2.cpp:63:13:63:18 | call to getenv | tests2.cpp:63:13:63:18 | call to getenv | tests2.cpp:63:13:63:18 | call to getenv | This operation exposes system data from $@. | tests2.cpp:63:13:63:18 | call to getenv | call to getenv |
2322
| tests2.cpp:64:13:64:18 | call to getenv | tests2.cpp:64:13:64:18 | call to getenv | tests2.cpp:64:13:64:18 | call to getenv | This operation exposes system data from $@. | tests2.cpp:64:13:64:18 | call to getenv | call to getenv |
2423
| tests2.cpp:65:13:65:18 | call to getenv | tests2.cpp:65:13:65:18 | call to getenv | tests2.cpp:65:13:65:18 | call to getenv | This operation exposes system data from $@. | tests2.cpp:65:13:65:18 | call to getenv | call to getenv |
25-
| tests2.cpp:66:13:66:18 | call to getenv | tests2.cpp:66:13:66:18 | call to getenv | tests2.cpp:66:13:66:18 | call to getenv | This operation exposes system data from $@. | tests2.cpp:66:13:66:18 | call to getenv | call to getenv |
2624
| tests2.cpp:78:14:78:34 | call to mysql_get_client_info | tests2.cpp:78:14:78:34 | call to mysql_get_client_info | tests2.cpp:78:14:78:34 | call to mysql_get_client_info | This operation exposes system data from $@. | tests2.cpp:78:14:78:34 | call to mysql_get_client_info | call to mysql_get_client_info |
2725
| tests2.cpp:79:14:79:19 | buffer | tests2.cpp:76:18:76:38 | call to mysql_get_client_info | tests2.cpp:79:14:79:19 | buffer | This operation exposes system data from $@. | tests2.cpp:76:18:76:38 | call to mysql_get_client_info | call to mysql_get_client_info |
2826
| tests2.cpp:109:17:109:19 | ptr | tests2.cpp:107:12:107:17 | call to getenv | tests2.cpp:109:17:109:19 | ptr | This operation exposes system data from $@. | tests2.cpp:107:12:107:17 | call to getenv | call to getenv |

cpp/ql/test/query-tests/Security/CWE/CWE-497/semmle/tests/tests2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void test1()
6363
send(sock, getenv("HOME"), val(), val()); // BAD
6464
send(sock, getenv("PATH"), val(), val()); // BAD
6565
send(sock, getenv("USERNAME"), val(), val()); // BAD
66-
send(sock, getenv("HARMLESS"), val(), val()); // GOOD: harmless information [FALSE POSITIVE]
66+
send(sock, getenv("HARMLESS"), val(), val()); // GOOD: harmless information
6767
send(sock, "HOME", val(), val()); // GOOD: not system data
6868
send(sock, "PATH", val(), val()); // GOOD: not system data
6969
send(sock, "USERNAME", val(), val()); // GOOD: not system data

0 commit comments

Comments
 (0)