Skip to content

fix: sandbox Jinja2 rendering in standard template create path - #472

Open
mufaddal-rohawala wants to merge 1 commit into
aws:mainfrom
mufaddal-rohawala:fix/ssti-sandboxed-jinja2-standard-templates
Open

mufaddal-rohawala wants to merge 1 commit into
aws:mainfrom
mufaddal-rohawala:fix/ssti-sandboxed-jinja2-standard-templates

Conversation

@mufaddal-rohawala

@mufaddal-rohawala mufaddal-rohawala commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

What

hyp create renders standard project template manifests (k8s.jinja / cfn_params.jinja) using a plain jinja2.Template. This change renders them inside a sandboxed Jinja2 environment instead, so template expressions cannot access unsafe Python attributes or callables.

The recipe rendering path (recipe_utils._render_k8s_template) already uses a sandboxed environment. This PR brings the standard-template path in _create_standard_template in line with it.

Change

  • src/sagemaker/hyperpod/cli/commands/init.py: render with jinja2.sandbox.ImmutableSandboxedEnvironment instead of jinja2.Template.
  • test/unit_tests/cli/test_init.py: tests asserting that a disallowed template expression is blocked and that benign templates still render.

Testing

python -m pytest test/unit_tests/cli/test_init.py
# 49 passed

@mufaddal-rohawala
mufaddal-rohawala requested a review from a team as a code owner October 21, 2026 19:15
`hyp create` rendered standard project template manifests (k8s.jinja /
cfn_params.jinja) with a plain `jinja2.Template`. Rendering now uses
`jinja2.sandbox.ImmutableSandboxedEnvironment` so template expressions
cannot access unsafe Python attributes or callables.

The recipe rendering path (recipe_utils._render_k8s_template) already used
a sandboxed environment; this aligns the standard-template path in
_create_standard_template with it.

Adds tests asserting that a disallowed template expression is blocked and
that benign templates still render.
@mufaddal-rohawala
mufaddal-rohawala force-pushed the fix/ssti-sandboxed-jinja2-standard-templates branch from 68b0786 to 88ef335 Compare October 22, 2026 18:28

This branch is waiting to be deployed

1 waiting deployment
manual-approval — 88ef3352 Waiting Oct 22, 2026 by mufaddal-rohawala via wait-for-approval #825
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.

2 participants