-
Notifications
You must be signed in to change notification settings - Fork 1.8k
JS: Add taint step for handlebars model #8430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0bd9e9f
add handlebars taint step
a28e9c5
documentation for handlebars.js flow step
9c3fcb6
precise tracking of handlebars arguments
a6d2ecd
review comments
8f1a359
autoformat
2cbb25a
another review fix
fb66ccf
handlebars taint step: conservatively assume unknown templates have n…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
javascript/ql/test/query-tests/Security/CWE-022/TaintedPath/handlebars.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const express = require('express'); | ||
const hb = require("handlebars"); | ||
const fs = require("fs"); | ||
|
||
const app = express(); | ||
|
||
const data = {}; | ||
|
||
function init() { | ||
hb.registerHelper("catFile", function catFile(filePath) { | ||
return fs.readFileSync(filePath); // SINK (reads file) | ||
}); | ||
hb.registerHelper("prependToLines", function prependToLines(prefix, filePath) { | ||
return fs | ||
.readFileSync(filePath) | ||
.split("\n") | ||
.map((line) => prefix + line) | ||
.join("\n"); | ||
}); | ||
data.compiledFileAccess = hb.compile("contents of file {{path}} are: {{catFile path}}") | ||
data.compiledBenign = hb.compile("hello, {{name}}"); | ||
data.compiledUnknown = hb.compile(fs.readFileSync("greeting.template")); | ||
data.compiledMixed = hb.compile("helpers may have several args, like here: {{prependToLines prefix path}}"); | ||
} | ||
|
||
init(); | ||
|
||
app.get('/some/path1', function (req, res) { | ||
res.send(data.compiledFileAccess({ path: req.params.path })); // NOT ALLOWED (template uses vulnerable catFile) | ||
}); | ||
|
||
app.get('/some/path2', function (req, res) { | ||
res.send(data.compiledBenign({ name: req.params.name })); // ALLOWED (this template does not use catFile) | ||
}); | ||
|
||
app.get('/some/path3', function (req, res) { | ||
res.send(data.compiledUnknown({ name: req.params.name })); // ALLOWED (could be using a vulnerable helper, but we'll assume it's ok) | ||
erik-krogh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
|
||
app.get('/some/path4', function (req, res) { | ||
res.send(data.compiledMixed({ | ||
prefix: ">>> ", | ||
path: req.params.path // NOT ALLOWED (template uses vulnerable helper) | ||
})); | ||
}); | ||
|
||
app.get('/some/path5', function (req, res) { | ||
res.send(data.compiledMixed({ | ||
prefix: req.params.prefix, // ALLOWED (this parameter is safe) | ||
path: "data/path-5.txt" | ||
})); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.