Skip to content

Commit d203843

Browse files
committed
fix(security): enable Jinja2 autoescape to prevent XSS in gepa sample
CWE-79 (Cross-Site Scripting) The gepa rater_lib.py instantiated jinja2.Environment() without autoescape=True, allowing user_input and model_response to be rendered as raw HTML. This fix: - Enable autoescape=True in jinja2.Environment() - Add explicit |e filters to {{user_input}} and {{model_response}} as defense-in-depth
1 parent 3e282d2 commit d203843

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

contributing/samples/gepa/rater_lib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def __call__(self, messages: list[dict[str, Any]]) -> dict[str, Any]:
167167
Returns:
168168
A dictionary containing rating information including score.
169169
"""
170-
env = jinja2.Environment()
170+
env = jinja2.Environment(autoescape=True)
171171
env.globals['user_input'] = (
172172
messages[0].get('parts', [{}])[0].get('text', '') if messages else ''
173173
)

contributing/samples/gepa/rubric_validation_template.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,12 @@ Verdict: no
155155
</available_tools>
156156

157157
<main_prompt>
158-
{{user_input}}
158+
{{user_input|e}}
159159
</main_prompt>
160160
</user_prompt>
161161

162162
<responses>
163-
{{model_response}}
163+
{{model_response|e}}
164164
</responses>
165165

166166
<properties>

0 commit comments

Comments
 (0)