|
14 | 14 | */ |
15 | 15 |
|
16 | 16 | import javascript |
17 | | -import semmle.javascript.RestrictedLocations |
18 | | -import semmle.javascript.security.SensitiveActions |
19 | | - |
20 | | -/** |
21 | | - * Holds if some JSON or YAML file contains a property with name `key` |
22 | | - * and value `val`, where `valElement` is the entity corresponding to the |
23 | | - * value. |
24 | | - * |
25 | | - * Dependencies in `package.json` files are excluded by this predicate. |
26 | | - */ |
27 | | -predicate config(string key, string val, Locatable valElement) { |
28 | | - exists(JSONObject obj | not exists(PackageJSON p | obj = p.getADependenciesObject(_)) | |
29 | | - obj.getPropValue(key) = valElement and |
30 | | - val = valElement.(JSONString).getValue() |
31 | | - ) |
32 | | - or |
33 | | - exists(YAMLMapping m, YAMLString keyElement | |
34 | | - m.maps(keyElement, valElement) and |
35 | | - key = keyElement.getValue() and |
36 | | - val = valElement.(YAMLString).getValue() |
37 | | - ) |
38 | | -} |
39 | | - |
40 | | -/** |
41 | | - * Holds if file `f` should be excluded because it looks like it may be |
42 | | - * an API specification, a dictionary file, or a test or example. |
43 | | - */ |
44 | | -predicate exclude(File f) { |
45 | | - f.getRelativePath().regexpMatch("(?i).*(^|/)(lang(uage)?s?|locales?|tests?|examples?|i18n)/.*") |
46 | | - or |
47 | | - f.getStem().regexpMatch("(?i)translations?") |
48 | | - or |
49 | | - f.getExtension().toLowerCase() = "raml" |
50 | | -} |
| 17 | +import semmle.javascript.security.PasswordInConfigurationFileQuery |
51 | 18 |
|
52 | 19 | from string key, string val, Locatable valElement, string pwd |
53 | 20 | where |
54 | 21 | config(key, val, valElement) and |
55 | 22 | val != "" and |
56 | | - // exclude possible templates |
57 | | - not val.regexpMatch(Templating::getDelimiterMatchingRegexp()) and |
58 | 23 | ( |
59 | 24 | key.toLowerCase() = "password" and |
60 | 25 | pwd = val and |
|
66 | 31 | // look for `password=...`, but exclude `password=;`, `password="$(...)"`, |
67 | 32 | // `password=%s` and `password==` |
68 | 33 | pwd = val.regexpCapture("(?is).*password\\s*=\\s*(?!;|\"?[$`]|%s|=)(\\S+).*", 1) |
69 | | - ) and |
70 | | - not exclude(valElement.getFile()) |
| 34 | + ) |
71 | 35 | select valElement.(FirstLineOf), "Hard-coded password '" + pwd + "' in configuration file." |
0 commit comments