template injection
An injection attack where a user supplies the template itself, letting them walk into objects and data the template was never meant to show.
A user-controlled template can read data and sometimes run code on the server.
In more detail
Some template languages, such as Python's str.format, can follow attributes and indexes, so a template chosen by a caller is a small program. Templates are code and belong in your repository; caller data is only ever a value passed to one.
Example
In the course, Python's str.format follows dotted attributes, so the template {u.__init__.__globals__[SECRET]} prints a deploy key.Related terms
- injection — A bug where untrusted data reaches an interpreter and part of it is read as code instead of as a value.
- format method — The string method that returns a copy of a string with each {} replacement field filled in from its arguments.
Taught in
- Injection In All Its Forms — Application Security & Threat Modeling for Engineers