Skip to content

Commit 1d2e08a

Browse files
committed
JS: now Reg Exp injection treats unknownFlags as sanitization, MetacharEscapeSanitizer
1 parent 62194f5 commit 1d2e08a

File tree

3 files changed

+2
-13
lines changed

3 files changed

+2
-13
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ module RegExpInjection {
7676
*/
7777
class MetacharEscapeSanitizer extends Sanitizer, StringReplaceCall {
7878
MetacharEscapeSanitizer() {
79-
this.isGlobal() and
79+
this.maybeGlobal() and
8080
(
8181
RegExp::alwaysMatchesMetaCharacter(this.getRegExp().getRoot(), ["{", "[", "+"])
8282
or

javascript/ql/test/query-tests/Security/CWE-730/RegExpInjection.expected

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,6 @@ nodes
7272
| RegExpInjection.js:99:19:99:106 | input.r ... "\\\\$&") |
7373
| RegExpInjection.js:100:14:100:22 | sanitized |
7474
| RegExpInjection.js:100:14:100:22 | sanitized |
75-
| RegExpInjection.js:105:7:105:122 | sanitized |
76-
| RegExpInjection.js:105:19:105:23 | input |
77-
| RegExpInjection.js:105:19:105:122 | input.r ... "\\\\$&") |
78-
| RegExpInjection.js:106:14:106:22 | sanitized |
79-
| RegExpInjection.js:106:14:106:22 | sanitized |
8075
| tst.js:5:9:5:29 | data |
8176
| tst.js:5:16:5:29 | req.query.data |
8277
| tst.js:5:16:5:29 | req.query.data |
@@ -147,17 +142,12 @@ edges
147142
| RegExpInjection.js:93:20:93:34 | process.argv[1] | RegExpInjection.js:93:16:93:49 | `^${pro ... r.app$` |
148143
| RegExpInjection.js:93:20:93:34 | process.argv[1] | RegExpInjection.js:93:16:93:49 | `^${pro ... r.app$` |
149144
| RegExpInjection.js:97:7:97:32 | input | RegExpInjection.js:99:19:99:23 | input |
150-
| RegExpInjection.js:97:7:97:32 | input | RegExpInjection.js:105:19:105:23 | input |
151145
| RegExpInjection.js:97:15:97:32 | req.param("input") | RegExpInjection.js:97:7:97:32 | input |
152146
| RegExpInjection.js:97:15:97:32 | req.param("input") | RegExpInjection.js:97:7:97:32 | input |
153147
| RegExpInjection.js:99:7:99:106 | sanitized | RegExpInjection.js:100:14:100:22 | sanitized |
154148
| RegExpInjection.js:99:7:99:106 | sanitized | RegExpInjection.js:100:14:100:22 | sanitized |
155149
| RegExpInjection.js:99:19:99:23 | input | RegExpInjection.js:99:19:99:106 | input.r ... "\\\\$&") |
156150
| RegExpInjection.js:99:19:99:106 | input.r ... "\\\\$&") | RegExpInjection.js:99:7:99:106 | sanitized |
157-
| RegExpInjection.js:105:7:105:122 | sanitized | RegExpInjection.js:106:14:106:22 | sanitized |
158-
| RegExpInjection.js:105:7:105:122 | sanitized | RegExpInjection.js:106:14:106:22 | sanitized |
159-
| RegExpInjection.js:105:19:105:23 | input | RegExpInjection.js:105:19:105:122 | input.r ... "\\\\$&") |
160-
| RegExpInjection.js:105:19:105:122 | input.r ... "\\\\$&") | RegExpInjection.js:105:7:105:122 | sanitized |
161151
| tst.js:5:9:5:29 | data | tst.js:6:21:6:24 | data |
162152
| tst.js:5:16:5:29 | req.query.data | tst.js:5:9:5:29 | data |
163153
| tst.js:5:16:5:29 | req.query.data | tst.js:5:9:5:29 | data |
@@ -183,5 +173,4 @@ edges
183173
| RegExpInjection.js:91:16:91:50 | `^${pro ... r.app$` | RegExpInjection.js:91:20:91:30 | process.env | RegExpInjection.js:91:16:91:50 | `^${pro ... r.app$` | This regular expression is constructed from a $@. | RegExpInjection.js:91:20:91:30 | process.env | environment variable |
184174
| RegExpInjection.js:93:16:93:49 | `^${pro ... r.app$` | RegExpInjection.js:93:20:93:31 | process.argv | RegExpInjection.js:93:16:93:49 | `^${pro ... r.app$` | This regular expression is constructed from a $@. | RegExpInjection.js:93:20:93:31 | process.argv | command-line argument |
185175
| RegExpInjection.js:100:14:100:22 | sanitized | RegExpInjection.js:97:15:97:32 | req.param("input") | RegExpInjection.js:100:14:100:22 | sanitized | This regular expression is constructed from a $@. | RegExpInjection.js:97:15:97:32 | req.param("input") | user-provided value |
186-
| RegExpInjection.js:106:14:106:22 | sanitized | RegExpInjection.js:97:15:97:32 | req.param("input") | RegExpInjection.js:106:14:106:22 | sanitized | This regular expression is constructed from a $@. | RegExpInjection.js:97:15:97:32 | req.param("input") | user-provided value |
187176
| tst.js:6:16:6:35 | "^"+ data.name + "$" | tst.js:5:16:5:29 | req.query.data | tst.js:6:16:6:35 | "^"+ data.name + "$" | This regular expression is constructed from a $@. | tst.js:5:16:5:29 | req.query.data | user-provided value |

javascript/ql/test/query-tests/Security/CWE-730/RegExpInjection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,5 @@ app.get("argv", function(req, res) {
103103
new RegExp(sanitized); // OK
104104

105105
var sanitized = input.replace(new RegExp("[\\-\\[\\]\\/\\{\\}\\(\\)\\*\\+\\?\\.\\\\\\^\\$\\|]", unknownFlags()), "\\$&");
106-
new RegExp(sanitized); // OK -- Currently flagged, but most likely should not be.
106+
new RegExp(sanitized); // OK -- Most likely not a problem.
107107
});

0 commit comments

Comments
 (0)