Repository navigation
fix(dotprompt): add per-render nonce to template markers - #640
Conversation
The role, history, section and media helpers emit in-band markers that are split back out of the rendered string, which also contains user-supplied values verbatim. An end user controlling any interpolated value could forge system/model turns, inject media parts with arbitrary URLs, move history, or inject pending section parts. Every marker now carries a random 128-bit nonce generated per render, and the parser only honors markers with that nonce, classifying pieces by position rather than prefix. Anything else that looks like a marker stays literal text.
|
/gemini review |
A user-controlled media url (or section name) containing a newline made the trusted marker fail to match, dropping the media part and leaking the raw marker, nonce included, into the text. Use the dotAll flag.
apascal07
left a comment
There was a problem hiding this comment.
packages/vscode/snippets/dotprompt.snippets.json still inserts <<<dotprompt:role:system>>> on <<<, and the vscode, monaco, codemirror, vim, emacs, jetbrains and treesitter grammars highlight un-nonced markers as live syntax. After this change those render as literal text in a user message, so the tooling teaches a form that now silently does nothing.
With no positional argument Handlebars passes the options object as the first parameter, so the helpers crashed reading options.data. Throw a clear error instead.
|
Re the editor tooling point in the review above: Agreed. The editor packages have their own release scopes, so this is in a separate PR: #648. It drops the raw-marker snippet, inserts |
What's new
<<<dotprompt:{nonce}:role:system>>>.<<<dotprompt:...>>>markers written in template source, passed in input, or returned by custom helpers are no longer interpreted. No in-repo templates rely on this.JS specifics
markers.ts; nonce stored in the Handlebars data frame afterdata.context.parse.tsisn't exported fromindex.ts).Why
The
role,history,sectionandmediahelpers emit in-band markers (<<<dotprompt:role:system>>>) into the rendered string, which is then split back into messages. The rendered string also contains user-supplied values verbatim, so any end user who controls an interpolated value can forge markers:This forges system/model turns, injects media parts with arbitrary URLs (server-side fetch / SSRF when a model plugin downloads media, e.g. Genkit's Vertex AI plugin), moves history insertion, and injects pending section parts. It works through
{{x}},{{{x}}},{{json x}},#each, and partials. Escaping input can't reliably fix it (triple-stash andSafeStringhelpers skip escaping, and markers can be assembled from adjacent values), so markers are now authenticated instead.Not in this PR
spec/conformance test for injection (follow-up after all runtimes land).{{media url=...}}against user URLs with spaces or>>>(pre-existing parsing quirk, can't forge markers).downloadRequestMediaSSRF hardening (separate repo).Sibling PRs (one per runtime, independent, no stacking): JS #640, Go #641, Python #642, Dart #643, Java #644, Rust #645.