Skip to content

Commit 8d4a8a6

Browse files
committed
Python: Reduce the number of strings and ints identified and possible hard-coded credentials.
1 parent 66ba107 commit 8d4a8a6

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ predicate capitalized_word(StrConst str) {
5353
str.getText().regexpMatch("[A-Z][a-z]+")
5454
}
5555

56+
predicate format_string(StrConst str) {
57+
str.getText().matches("%{%}%")
58+
}
59+
5660
predicate maybeCredential(ControlFlowNode f) {
5761
/* A string that is not too short and unlikely to be text or an identifier. */
5862
exists(StrConst str |
@@ -66,20 +70,21 @@ predicate maybeCredential(ControlFlowNode f) {
6670
/* Not too repetitive */
6771
exists(int chars |
6872
chars = char_count(str) |
69-
chars > 20 or
70-
chars > str.getText().length()/2
73+
chars > 15 or
74+
chars*3 > str.getText().length()*2
7175
) and
7276
not possible_reflective_name(str.getText()) and
73-
not capitalized_word(str)
77+
not capitalized_word(str) and
78+
not format_string(str)
7479
)
7580
or
76-
/* Or, an integer with at least 8 digits */
81+
/* Or, an integer with over 32 bits */
7782
exists(IntegerLiteral lit |
7883
f.getNode() = lit
7984
|
80-
not exists(lit.getValue())
81-
or
82-
lit.getValue() > 10000000
85+
not exists(lit.getValue()) and
86+
/* Not a set of flags or round number */
87+
not lit.getN().matches("%00%")
8388
)
8489
}
8590

0 commit comments

Comments
 (0)