Skip to content

Commit fb66ccf

Browse files
author
Stephan Brandauer
committed
handlebars taint step: conservatively assume unknown templates have no flow to helpers
1 parent 2cbb25a commit fb66ccf

File tree

3 files changed

+8
-40
lines changed

3 files changed

+8
-40
lines changed

javascript/ql/lib/semmle/javascript/frameworks/Handlebars.qll

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -135,21 +135,12 @@ private module HandlebarsTaintSteps {
135135
DataFlow::FunctionNode helperFunction
136136
|
137137
templatingCall = compiledTemplate(compileCall).getACall() and
138-
(
139-
exists(string templateText, string paramName, int argIdx |
140-
compileCall.getArgument(0).mayHaveStringValue(templateText)
141-
|
142-
pred =
143-
templatingCall.getArgument(0).getALocalSource().getAPropertyWrite(paramName).getRhs() and
144-
isTemplateHelperCallArg(templateText, helperName, argIdx, paramName) and
145-
succ = getRegisteredHelperParam(helperName, helperFunction, argIdx)
146-
)
147-
or
148-
// When we don't have a string value, we can't be sure
149-
// and we assume a step to all parameters of all helpers.
150-
not exists(string s | compileCall.getArgument(0).mayHaveStringValue(s)) and
151-
pred = templatingCall.getArgument(0).getALocalSource().getAPropertyWrite().getRhs() and
152-
succ = getRegisteredHelperParam(helperName, helperFunction, _)
138+
exists(string templateText, string paramName, int argIdx |
139+
compileCall.getArgument(0).mayHaveStringValue(templateText)
140+
|
141+
pred = templatingCall.getArgument(0).getALocalSource().getAPropertyWrite(paramName).getRhs() and
142+
isTemplateHelperCallArg(templateText, helperName, argIdx, paramName) and
143+
succ = getRegisteredHelperParam(helperName, helperFunction, argIdx)
153144
)
154145
)
155146
}

javascript/ql/test/query-tests/Security/CWE-022/TaintedPath/TaintedPath.expected

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,11 +1564,6 @@ nodes
15641564
| handlebars.js:29:46:29:60 | req.params.path |
15651565
| handlebars.js:29:46:29:60 | req.params.path |
15661566
| handlebars.js:29:46:29:60 | req.params.path |
1567-
| handlebars.js:37:43:37:57 | req.params.name |
1568-
| handlebars.js:37:43:37:57 | req.params.name |
1569-
| handlebars.js:37:43:37:57 | req.params.name |
1570-
| handlebars.js:37:43:37:57 | req.params.name |
1571-
| handlebars.js:37:43:37:57 | req.params.name |
15721567
| handlebars.js:43:15:43:29 | req.params.path |
15731568
| handlebars.js:43:15:43:29 | req.params.path |
15741569
| handlebars.js:43:15:43:29 | req.params.path |
@@ -6471,22 +6466,6 @@ edges
64716466
| handlebars.js:29:46:29:60 | req.params.path | handlebars.js:10:51:10:58 | filePath |
64726467
| handlebars.js:29:46:29:60 | req.params.path | handlebars.js:10:51:10:58 | filePath |
64736468
| handlebars.js:29:46:29:60 | req.params.path | handlebars.js:10:51:10:58 | filePath |
6474-
| handlebars.js:37:43:37:57 | req.params.name | handlebars.js:10:51:10:58 | filePath |
6475-
| handlebars.js:37:43:37:57 | req.params.name | handlebars.js:10:51:10:58 | filePath |
6476-
| handlebars.js:37:43:37:57 | req.params.name | handlebars.js:10:51:10:58 | filePath |
6477-
| handlebars.js:37:43:37:57 | req.params.name | handlebars.js:10:51:10:58 | filePath |
6478-
| handlebars.js:37:43:37:57 | req.params.name | handlebars.js:10:51:10:58 | filePath |
6479-
| handlebars.js:37:43:37:57 | req.params.name | handlebars.js:10:51:10:58 | filePath |
6480-
| handlebars.js:37:43:37:57 | req.params.name | handlebars.js:10:51:10:58 | filePath |
6481-
| handlebars.js:37:43:37:57 | req.params.name | handlebars.js:10:51:10:58 | filePath |
6482-
| handlebars.js:37:43:37:57 | req.params.name | handlebars.js:13:73:13:80 | filePath |
6483-
| handlebars.js:37:43:37:57 | req.params.name | handlebars.js:13:73:13:80 | filePath |
6484-
| handlebars.js:37:43:37:57 | req.params.name | handlebars.js:13:73:13:80 | filePath |
6485-
| handlebars.js:37:43:37:57 | req.params.name | handlebars.js:13:73:13:80 | filePath |
6486-
| handlebars.js:37:43:37:57 | req.params.name | handlebars.js:13:73:13:80 | filePath |
6487-
| handlebars.js:37:43:37:57 | req.params.name | handlebars.js:13:73:13:80 | filePath |
6488-
| handlebars.js:37:43:37:57 | req.params.name | handlebars.js:13:73:13:80 | filePath |
6489-
| handlebars.js:37:43:37:57 | req.params.name | handlebars.js:13:73:13:80 | filePath |
64906469
| handlebars.js:43:15:43:29 | req.params.path | handlebars.js:13:73:13:80 | filePath |
64916470
| handlebars.js:43:15:43:29 | req.params.path | handlebars.js:13:73:13:80 | filePath |
64926471
| handlebars.js:43:15:43:29 | req.params.path | handlebars.js:13:73:13:80 | filePath |
@@ -9926,8 +9905,6 @@ edges
99269905
| TaintedPath.js:214:35:214:38 | path | TaintedPath.js:211:24:211:30 | req.url | TaintedPath.js:214:35:214:38 | path | This path depends on $@. | TaintedPath.js:211:24:211:30 | req.url | a user-provided value |
99279906
| express.js:8:20:8:32 | req.query.bar | express.js:8:20:8:32 | req.query.bar | express.js:8:20:8:32 | req.query.bar | This path depends on $@. | express.js:8:20:8:32 | req.query.bar | a user-provided value |
99289907
| handlebars.js:11:32:11:39 | filePath | handlebars.js:29:46:29:60 | req.params.path | handlebars.js:11:32:11:39 | filePath | This path depends on $@. | handlebars.js:29:46:29:60 | req.params.path | a user-provided value |
9929-
| handlebars.js:11:32:11:39 | filePath | handlebars.js:37:43:37:57 | req.params.name | handlebars.js:11:32:11:39 | filePath | This path depends on $@. | handlebars.js:37:43:37:57 | req.params.name | a user-provided value |
9930-
| handlebars.js:15:25:15:32 | filePath | handlebars.js:37:43:37:57 | req.params.name | handlebars.js:15:25:15:32 | filePath | This path depends on $@. | handlebars.js:37:43:37:57 | req.params.name | a user-provided value |
99319908
| handlebars.js:15:25:15:32 | filePath | handlebars.js:43:15:43:29 | req.params.path | handlebars.js:15:25:15:32 | filePath | This path depends on $@. | handlebars.js:43:15:43:29 | req.params.path | a user-provided value |
99329909
| normalizedPaths.js:13:19:13:22 | path | normalizedPaths.js:11:14:11:27 | req.query.path | normalizedPaths.js:13:19:13:22 | path | This path depends on $@. | normalizedPaths.js:11:14:11:27 | req.query.path | a user-provided value |
99339910
| normalizedPaths.js:14:19:14:29 | './' + path | normalizedPaths.js:11:14:11:27 | req.query.path | normalizedPaths.js:14:19:14:29 | './' + path | This path depends on $@. | normalizedPaths.js:11:14:11:27 | req.query.path | a user-provided value |

javascript/ql/test/query-tests/Security/CWE-022/TaintedPath/handlebars.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ app.get('/some/path2', function (req, res) {
3434
});
3535

3636
app.get('/some/path3', function (req, res) {
37-
res.send(data.compiledUnknown({ name: req.params.name })); // NOT ALLOWED (could be using a vulnerable helper)
37+
res.send(data.compiledUnknown({ name: req.params.name })); // ALLOWED (could be using a vulnerable helper, but we'll assume it's ok)
3838
});
3939

4040
app.get('/some/path4', function (req, res) {
@@ -49,4 +49,4 @@ app.get('/some/path5', function (req, res) {
4949
prefix: req.params.prefix, // ALLOWED (this parameter is safe)
5050
path: "data/path-5.txt"
5151
}));
52-
});
52+
});

0 commit comments

Comments
 (0)