Fix #50: Add Jinja2 security utilities for template injection prevention - #74
Open
TensorDevLJ wants to merge 5 commits into
Open
Conversation
…t-data-and-ai#22) Signed-off-by: Abhishek Kumar <abhishek68@gmail.com> Co-authored-by: Cursor <cursoragent@cursor.com>
…edhat-data-and-ai#65) Co-authored-by: Cursor <cursoragent@cursor.com>
… injection prevention Introduce reusable delimiter validation, escaping, and secure Environment creation behind ENABLE_JINJA2_SECURITY so future Jinja2 tools can handle untrusted input safely without changing current server behavior. Co-authored-by: Cursor <cursoragent@cursor.com>
Signed-off-by: Likhitha J <143345274+TensorDevLJ@users.noreply.github.com>
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
template_mcp_server.utils.jinja2_securitywith three utilities for Jinja2 SSTI defense-in-depth:escape_jinja2_delimiters()— neutralize{{,}},{%,%},{#,#}in untrusted textvalidate_user_query_for_jinja2()— reject delimiter injection withValueErrorand WARNING logget_secure_jinja2_env()— returnEnvironment(autoescape=True)when security is enabledENABLE_JINJA2_SECURITYfeature flag (default:True)docs/development.mdFixes #50
Scope note
This repository currently has no Jinja2 usage. This PR intentionally adds reusable security utilities for future tools and does not integrate them into existing code. Current server behavior is unchanged.
Security model
These utilities help prevent accidental template injection when handling untrusted input. They do not make it safe to construct Jinja2 template source from user-controlled data. Callers should validate input before rendering and avoid building templates from user input.
Test plan
autoescape=Trueenforced when security enabled (kwargs cannot override)