Skip to content

Commit 3eb9491

Browse files
committed
python: rewrite HardcodedCredentials away from PointsTo
- `ModuleValue.attr` and `ClassValue.lookup` are approximated by `Function.getName` - `ClassValue.getName` is apprximated by `Class.getName` - `Module::named` is approximated by `Module.getName` - `Value::named` is approximated by `Builtins::likelyBuiltin` - `FunctionValue.getNamedArgumentForCall` is approximated by `ArgumentNode.argumentOf`
1 parent 9ecac04 commit 3eb9491

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

python/ql/src/Security/CWE-798/HardcodedCredentials.ql

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import python
1616
import semmle.python.dataflow.new.DataFlow
1717
import semmle.python.dataflow.new.TaintTracking
1818
import semmle.python.filters.Tests
19+
private import semmle.python.dataflow.new.internal.DataFlowDispatch as DataFlowDispatch
20+
private import semmle.python.dataflow.new.internal.Builtins::Builtins as Builtins
1921

2022
bindingset[char, fraction]
2123
predicate fewer_characters_than(StrConst str, string char, float fraction) {
@@ -30,15 +32,13 @@ predicate fewer_characters_than(StrConst str, string char, float fraction) {
3032
}
3133

3234
predicate possible_reflective_name(string name) {
33-
exists(any(ModuleValue m).attr(name))
35+
any(Function f).getName() = name
3436
or
35-
exists(any(ClassValue c).lookup(name))
37+
any(Class c).getName() = name
3638
or
37-
any(ClassValue c).getName() = name
39+
any(Module m).getName() = name
3840
or
39-
exists(Module::named(name))
40-
or
41-
exists(Value::named(name))
41+
exists(Builtins::likelyBuiltin(name))
4242
}
4343

4444
int char_count(StrConst str) { result = count(string c | c = str.getText().charAt(_)) }
@@ -84,7 +84,9 @@ class CredentialSink extends DataFlow::Node {
8484
name.regexpMatch(getACredentialRegex()) and
8585
not name.matches("%file")
8686
|
87-
any(FunctionValue func).getNamedArgumentForCall(_, name) = this.asCfgNode()
87+
exists(DataFlowDispatch::ArgumentPosition pos | pos.isKeyword(name) |
88+
this.(DataFlow::ArgumentNode).argumentOf(_, pos)
89+
)
8890
or
8991
exists(Keyword k | k.getArg() = name and k.getValue().getAFlowNode() = this.asCfgNode())
9092
or

0 commit comments

Comments
 (0)