Skip to content

Commit a2c4674

Browse files
committed
JS: fixed issue where MaskingReplacer would work only with regexp literals but not objects
1 parent 1ca57cf commit a2c4674

File tree

3 files changed

+5
-11
lines changed

3 files changed

+5
-11
lines changed

javascript/ql/lib/semmle/javascript/security/dataflow/CleartextLoggingCustomizations.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ module CleartextLogging {
3838
MaskingReplacer() {
3939
this.isGlobal() and
4040
exists(this.getRawReplacement().getStringValue()) and
41-
any(RegExpDot term).getLiteral() = this.getRegExp().asExpr()
41+
exists(DataFlow::RegExpCreationNode regexpObj |
42+
this.(StringReplaceCall).getRegExp() = regexpObj and
43+
regexpObj.getRoot() = any(RegExpDot term)
44+
)
4245
}
4346
}
4447

javascript/ql/test/query-tests/Security/CWE-312/CleartextLogging.expected

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,6 @@ nodes
139139
| passwords.js:176:17:176:26 | myPasscode |
140140
| passwords.js:176:17:176:26 | myPasscode |
141141
| passwords.js:176:17:176:26 | myPasscode |
142-
| passwords.js:181:14:181:21 | password |
143-
| passwords.js:181:14:181:21 | password |
144-
| passwords.js:181:14:181:56 | passwor ... ), "*") |
145-
| passwords.js:181:14:181:56 | passwor ... ), "*") |
146142
| passwords.js:182:14:182:21 | password |
147143
| passwords.js:182:14:182:21 | password |
148144
| passwords.js:182:14:182:51 | passwor ... ), "*") |
@@ -297,10 +293,6 @@ edges
297293
| passwords.js:170:11:170:18 | password | passwords.js:170:11:170:39 | passwor ... g, "*") |
298294
| passwords.js:173:17:173:26 | myPassword | passwords.js:173:17:173:26 | myPassword |
299295
| passwords.js:176:17:176:26 | myPasscode | passwords.js:176:17:176:26 | myPasscode |
300-
| passwords.js:181:14:181:21 | password | passwords.js:181:14:181:56 | passwor ... ), "*") |
301-
| passwords.js:181:14:181:21 | password | passwords.js:181:14:181:56 | passwor ... ), "*") |
302-
| passwords.js:181:14:181:21 | password | passwords.js:181:14:181:56 | passwor ... ), "*") |
303-
| passwords.js:181:14:181:21 | password | passwords.js:181:14:181:56 | passwor ... ), "*") |
304296
| passwords.js:182:14:182:21 | password | passwords.js:182:14:182:51 | passwor ... ), "*") |
305297
| passwords.js:182:14:182:21 | password | passwords.js:182:14:182:51 | passwor ... ), "*") |
306298
| passwords.js:182:14:182:21 | password | passwords.js:182:14:182:51 | passwor ... ), "*") |
@@ -356,7 +348,6 @@ edges
356348
| passwords.js:170:11:170:39 | passwor ... g, "*") | passwords.js:170:11:170:18 | password | passwords.js:170:11:170:39 | passwor ... g, "*") | This logs sensitive data returned by $@ as clear text. | passwords.js:170:11:170:18 | password | an access to password |
357349
| passwords.js:173:17:173:26 | myPassword | passwords.js:173:17:173:26 | myPassword | passwords.js:173:17:173:26 | myPassword | This logs sensitive data returned by $@ as clear text. | passwords.js:173:17:173:26 | myPassword | an access to myPassword |
358350
| passwords.js:176:17:176:26 | myPasscode | passwords.js:176:17:176:26 | myPasscode | passwords.js:176:17:176:26 | myPasscode | This logs sensitive data returned by $@ as clear text. | passwords.js:176:17:176:26 | myPasscode | an access to myPasscode |
359-
| passwords.js:181:14:181:56 | passwor ... ), "*") | passwords.js:181:14:181:21 | password | passwords.js:181:14:181:56 | passwor ... ), "*") | This logs sensitive data returned by $@ as clear text. | passwords.js:181:14:181:21 | password | an access to password |
360351
| passwords.js:182:14:182:51 | passwor ... ), "*") | passwords.js:182:14:182:21 | password | passwords.js:182:14:182:51 | passwor ... ), "*") | This logs sensitive data returned by $@ as clear text. | passwords.js:182:14:182:21 | password | an access to password |
361352
| passwords.js:183:14:183:67 | passwor ... ), "*") | passwords.js:183:14:183:21 | password | passwords.js:183:14:183:67 | passwor ... ), "*") | This logs sensitive data returned by $@ as clear text. | passwords.js:183:14:183:21 | password | an access to password |
362353
| passwords_in_server_1.js:6:13:6:20 | password | passwords_in_server_1.js:6:13:6:20 | password | passwords_in_server_1.js:6:13:6:20 | password | This logs sensitive data returned by $@ as clear text. | passwords_in_server_1.js:6:13:6:20 | password | an access to password |

javascript/ql/test/query-tests/Security/CWE-312/passwords.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ const debug = require('debug')('test');
178178

179179
(function () {
180180
console.log(password.replace(/./g, "*")); // OK
181-
console.log(password.replace(new RegExp(".", "g"), "*")); // OK -- Currently flagged, though it shouldn't be
181+
console.log(password.replace(new RegExp(".", "g"), "*")); // OK
182182
console.log(password.replace(new RegExp("."), "*")); // NOT OK
183183
console.log(password.replace(new RegExp(".", unknownFlags()), "*")); // OK -- Currently flagged, though maybe it should not be.
184184
})();

0 commit comments

Comments
 (0)