PHASE 1: FOUNDATION — What Is Server-Side Template Rendering, Why It Exists, and How It Works at the Most Primitive Level


This phase is not about the vulnerability. It is pure groundwork. We're dissecting what template engines are, where they live in the architecture, and how they’re intended to function — before any exploitation is possible. You must grasp the full mechanics of how data flows into and out of a template engine inside a web application. No assumptions. No compression.


🧱 I. What is Template Rendering?

A template engine is a software component used to generate dynamic content, usually HTML, by combining static templates with dynamic data. It allows developers to define placeholders inside a file (the template), which are later filled in with actual data from the server.

This process is called server-side rendering or server-side templating when it happens before the page is sent to the client.


✅ Template Rendering Workflow

Let’s start from scratch. Here’s the typical web stack flow when using a server-side template engine:

[Client Request] → [Web Server] → [App Logic] → [Template Engine] → [HTML Output] → [Client]

  1. Client sends a request: e.g., /profile?user=admin
  2. Server logic fetches relevant data from a database or other sources
  3. Template engine takes a template file like profile.html with placeholders like {{ username }}
  4. Data is injected into those placeholders: username = "admin"
  5. Final HTML is generated and sent to the browser

🧪 Example (Jinja2 in Python Flask)

Template (profile.html):

<h1>Welcome {{ username }}</h1>