Skip to content

fix(a3): prevent server-side template injection - #657

Closed
gabrielesequeira wants to merge 1 commit into
globocom:masterfrom
gabrielesequeira:feature/a3-sstype
Closed

gabrielesequeira wants to merge 1 commit into
globocom:masterfrom
gabrielesequeira:feature/a3-sstype

Conversation

@gabrielesequeira

Copy link
Copy Markdown

This solution refers to which of the apps?

A3 - Injection - Server-Side Template Injection (SSTI).

What did you do to mitigate the vulnerability?

I modified src/server.py to prevent user input from being inserted directly into the template source before compilation. Previously, the application used tmpl.replace("NAMEHERE", name) to replace a placeholder with the user-provided name and then compiled the resulting template. This allowed malicious input to be interpreted as template code by Tornado.

For that cause, I changed the application to compile the original, trusted HTML template once, outside the request handler. The get() method now just retrieves the name query parameter and passes it to the compiled template using template.generate(name=name), keeping user input separate from the template source.

I also updated src/public/index.html, replacing NAMEHERE with {{ name }} so Tornado can render the provided name through its template variable. These changes prevent user input from being compiled as part of the template source and reduce the risk of Server-Side Template Injection (SSTI).

Did you test your changes? What commands did you run?

I tested the application using two URL parameters:

/?name=Gabriele — output: Hello: Gabriele

/?name=%7B%7B7*7%7D%7D — output: Hello: {{7*7}}, instead of Hello: 49. (treating the input as a string rather than executing it as template code)

@vitor-mauricio

Copy link
Copy Markdown

Hi @gabrielesequeira , After the changes you made, I was no longer able to reproduce the attack. Well done 🐼!

@vitor-mauricio vitor-mauricio added mitigation solution 🔒 This is a possible way to fix this vulnerability SSType labels Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mitigation solution 🔒 This is a possible way to fix this vulnerability SSType

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants