Skip to content

Commit a28e9c5

Browse files
author
Stephan Brandauer
committed
documentation for handlebars.js flow step
1 parent 0bd9e9f commit a28e9c5

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,23 @@ module TaintStep {
5252
/**
5353
* Holds if there's a step from `pred` to `succ` due to templating data being
5454
* passed from a templating call to a registered helper via a parameter.
55+
*
56+
* To establish the step, we look at the template passed to `compile`, and will
57+
* only track steps from templates to helpers they actually reference.
58+
*
59+
* ```javascript
60+
* function loudHelper(text) {
61+
* // ^^^^ succ
62+
* return text.toUpperCase();
63+
* }
64+
*
65+
* hb.registerHelper("loud", loudHelper);
66+
*
67+
* const template = hb.compile("Hello, {{loud name}}!");
68+
*
69+
* template({name: "user"});
70+
* // ^^^^^^ pred
71+
* ```
5572
*/
5673
private predicate isHandlebarsArgStep(DataFlow::Node pred, DataFlow::Node succ) {
5774
exists(string helperName |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ const app = express();
77
const data = {};
88

99
function init() {
10+
hb.registerHelper("catFile", catFile);
1011
data.compiledFileAccess = hb.compile("contents of file {{path}} are: {{catFile path}}")
1112
data.compiledBenign = hb.compile("hello, {{name}}");
1213
data.compiledUnknown = hb.compile(fs.readFileSync("greeting.template"));
13-
hb.registerHelper("catFile", catFile);
1414
}
1515

1616
init();

0 commit comments

Comments
 (0)