Skip to content

Commit 70b8cde

Browse files
committed
add qhelp
1 parent 28951e9 commit 70b8cde

File tree

3 files changed

+54
-12
lines changed

3 files changed

+54
-12
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
<overview>
6+
<p>
7+
Directly using user-controlled objects as arguments to template engines might allow an attacker to do
8+
local file reads or even remote code execution.
9+
</p>
10+
</overview>
11+
12+
<recommendation>
13+
<p>
14+
Avoid using user-controlled objects as arguments to template engine, instead construct the object explicitly with
15+
the specific properties needed by the template.
16+
</p>
17+
</recommendation>
18+
19+
<example>
20+
<p>
21+
In the below example a server uses the user-controlled <code>profile</code> object to
22+
render the <code>index</code> template.
23+
</p>
24+
<sample src="examples/TemplateObjectInjection.js" />
25+
<p>
26+
However, if an attacker adds a <code>layout</code> property to the <code>profile</code> object then
27+
the server will load the file specified by the <code>layout</code> property, thereby allowing an attacker
28+
to do local file reads.
29+
</p>
30+
<p>
31+
The fix is to have the server construct the object, and only add the properties that are needed by the template.
32+
</p>
33+
<sample src="examples/TemplateObjectInjection_fixed.js" />
34+
</example>
35+
36+
<references>
37+
<li>
38+
blog.shoebpatel.com: <a href="https://blog.shoebpatel.com/2021/01/23/The-Secret-Parameter-LFR-and-Potential-RCE-in-NodeJS-Apps/">The Secret Parameter, LFR, and Potential RCE in NodeJS Apps</a>.
39+
</li>
40+
<li>
41+
cwe.mitre.org: <a href="https://cwe.mitre.org/data/definitions/73.html">CWE-73: External Control of File Name or Path</a>
42+
</li>
43+
44+
</references>
45+
</qhelp>
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
var app = require('express')();
22
app.set('view engine', 'hbs');
33

4-
app.post('/path', function(req, res) {
5-
var bodyParameter = req.body.bodyParameter
6-
var queryParameter = req.query.queryParameter
7-
8-
res.render('template', bodyParameter)
9-
res.render('template', queryParameter)
4+
app.post('/', function (req, res, next) {
5+
var profile = req.body.profile;
6+
res.render('index', profile);
107
});
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
var app = require('express')();
22
app.set('view engine', 'hbs');
33

4-
app.post('/path', function(req, res) {
5-
var bodyParameter = req.body.bodyParameter
6-
var queryParameter = req.query.queryParameter
7-
8-
res.render('template', {bodyParameter})
9-
res.render('template', {queryParameter})
4+
app.post('/', function (req, res, next) {
5+
var profile = req.body.profile;
6+
res.render('index', {
7+
name: profile.name,
8+
location: profile.location
9+
});
1010
});

0 commit comments

Comments
 (0)