Repository navigation
fix(a3): prevent server-side template injection - #657
Closed
gabrielesequeira wants to merge 1 commit into
Closed
gabrielesequeira wants to merge 1 commit into
gabrielesequeira wants to merge 1 commit into
Conversation
|
Hi @gabrielesequeira , After the changes you made, I was no longer able to reproduce the attack. Well done 🐼! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.pyto prevent user input from being inserted directly into the template source before compilation. Previously, the application usedtmpl.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 thenamequery parameter and passes it to the compiled template usingtemplate.generate(name=name), keeping user input separate from the template source.I also updated
src/public/index.html, replacingNAMEHEREwith{{ 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: