← Lab /AI/ML

Handlebars escaping blocks only angle-bracket role delimiters, leaving others fully exploitable

Handlebars double-brace HTML escaping fails to prevent structural role injection for several common delimiter schemes.

AI/ML arXiv 16 Jun 2026 Measurement Real-world evidence Threat model

Published as “Structural Role Injection in Handlebars-Templated LLM Prompts: Triple-Brace Interpolation, Delimiter Family, and the Limits of HTML Auto-Escaping”

Why it matters

Developers should not rely on Handlebars' default HTML escaping as a prompt-injection defence; they must pair it with a true structural separation of instruction and data.

Summary

The escaped Handlebars double-brace interpolation only blocks structural role injection for delimiter families that use angle brackets, leaving three of seven common families fully exposed. In a 5760-trial evaluation, GPT-3.5 Turbo’s hijack success fell from 97% to 91% with escaping (6% gap, p=0.003), while markdown and colon-based families saw no change. The protection is conditional on both the delimiter scheme and the model’s baseline susceptibility, so escaping alone is not a reliable defence.

What they found 1

  1. Angle-bracket delimiter families have a survival rate of 0.00 under Handlebars escaping.

    “chatml 0 0.00”

Caveats 7

  • Escaping provides no protection for markdown and colon-based families, which retain 100% attack success.
  • Models that are already saturated (e.g., GPT-3.5 Turbo on hijack) show little or no reduction in ASR despite escaping.
  • Overall raw-vs-escaped gaps are modest because many families are unaffected and some models are highly vulnerable regardless of escaping.
  • The suite has 16 scenarios, so a per-family cell holds 16 scenarios per escaping mode per run (3 runs pooled), and individual family gaps still have wide intervals; we report the direction of the per-family effect and the pooled test rather than claiming per-family significance.
  • We evaluate at temperature 0, which reduces but does not eliminate run-to-run variation; the largest per-run ASR spread is 6%.
  • The hijack success criterion is a marker-emission proxy for instruction following, and the exfiltration criterion is a verbatim canary match; both can miss partial compliance that neither emits the token nor refuses.
  • We send the flattened template as a single user message to chat-completion APIs, so the structural delimiters reach the model as ordinary text rather than as parsed control tokens; a local-model stack that tokenises delimiters as special tokens could amplify the raw-vs-escaped gap.

What’s new here 4

  • Isolates Handlebars escaping (escaped vs raw) as the independent variable in prompt-injection experiments.
  • Provides a model-free static analysis of which role-delimiter tokens survive HTML escaping.
  • Measures the interaction between escaping and seven delimiter families across four LLMs and two attack objectives.
  • Releases the full benchmark suite and analysis scripts for reproducibility.

Threat model stated by the source

Adversaryattacker who controls the untrusted field inserted into a Handlebars template
Capabilitycan supply arbitrary text into the templated slot
Assumesdeveloper uses Handlebars with either escaped {{}} or raw {{{}}} interpolation; the model receives the rendered prompt as a single flattened user message