fix: sandbox ImageRAGPrompt template rendering (SSTI, sibling of CVE-2026-2969) - #144
Open
joysinleung wants to merge 1 commit into
Open
Conversation
ImageRAGPrompt compiled user-supplied template strings with a bare, unsandboxed jinja2.Template, which allows server-side template injection (CWE-1336) — the exact sibling pattern of CVE-2026-2969 / GHSA-q5xx-fxv3-xxqf, which was fixed in prompt.py by switching to SandboxedEnvironment but was never applied to image_rag.py. Align with the existing fix: use jinja2.sandbox.SandboxedEnvironment + env.from_string() for both template sinks (L27 user_prompt_template, L29 each_image_template). Verified defensively: expression evaluation still works for legitimate templates, while attribute-traversal gadgets (().__class__.__mro__[1].__subclasses__()) raise SecurityError. Related: datapizza-labs#143
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ImageRAGPromptindatapizza/modules/prompt/image_rag.pycompiles user-suppliedtemplate strings with a bare, unsandboxed
jinja2.Templateand renders them later.This is the exact sibling pattern of
ChatPromptTemplate(CVE-2026-2969 /GHSA-q5xx-fxv3-xxqf), which was fixed by switching to
jinja2.sandbox.SandboxedEnvironment— but the fix was never applied to
image_rag.py.Change
Mirror the existing
prompt.pyfix (the CVE-2026-2969 remediation):Why it's safe
{{ var }}) still works —SandboxedEnvironmentevaluates ordinary expressions.
''.__class__.__mro__[1].__subclasses__()) is blocked withSecurityError, neutralizing the SSTI → RCE path.prompt.py.Impact
CWE-1336 Server-Side Template Injection. Attacker-influenced template strings (prompt builder,
config/API field, multi-tenant template store) → arbitrary Python code execution in the host
process. Proposed CVSS 3.1:
AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H= 7.2 High.Testing
Defensive verification (no weaponized payload):
Full disclosure in #143.