Skip to content

Commit 2f09f0e

Browse files
committed
C++: Turn the huge list into a predicate.
1 parent 13ae15b commit 2f09f0e

File tree

1 file changed

+12
-62
lines changed

1 file changed

+12
-62
lines changed

cpp/ql/src/Security/CWE/CWE-290/AuthenticationBypass.ql

Lines changed: 12 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@
1515
import semmle.code.cpp.ir.dataflow.internal.DefaultTaintTrackingImpl
1616
import TaintedWithPath
1717

18+
string getATopLevelDomain() {
19+
result =
20+
[
21+
"com", "ru", "net", "org", "de", "jp", "uk", "br", "pl", "in", "it", "fr", "au", "info", "nl",
22+
"cn", "ir", "es", "cz", "biz", "ca", "eu", "ua", "kr", "za", "co", "gr", "ro", "se", "tw",
23+
"vn", "mx", "ch", "tr", "at", "be", "hu", "tv", "dk", "me", "ar", "us", "no", "sk", "fi",
24+
"id", "cl", "nz", "by", "xyz", "pt", "ie", "il", "kz", "my", "hk", "lt", "cc", "sg", "io",
25+
"edu", "gov"
26+
]
27+
}
28+
1829
predicate hardCodedAddressOrIP(StringLiteral txt) {
1930
exists(string s | s = txt.getValueText() |
2031
// Hard-coded ip addresses, such as 127.0.0.1
@@ -23,68 +34,7 @@ predicate hardCodedAddressOrIP(StringLiteral txt) {
2334
s.matches("\"www.%\"") or
2435
s.matches("\"http:%\"") or
2536
s.matches("\"https:%\"") or
26-
s.matches("\"%.com\"") or
27-
s.matches("\"%.ru\"") or
28-
s.matches("\"%.net\"") or
29-
s.matches("\"%.org\"") or
30-
s.matches("\"%.de\"") or
31-
s.matches("\"%.jp\"") or
32-
s.matches("\"%.uk\"") or
33-
s.matches("\"%.br\"") or
34-
s.matches("\"%.pl\"") or
35-
s.matches("\"%.in\"") or
36-
s.matches("\"%.it\"") or
37-
s.matches("\"%.fr\"") or
38-
s.matches("\"%.au\"") or
39-
s.matches("\"%.info\"") or
40-
s.matches("\"%.nl\"") or
41-
s.matches("\"%.cn\"") or
42-
s.matches("\"%.ir\"") or
43-
s.matches("\"%.es\"") or
44-
s.matches("\"%.cz\"") or
45-
s.matches("\"%.biz\"") or
46-
s.matches("\"%.ca\"") or
47-
s.matches("\"%.eu\"") or
48-
s.matches("\"%.ua\"") or
49-
s.matches("\"%.kr\"") or
50-
s.matches("\"%.za\"") or
51-
s.matches("\"%.co\"") or
52-
s.matches("\"%.gr\"") or
53-
s.matches("\"%.ro\"") or
54-
s.matches("\"%.se\"") or
55-
s.matches("\"%.tw\"") or
56-
s.matches("\"%.vn\"") or
57-
s.matches("\"%.mx\"") or
58-
s.matches("\"%.ch\"") or
59-
s.matches("\"%.tr\"") or
60-
s.matches("\"%.at\"") or
61-
s.matches("\"%.be\"") or
62-
s.matches("\"%.hu\"") or
63-
s.matches("\"%.tv\"") or
64-
s.matches("\"%.dk\"") or
65-
s.matches("\"%.me\"") or
66-
s.matches("\"%.ar\"") or
67-
s.matches("\"%.us\"") or
68-
s.matches("\"%.no\"") or
69-
s.matches("\"%.sk\"") or
70-
s.matches("\"%.fi\"") or
71-
s.matches("\"%.id\"") or
72-
s.matches("\"%.cl\"") or
73-
s.matches("\"%.nz\"") or
74-
s.matches("\"%.by\"") or
75-
s.matches("\"%.xyz\"") or
76-
s.matches("\"%.pt\"") or
77-
s.matches("\"%.ie\"") or
78-
s.matches("\"%.il\"") or
79-
s.matches("\"%.kz\"") or
80-
s.matches("\"%.my\"") or
81-
s.matches("\"%.hk\"") or
82-
s.matches("\"%.lt\"") or
83-
s.matches("\"%.cc\"") or
84-
s.matches("\"%.sg\"") or
85-
s.matches("\"%.io\"") or
86-
s.matches("\"%.edu\"") or
87-
s.matches("\"%.gov\"")
37+
s.regexpMatch("\".*\\." + getATopLevelDomain() + "\"")
8838
)
8939
}
9040

0 commit comments

Comments
 (0)