Skip to content

Commit 8310c96

Browse files
Update javascript/ql/src/experimental/Security/CWE-94/ServerSideTemplateInjection.qhelp
Co-authored-by: Erik Krogh Kristensen <[email protected]>
1 parent 25df6e1 commit 8310c96

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@ render engine with sandbox options.
2323
<p>
2424
The following example shows a page being rendered with user input allowing attackers to access the
2525
template context and run arbitrary code on the application server.
26-
Pug template engine (and other template engines) provides Interpolation feature - insertion of variable values into a string of some kind.
27-
For example, `Hello #{user.username}!`, could be used for printing username from scoped variable user, but `user.username` expression will be executed as valid javascript code.
28-
Unsafe injection of user input provides attacker ability to inject conteqnt like #{some_js_expression}.
29-
Injection of `#{global.process.exit(1)}` leads to code execution of `global.process.exit(1)` by server.
30-
Working exploit (as curl command):
31-
curl -i -s -k -X $'POST' -H $'Host: 127.0.0.1:5061' -H $'Connection: close' -H $'Content-Length: 40' -H $'Content-Type: application/x-www-form-urlencoded' --data-binary $'name=%23%7Bglobal.process.exit%281%29%7D' $'http://127.0.0.1:5061/'
26+
The Pug template engine (and other template engines) provides an interpolation feature - insertion of variable values into a string of some kind.
27+
For example, <code>Hello #{user.username}!</code>, could be used for printing a username from a scoped variable user,
28+
but the <code>user.username</code> expression will be executed as JavaScript.
29+
Unsafe injection of user input in a template therefore allows an attacker to inject arbitrary JavaScript code.
30+
For example, a payload of <code>#{global.process.exit(1)}</code> will cause the server to crash.
3231
</p>
3332

3433
<sample src="examples/ServerSideTemplateInjection.js" />

0 commit comments

Comments
 (0)