Skip to content

Commit 5561e8f

Browse files
committed
JS: Delete old query and update qhelp
1 parent 6211fe7 commit 5561e8f

File tree

7 files changed

+65
-193
lines changed

7 files changed

+65
-193
lines changed

javascript/ql/src/Security/CWE-094/CodeInjection.qhelp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,23 @@ for example, steal cookies containing session information.
3232
<sample src="examples/CodeInjection.js" />
3333
</example>
3434

35+
<example>
36+
<p>
37+
The following example shows a Pug template being constructed from user input, allowing attackers to run
38+
arbitrary code via a payload such as <code>#{global.process.exit(1)}</code>.
39+
</p>
40+
41+
<sample src="examples/ServerSideTemplateInjection.js" />
42+
43+
<p>
44+
Below is an example of how to use a template engine without any risk of template injection.
45+
The user input is included via an interpolation expression <code>#{username}</code> whose value is provided
46+
as an option to the template, instead of being part of the template string itself:
47+
</p>
48+
49+
<sample src="examples/ServerSideTemplateInjectionSafe.js" />
50+
</example>
51+
3552
<references>
3653
<li>
3754
OWASP:
@@ -40,5 +57,13 @@ OWASP:
4057
<li>
4158
Wikipedia: <a href="https://en.wikipedia.org/wiki/Code_injection">Code Injection</a>.
4259
</li>
60+
<li>
61+
OWASP:
62+
<a href="https://owasp.org/www-project-web-security-testing-guide/latest/4-Web_Application_Security_Testing/07-Input_Validation_Testing/18-Testing_for_Server_Side_Template_Injection">Server Side Template Injection</a>.
63+
</li>
64+
<li>
65+
PortSwigger Research Blog:
66+
<a href="https://portswigger.net/research/server-side-template-injection">Server-Side Template Injection</a>.
67+
</li>
4368
</references>
4469
</qhelp>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const express = require('express')
2+
var pug = require('pug');
3+
const app = express()
4+
5+
app.post('/', (req, res) => {
6+
var input = req.query.username;
7+
var template = `
8+
doctype
9+
html
10+
head
11+
title= 'Hello world'
12+
body
13+
form(action='/' method='post')
14+
input#name.form-control(type='text)
15+
button.btn.btn-primary(type='submit') Submit
16+
p Hello `+ input
17+
var fn = pug.compile(template);
18+
var html = fn();
19+
res.send(html);
20+
})
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const express = require('express')
2+
var pug = require('pug');
3+
const app = express()
4+
5+
app.post('/', (req, res) => {
6+
var input = req.query.username;
7+
var template = `
8+
doctype
9+
html
10+
head
11+
title= 'Hello world'
12+
body
13+
form(action='/' method='post')
14+
input#name.form-control(type='text)
15+
button.btn.btn-primary(type='submit') Submit
16+
p Hello #{username}`
17+
var fn = pug.compile(template);
18+
var html = fn({username: input});
19+
res.send(html);
20+
})

javascript/ql/src/experimental/Security/CWE-94/ServerSideTemplateInjection.qhelp

Lines changed: 0 additions & 56 deletions
This file was deleted.

javascript/ql/src/experimental/Security/CWE-94/ServerSideTemplateInjection.ql

Lines changed: 0 additions & 68 deletions
This file was deleted.

javascript/ql/src/experimental/Security/CWE-94/examples/ServerSideTemplateInjection.js

Lines changed: 0 additions & 35 deletions
This file was deleted.

javascript/ql/src/experimental/Security/CWE-94/examples/ServerSideTemplateInjectionSafe.js

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)