You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Added a new experimental query, `rb/server-side-template-injection`, to detect cases where user input may be embedded into a template's code in an unsafe manner.
<!DOCTYPEqhelp PUBLIC "-//Semmle//qhelp//EN" "qhelp.dtd">
2
+
<qhelp>
3
+
<overview>
4
+
<p>
5
+
Template Injection occurs when user input is embedded in a template's code in an unsafe manner.
6
+
An attacker can use native template syntax to inject a malicious payload into a template, which is then executed server-side.
7
+
This permits the attacker to run arbitrary code in the server's context.
8
+
</p>
9
+
</overview>
10
+
11
+
<recommendation>
12
+
<p>
13
+
To fix this, ensure that untrusted input is not used as part of a template's code. If the application requirements do not allow this,
14
+
use a sandboxed environment where access to unsafe attributes and methods is prohibited.
15
+
</p>
16
+
</recommendation>
17
+
18
+
<example>
19
+
<p>
20
+
Consider the example given below, an untrusted HTTP parameter <code>name</code> is used to generate a template string. This can lead to remote code execution.
21
+
</p>
22
+
<samplesrc="examples/SSTIBad.rb" />
23
+
24
+
<p>
25
+
Here we have fixed the problem by including ERB/Slim syntax in the string, then the user input will be rendered but not evaluated.
26
+
</p>
27
+
<samplesrc="examples/SSTIGood.rb" />
28
+
</example>
29
+
30
+
<references>
31
+
<li>
32
+
Wikipedia: <ahref="https://en.wikipedia.org/wiki/Code_injection#Server_Side_Template_Injection">Server Side Template Injection</a>.
33
+
</li>
34
+
<li>
35
+
Portswigger : <ahref="https://portswigger.net/web-security/server-side-template-injection">Server Side Template Injection</a>.
0 commit comments