# Template injection

## What is it?

Template Injection attacks occur when an attacker can inject malicious input into template expressions, causing the application to execute unintended instructions. These attacks exploit weaknesses in the way applications interpret template expressions, often leading to remote code execution or data exposure.

Template engines are used in various programming languages and frameworks to dynamically generate HTML, XML, or other output formats. While they often have sandboxing features to limit the effects of template injection, these can sometimes be bypassed.

There are many types of Template Injection, which can occur in different template engines, including:

* Server-side Template Injection (SSTI)
* AngularJS Template Injection
* Jinja2 Template Injection
* Twig Template Injection
* Freemarker Template Injection
* Django Template Injection

## Detection

```
${3*3}
${3*'3'}
${{3*3}}
#{3*3}
*{3*3}
{{3*3}}
<%= 3*3 %>
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://appsecexplained.gitbook.io/appsecexplained/common-vulns/template-injection.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
