What SSTI is, conceptually
Server-side template injection happens when user input is passed into a template string that the engine actually renders, rather than only inserted as a data value inside a fixed template. Once that happens, the template engine's own expression syntax — attribute access, method calls, filters — becomes something an attacker can reach and steer.
Why Jinja-style engines are a common target
Engines like Jinja are popular in Python web frameworks specifically because they're expressive: templates can access object attributes and call methods, which is genuinely useful for developers building views. That expressiveness is exactly what makes injection dangerous if attacker-controlled input ever ends up being compiled and rendered as a template rather than passed in as a context variable.
How it tends to get introduced
Almost never on purpose. It usually creeps in through building a template string by concatenating request input directly, rendering a user-supplied string (like an 'email template' feature or custom error message) instead of passing it as data, or using a 'trust this content' flag on something that turned out to include user input further upstream.
What it can lead to
Impact ranges from information disclosure up to server-side code execution, depending on the engine's sandboxing and what objects are reachable from the template context. The specific technical mechanics aren't something we'll walk through here — the useful thing for a review checklist is knowing this class of bug exists and where to look for it, not a working payload.
Defense
The core rule: never render user input as a template. Only pass it into a template as a data variable inside a fixed, developer-authored template. If your engine offers a sandboxed environment, use it and understand its actual limits — sandboxes have had bypasses before. Keep the template rendering context free of powerful objects like file or subprocess access. Keep the templating library patched, and make 'is this ever compiled as a template' an explicit code review question.