JavaScript: Fix a few false positives in PasswordInConfigurationFile.

This commit is contained in:
Max Schaefer
2019-05-07 17:41:02 +01:00
parent d23c48330c
commit c16e9a77f3
12 changed files with 39 additions and 6 deletions

View File

@@ -35,10 +35,14 @@ predicate config(string key, string val, Locatable valElement) {
/**
* Holds if file `f` should be excluded because it looks like it may be
* a dictionary file, or a test or example.
* an API specification, a dictionary file, or a test or example.
*/
predicate exclude(File f) {
f.getRelativePath().regexpMatch(".*(^|/)(lang(uage)?s?|locales?|tests?|examples?)/.*")
f.getRelativePath().regexpMatch("(?i).*(^|/)(lang(uage)?s?|locales?|tests?|examples?|i18n)/.*")
or
f.getStem().regexpMatch("(?i)translations?")
or
f.getExtension().toLowerCase() = "raml"
}
from string key, string val, Locatable valElement
@@ -48,11 +52,14 @@ where
// exclude possible templates
not val.regexpMatch(Templating::getDelimiterMatchingRegexp()) and
(
key.toLowerCase() = "password"
key.toLowerCase() = "password" and
// exclude interpolations of environment variables
not val.regexpMatch("\\$\\w+|\\$[{(].+[)}]|%.*%")
or
key.toLowerCase() != "readme" and
// look for `password=...`, but exclude `password=;` and `password="$(...)"`
val.regexpMatch("(?is).*password\\s*=(?!\\s*;)(?!\"?[$`]).*")
// look for `password=...`, but exclude `password=;`, `password="$(...)"`,
// `password=%s` and `password==`
val.regexpMatch("(?is).*password\\s*=(?!\\s*;)(?!\"?[$`])(?!%s)(?!=).*")
) and
not exclude(valElement.getFile())
select valElement, "Avoid plaintext passwords in configuration files."

View File

@@ -1 +1,2 @@
| mysql-config.json:4:16:4:23 | "secret" | Avoid plaintext passwords in configuration files. |
| tst4.json:2:10:2:38 | "script ... ecret'" | Avoid plaintext passwords in configuration files. |

View File

@@ -0,0 +1,3 @@
{
"password": "Passwort"
}

View File

@@ -0,0 +1,3 @@
{
"password": "Passwort"
}

View File

@@ -0,0 +1 @@
password: string

View File

@@ -0,0 +1,3 @@
{
"password": "$pwd"
}

View File

@@ -0,0 +1,3 @@
{
"password": "%pwd%"
}

View File

@@ -0,0 +1,3 @@
{
"password": "${pwd:foo}"
}

View File

@@ -0,0 +1,3 @@
{
"cmd": "script.sh password='secret'"
}

View File

@@ -0,0 +1,3 @@
{
"cmd": "script.sh password=%s"
}

View File

@@ -0,0 +1,3 @@
{
"foo": "password==bar"
}