Skip to content

Commit 6cd0087

Browse files
committed
Python: Use Value API for sensitive data analysis.
1 parent 81c65cd commit 6cd0087

File tree

5 files changed

+42
-6
lines changed

5 files changed

+42
-6
lines changed

python/ql/src/semmle/python/objects/Modules.qll

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,11 @@ class AbsentModuleAttributeObjectInternal extends ObjectInternal, TAbsentModuleA
398398

399399
override predicate subscriptUnknown() { any() }
400400

401-
/* We know what this is called, but not its innate name */
402-
override string getName() { none() }
401+
/* We know what this is called, but not its innate name.
402+
* However, if we are looking for things by name, this is a reasonable approximation */
403+
override string getName() {
404+
this = TAbsentModuleAttribute(_, result)
405+
}
403406

404407
override predicate contextSensitiveCallee() { none() }
405408

python/ql/src/semmle/python/security/SensitiveData.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ module SensitiveData {
110110
override string repr() { result = "a certificate or key" }
111111
}
112112

113-
private SensitiveData fromFunction(FunctionObject f) {
114-
result = HeuristicNames::getSensitiveDataForName(f.getName())
113+
private SensitiveData fromFunction(Value func) {
114+
result = HeuristicNames::getSensitiveDataForName(func.getName())
115115
or
116116
// This is particularly to pick up methods with an argument like "password", which
117117
// may indicate a lookup.
118-
exists(string name | name = f.getFunction().getAnArg().asName().getId() |
118+
exists(string name | name = func.(PythonFunctionValue).getScope().getAnArg().asName().getId() |
119119
result = HeuristicNames::getSensitiveDataForName(name)
120120
)
121121
}
@@ -131,7 +131,7 @@ module SensitiveData {
131131
SensitiveData data;
132132

133133
SensitiveCallSource() {
134-
exists(FunctionObject callee |
134+
exists(Value callee |
135135
callee.getACall() = this |
136136
data = fromFunction(callee)
137137
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
| test.py:16:1:16:14 | test.py:16 | a call returning a password |
2+
| test.py:17:1:17:12 | test.py:17 | a call returning a password |
3+
| test.py:18:1:18:12 | test.py:18 | a call returning a secret |
4+
| test.py:19:1:19:19 | test.py:19 | a call returning a certificate or key |
5+
| test.py:20:1:20:12 | test.py:20 | a call returning an ID |
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
import python
3+
4+
import semmle.python.security.SensitiveData
5+
6+
from SensitiveData::Source src
7+
select src.getLocation(), src.repr()
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
from not_found import get_passwd, account_id
3+
4+
def get_password():
5+
pass
6+
7+
def get_secret():
8+
pass
9+
10+
def fetch_certificate():
11+
pass
12+
13+
def encrypt_password(pwd):
14+
pass
15+
16+
get_password()
17+
get_passwd()
18+
get_secret()
19+
fetch_certificate()
20+
account_id()
21+
safe_to_store = encrypt_password(pwd)

0 commit comments

Comments
 (0)