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

Copy link
Copy Markdown
Member

What

hyp create renders standard project template manifests (k8s.jinja / cfn_params.jinja) using an unsandboxed jinja2.Template. Jinja2 expressions in those files can traverse Python internals (e.g. {{ cycler.__init__.__globals__ }}) to reach os/subprocess, which means rendering a template authored in a project scaffold can execute arbitrary code on the user's machine when they run hyp create.

The recipe rendering path (recipe_utils._render_k8s_template) is already hardened with SandboxedEnvironment, but the standard-template path in _create_standard_template was still using the unsandboxed Template. This PR brings the two paths in line.

Change

  • src/sagemaker/hyperpod/cli/commands/init.py: render with jinja2.sandbox.ImmutableSandboxedEnvironment instead of jinja2.Template, so unsafe attribute/callable access is blocked.
  • test/unit_tests/cli/test_init.py: regression tests asserting that an internals-traversing payload does not execute, that rendering it fails safely, and that benign templates still render.

Testing

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

`hyp create` rendered standard project template manifests (k8s.jinja /
cfn_params.jinja) with an unsandboxed `jinja2.Template`. Template
expressions could traverse Python internals (e.g.
`{{ cycler.__init__.__globals__ }}`) to reach os/subprocess, allowing
arbitrary code execution when a user runs `hyp create` on a malicious
project scaffold.

The recipe rendering path (recipe_utils._render_k8s_template) was already
sandboxed with SandboxedEnvironment, but the standard-template path in
_create_standard_template was still using the unsandboxed Template. This
change switches it to ImmutableSandboxedEnvironment so unsafe attribute and
callable access is blocked.

Adds regression tests that assert an SSTI payload does not execute, that
rendering such a payload fails safely, and that benign templates still
render.
@mufaddal-rohawala
mufaddal-rohawala requested a review from a team as a code owner October 21, 2026 19:15

This branch was successfully deployed

1 active deployment
manual-approval — 68b07863 Deployed Oct 21, 2026 by mufaddal-rohawala via wait-for-approval #824
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