Skip to content

Template Injection

Template injection is a sophisticated server-side attack vector where malicious users exploit template engines by injecting template directives into user-controllable input fields processed by these engines. During the Payload Execution phase, attackers leverage template injection vulnerabilities to execute arbitrary code or commands on the target system, bypassing traditional input validation mechanisms. Unlike standard injection techniques, template injection specifically targets the template rendering process where applications dynamically generate content using frameworks like Jinja2, Twig, FreeMarker, or Velocity. The attack works by inserting template syntax (such as {{7*7}} or ${7*7}) that gets evaluated server-side, potentially allowing for sandbox escapes, access to sensitive environment variables, remote code execution, or privilege escalation. This technique is particularly dangerous as it often provides direct access to the application's underlying interpreter and can be difficult to detect through standard security testing methods since it requires understanding of the specific template engine's syntax and evaluation context.