mirror of
https://github.com/github/codeql.git
synced 2026-04-30 03:05:15 +02:00
JavaScript: Fix a few false positives in PasswordInConfigurationFile.
This commit is contained in:
@@ -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."
|
||||
|
||||
@@ -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. |
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"password": "Passwort"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"password": "Passwort"
|
||||
}
|
||||
1
javascript/ql/test/query-tests/Security/CWE-313/tst.raml
Normal file
1
javascript/ql/test/query-tests/Security/CWE-313/tst.raml
Normal file
@@ -0,0 +1 @@
|
||||
password: string
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"password": "$pwd"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"password": "%pwd%"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"password": "${pwd:foo}"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"cmd": "script.sh password='secret'"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"cmd": "script.sh password=%s"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"foo": "password==bar"
|
||||
}
|
||||
Reference in New Issue
Block a user