# Template Expression Injection via Raw Input

User or stored values reaching template compilers, evaluators or preprocessors as source instead of bound data

_Area: Web injection and code execution. Seen in 3 disclosed reports; one confirmed bounty: $4,500; latest 2026-08-21. Updated 2026-12-01._

## How it works
A component treats a value as *source to compile or evaluate* rather than as *data to bind*. The assumption that breaks is "this field is just a string": the string is handed to a template engine, expression evaluator, or code generator that parses it. Anything the parser accepts becomes executable. Three shapes appear in the evidence: a stored field interpolated into a markup template whose attribute the engine `eval`s [E2](https://bugbountylibrary.com/r/blog%3Agithub-com-sudistark-bb-writeups-blob-main-2023-cve-2023-33733-rce-via-htmli-in-reportlab-md.md); a compiler filter that splices raw token bytes into generated PHP [E3](https://bugbountylibrary.com/r/ghsa%3AGHSA-hrwp-4hh9-c8r8.md); and a request-controlled value choosing *which* template path/loader is used, so attacker-supplied template source is what gets compiled [E1](https://bugbountylibrary.com/r/blog%3Aassetnote-io-resources-research-how-an-obscure-php-footgun-led-to-rce-in-craft-cms.md). In all three the data/code boundary is crossed at the parse step, not at any later sanitizer.

## Where it shows up
- Values interpolated into a template string before rendering (e.g. `<font color=USER>`), especially attributes the engine evaluates [E2](https://bugbountylibrary.com/r/blog%3Agithub-com-sudistark-bb-writeups-blob-main-2023-cve-2023-33733-rce-via-htmli-in-reportlab-md.md).
- Template compiler cases that read raw token bytes (`expr.value`) and concatenate them into generated code instead of routing through the expression emitter [E3](https://bugbountylibrary.com/r/ghsa%3AGHSA-hrwp-4hh9-c8r8.md).
- Config/path values taken from request-derived globals (`$_SERVER['argv']`, headers, query tokens) and used to select template paths or loaders [E1](https://bugbountylibrary.com/r/blog%3Aassetnote-io-resources-research-how-an-obscure-php-footgun-led-to-rce-in-craft-cms.md).
- Any `eval`, `compile`, or `render_string` call whose argument includes user or stored data [E2](https://bugbountylibrary.com/r/blog%3Agithub-com-sudistark-bb-writeups-blob-main-2023-cve-2023-33733-rce-via-htmli-in-reportlab-md.md)[E3](https://bugbountylibrary.com/r/ghsa%3AGHSA-hrwp-4hh9-c8r8.md).

## How to review
Find every place a value reaches a parser/compiler/evaluator. The invariant: **user and stored values must be passed as bound data or escaped literals, never concatenated into template or code source.** For each sink, ask: does this path call the engine's expression/escape emitter, or does it splice raw bytes? Check that string literals are quoted/escaped before code generation [E3](https://bugbountylibrary.com/r/ghsa%3AGHSA-hrwp-4hh9-c8r8.md), that attribute values are validated against a whitelist rather than evaluated [E2](https://bugbountylibrary.com/r/blog%3Agithub-com-sudistark-bb-writeups-blob-main-2023-cve-2023-33733-rce-via-htmli-in-reportlab-md.md), and that path/config inputs are not sourced from request-controlled globals without a SAPI or origin check [E1](https://bugbountylibrary.com/r/blog%3Aassetnote-io-resources-research-how-an-obscure-php-footgun-led-to-rce-in-craft-cms.md).

## How finders spotted it
- Read `bootstrap.php`/`App::cliOption`, saw it only checks `empty($_SERVER['argv'])` with no `PHP_SAPI` check; recalled `register_argc_argv` fills argv from the query string, then enumerated stream wrappers passing `stat()`/`file_exists` to find an includable one, after `http://` and `php://filter` failed that check [E1](https://bugbountylibrary.com/r/blog%3Aassetnote-io-resources-research-how-an-obscure-php-footgun-led-to-rce-in-craft-cms.md).
- Injected HTML into a comment field and read verbose parser errors (`invalid attribute name ... attrMap=[...]`) to fingerprint the library, matched the error to ReportLab source, then tested the known CVE [E2](https://bugbountylibrary.com/r/blog%3Agithub-com-sudistark-bb-writeups-blob-main-2023-cve-2023-33733-rce-via-htmli-in-reportlab-md.md).
- Code review of the compiler's `join` case: noticed separator and array tokens used as raw `expr.value` bytes rather than through `expression()`, confirmed against generated PHP [E3](https://bugbountylibrary.com/r/ghsa%3AGHSA-hrwp-4hh9-c8r8.md).

## Variants seen
- Request globals promoted to CLI flags, steering template path to a remote wrapper [E1](https://bugbountylibrary.com/r/blog%3Aassetnote-io-resources-research-how-an-obscure-php-footgun-led-to-rce-in-craft-cms.md).
- Stored field interpolated into a markup template whose attribute is `eval`'d [E2](https://bugbountylibrary.com/r/blog%3Agithub-com-sudistark-bb-writeups-blob-main-2023-cve-2023-33733-rce-via-htmli-in-reportlab-md.md).
- Compiler filter splicing raw token bytes into generated PHP [E3](https://bugbountylibrary.com/r/ghsa%3AGHSA-hrwp-4hh9-c8r8.md).

## Impact and severity
Unauthenticated RCE in Craft CMS [E1](https://bugbountylibrary.com/r/blog%3Aassetnote-io-resources-research-how-an-obscure-php-footgun-led-to-rce-in-craft-cms.md); RCE chained to cloud metadata and service-account token theft [E2](https://bugbountylibrary.com/r/blog%3Agithub-com-sudistark-bb-writeups-blob-main-2023-cve-2023-33733-rce-via-htmli-in-reportlab-md.md); code execution on template render [E3](https://bugbountylibrary.com/r/ghsa%3AGHSA-hrwp-4hh9-c8r8.md). Severity rises when the sink is reachable pre-auth [E1](https://bugbountylibrary.com/r/blog%3Aassetnote-io-resources-research-how-an-obscure-php-footgun-led-to-rce-in-craft-cms.md) and when RCE chains to cloud credentials [E2](https://bugbountylibrary.com/r/blog%3Agithub-com-sudistark-bb-writeups-blob-main-2023-cve-2023-33733-rce-via-htmli-in-reportlab-md.md).

## Seen in real software
Open-source packages and projects, and products, where this pattern was found. If the target runs one, compare the version it runs with the fix.
- **phalcon/cphalcon (composer)** <= 5.15.0, fixed in 5.16.0: Phalcon Volt compiler `join` filter compile-time PHP code injection (SSTI leads to RCE) (CVE-2026-59989). Report: https://bugbountylibrary.com/r/ghsa%3AGHSA-hrwp-4hh9-c8r8.md. Fix: https://github.com/phalcon/cphalcon/commit/e434061be3b7161930476c1368c868badc71e1bd
- **ReportLab** (paraparser.py color attribute evaluator) v3.6.12: CVE-2023-33733 RCE via HTMLi in reportlab (CVE-2023-33733). Report: https://bugbountylibrary.com/r/blog%3Agithub-com-sudistark-bb-writeups-blob-main-2023-cve-2023-33733-rce-via-htmli-in-reportlab-md.md

## Evidence
- E1: https://bugbountylibrary.com/r/blog%3Aassetnote-io-resources-research-how-an-obscure-php-footgun-led-to-rce-in-craft-cms.md
- E2: https://bugbountylibrary.com/r/blog%3Agithub-com-sudistark-bb-writeups-blob-main-2023-cve-2023-33733-rce-via-htmli-in-reportlab-md.md
- E3: https://bugbountylibrary.com/r/ghsa%3AGHSA-hrwp-4hh9-c8r8.md
