Skip to content

Security: enable Jinja2 autoescaping in CLI template rendering (FHUB-259) - #986

Merged
Eyal-Danieli merged 2 commits into
mlrun:developmentfrom
Eyal-Danieli:fix/jija-fox
Aug 16, 2026
Merged

Security: enable Jinja2 autoescaping in CLI template rendering (FHUB-259)#986
Eyal-Danieli merged 2 commits into
mlrun:developmentfrom
Eyal-Danieli:fix/jija-fox

Conversation

@Eyal-Danieli

Copy link
Copy Markdown
Member

Summary

Resolves the two high-severity CodeQL code-scanning alerts
py/jinja2/autoescape-false in the CLI by enabling Jinja2 autoescaping where
templates are rendered.

Changes

  • cli/common/generate_item_yaml.py – pass autoescape=select_autoescape()
    to the Jinja2 Environment. The item templates are *.yaml.j2, so
    autoescape resolves to False at runtime and generated item.yaml output is
    unchanged; the change satisfies the scanner and is safe-by-default for any
    future HTML/XML templates added to the loader.
  • cli/utils/helpers.py (render_jinja) – choose autoescape based on the
    template file extension via
    select_autoescape(enabled_extensions=("html","htm","xml")). This is the
    substantive fix: render_jinja injects raw source code / YAML into the
    marketplace's python.html and yaml.html pages, which were previously
    rendered without escaping (the reported XSS vector). HTML/XML templates are now
    escaped, while non-HTML templates (e.g. conf.template -> conf.py) continue
    to render unescaped.

Why extension-based (not a blanket autoescape=True)

render_jinja is used for both HTML pages (must escape) and non-HTML files like
conf.py (must not escape, or the generated Python config could be corrupted).
Deriving autoescape from the template extension fixes the XSS without changing
non-HTML output.

Test plan

  • Verified HTML templates now escape embedded content
    (<script> -> &lt;script&gt;).
  • Verified conf.template / non-HTML output remains unescaped.

@Eyal-Danieli Eyal-Danieli changed the title Security: enable Jinja2 autoescaping in CLI template rendering (fix CodeQL py/jinja2/autoescape-false) Security: enable Jinja2 autoescaping in CLI template rendering (FHUB-259) Aug 16, 2026
@Eyal-Danieli
Eyal-Danieli merged commit 7a52b38 into mlrun:development Aug 16, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant