- Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathPasswordInConfigurationFile.ql
35 lines (33 loc) · 1.17 KB
/
PasswordInConfigurationFile.ql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* @name Password in configuration file
* @description Storing unencrypted passwords in configuration files is unsafe.
* @kind problem
* @problem.severity warning
* @security-severity 7.5
* @precision medium
* @id js/password-in-configuration-file
* @tags security
* external/cwe/cwe-256
* external/cwe/cwe-260
* external/cwe/cwe-313
* external/cwe/cwe-522
*/
import javascript
import semmle.javascript.security.PasswordInConfigurationFileQuery
fromstringkey,stringval,LocatablevalElement,stringpwd
where
config(key,val,valElement)and
val!=""and
(
key.toLowerCase()="password"and
pwd=valand
// exclude interpolations of environment variables
notval.regexpMatch("\\$.*|%.*%")and
not PasswordHeuristics::isDummyPassword(val)
or
notkey.toLowerCase()=["readme","run"]and
// look for `password=...`, but exclude `password=;`, `password="$(...)"`, `password=foo()`
// `password=%s` and `password==`
pwd=val.regexpCapture("(?is).*password\\s*=\\s*(?!;|\"?[$`]|%s|=|\\w+\\(.+\\))(\\S+).*",1)
)
selectvalElement.(FirstLineOf),"Hard-coded password '"+pwd+"' in configuration file."