Skip to content

Commit c16e9a7

Browse files
author
Max Schaefer
committed
JavaScript: Fix a few false positives in PasswordInConfigurationFile.
1 parent d23c483 commit c16e9a7

File tree

12 files changed

+39
-6
lines changed

12 files changed

+39
-6
lines changed

change-notes/1.21/analysis-javascript.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
| Expression has no effect | Fewer false-positive results | This rule now treats uses of `Object.defineProperty` more conservatively. |
3434
| Incomplete regular expression for hostnames | More results | This rule now tracks regular expressions for host names further. |
3535
| Incomplete string escaping or encoding | More results | This rule now considers the flow of regular expressions literals, and it no longer flags the removal of trailing newlines. |
36-
| Password in configuration file | Fewer false positive results | This query now excludes passwords that are inserted into the configuration file using a templating mechanism. |
36+
| Password in configuration file | Fewer false positive results | This query now excludes passwords that are inserted into the configuration file using a templating mechanism or read from environment variables. |
3737
| Replacement of a substring with itself | More results | This rule now considers the flow of regular expressions literals. |
3838
| Server-side URL redirect | Fewer false-positive results | This rule now treats URLs as safe in more cases where the hostname cannot be tampered with. |
3939
| Type confusion through parameter tampering | Fewer false-positive results | This rule now recognizes additional emptiness checks. |

javascript/ql/src/Security/CWE-313/PasswordInConfigurationFile.ql

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,14 @@ predicate config(string key, string val, Locatable valElement) {
3535

3636
/**
3737
* Holds if file `f` should be excluded because it looks like it may be
38-
* a dictionary file, or a test or example.
38+
* an API specification, a dictionary file, or a test or example.
3939
*/
4040
predicate exclude(File f) {
41-
f.getRelativePath().regexpMatch(".*(^|/)(lang(uage)?s?|locales?|tests?|examples?)/.*")
41+
f.getRelativePath().regexpMatch("(?i).*(^|/)(lang(uage)?s?|locales?|tests?|examples?|i18n)/.*")
42+
or
43+
f.getStem().regexpMatch("(?i)translations?")
44+
or
45+
f.getExtension().toLowerCase() = "raml"
4246
}
4347

4448
from string key, string val, Locatable valElement
@@ -48,11 +52,14 @@ where
4852
// exclude possible templates
4953
not val.regexpMatch(Templating::getDelimiterMatchingRegexp()) and
5054
(
51-
key.toLowerCase() = "password"
55+
key.toLowerCase() = "password" and
56+
// exclude interpolations of environment variables
57+
not val.regexpMatch("\\$\\w+|\\$[{(].+[)}]|%.*%")
5258
or
5359
key.toLowerCase() != "readme" and
54-
// look for `password=...`, but exclude `password=;` and `password="$(...)"`
55-
val.regexpMatch("(?is).*password\\s*=(?!\\s*;)(?!\"?[$`]).*")
60+
// look for `password=...`, but exclude `password=;`, `password="$(...)"`,
61+
// `password=%s` and `password==`
62+
val.regexpMatch("(?is).*password\\s*=(?!\\s*;)(?!\"?[$`])(?!%s)(?!=).*")
5663
) and
5764
not exclude(valElement.getFile())
5865
select valElement, "Avoid plaintext passwords in configuration files."
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
| mysql-config.json:4:16:4:23 | "secret" | Avoid plaintext passwords in configuration files. |
2+
| tst4.json:2:10:2:38 | "script ... ecret'" | Avoid plaintext passwords in configuration files. |
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"password": "Passwort"
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"password": "Passwort"
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
password: string
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"password": "$pwd"
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"password": "%pwd%"
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"password": "${pwd:foo}"
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"cmd": "script.sh password='secret'"
3+
}

0 commit comments

Comments
 (0)