Skip to content

Conversation

@ashb
Copy link
Member

@ashb ashb commented May 18, 2021

Templates shouldn't ever be taken from untrusted user input (and it's hard to do so without just edit the dag file, at which point you can run whatever python code you like anyway), but this is a reasonable safety measure just in case someone does something "clever".

This change does mean that templates can no longer access any attributes that start with a _, i.e. {{ obj._foo }} would now fail

The second commit in this PR changes it so that obj._foo continues to work, to reduce chance of breaking existing dags.

ashb added 2 commits May 18, 2021 09:21
Templates _shouldn't_ ever be taken from untrusted user input, but this
is a reasonable safety measure just in case someone does something
"clever".

This change does mean that templates can no longer access any attributes
that start with a `_`, i.e. `{{ obj._foo }}` would now fail
@ashb ashb requested review from kaxil and potiuk May 18, 2021 08:59
@ashb ashb requested review from XD-DENG and turbaszek as code owners May 18, 2021 08:59
)
jinja_env = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.dirname(__file__)), autoescape=True
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change was made because I was looking for all cases of jinaj2.Environment, and since 3 lines down we render fixed templates, we know it would never product a Native object, so we don't need it.

This change isn't required here, and I can split it out to a separate PR.

Copy link
Member

@potiuk potiuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@potiuk
Copy link
Member

potiuk commented May 18, 2021

No need to split.

@ashb ashb merged commit 4295845 into apache:master May 18, 2021
@ashb ashb deleted the sandbox-templates branch May 18, 2021 10:50
ashb added a commit that referenced this pull request May 18, 2021
Templates _shouldn't_ ever be taken from untrusted user input (and it's hard to
do so without just edit the dag file, at which point you can run whatever
python code you like _anyway_), but this is a reasonable safety measure just in
case someone does something "clever".

(cherry picked from commit 4295845)
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