Server Side Template Injection (SSTI)

Server Side Template Injection (SSTI)

Knowledge Base>Server Side Template Injection (SSTI)

Summary

SSTI allows an attacker to inject malicious code into server-side templates, leading to potential remote code execution, data leakage, or server compromise.

Testing methodology

${5*5}, {{5*5}}a{*test*}b${"c".join("ab")}{{5*'5'}} = 55555{{5*'5'}} = 25{{5*5}}<%=5*5%>{system('ls')}Smarty_Internal_Write_File${os.popen('ls').read()}createObject("Wscript.Shell"){{settings.SECRET_KEY}}__globals__.os.popen{{_self.env}}{{['id']|filter('system')}}
Identified Inputs
Detection
Smarty
Mako
Jinja2
Twig
CSTI
File Read/ Write
RCE
ASP

Description

Server Side Template Injection (SSTI) is a vulnerability that arises when user-controlled input is processed and rendered within server-side templates without proper validation. Attackers can exploit this vulnerability to inject malicious code into the template, which is then executed on the server-side, leading to potential remote code execution, data leakage, or even full server compromise.

Remediations

  • Avoid direct evaluation or rendering of user-controlled input within server-side templates.
  • Implement strict input validation and sanitization of user-controlled input.
  • Use context-specific output encoding or escaping when injecting user input into templates.
  • Use template engines or frameworks with built-in protections against SSTI vulnerabilities.

By using this site you agree to our Terms of Service and Privacy Policy.