-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jinja autoescape #50
Jinja autoescape #50
Conversation
a5b398b
to
9c717d7
Compare
b85c36f
to
f909c5a
Compare
f909c5a
to
63e6a63
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall. The main substantive comment is about the semgrep pattern, plus a few minor comments on the docs.
from jinja2 import Environment | ||
|
||
- env = Environment() | ||
- env = Environment(autoescape=False, loader=some-loader) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor thing but the -
here and below is not valid Python syntax.
jinja2.Environment(...) | ||
- pattern: | | ||
jinja2.Environment(..., autoescape=False, ...) | ||
- pattern-not: | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this pattern-not
by itself be sufficient instead of enumerating the other cases above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh hmm good point let me check if tests pass with that
else: | ||
new = arg | ||
new_args.append(new) | ||
|
||
if add_if_missing and not arg_added: | ||
new = cst.Arg( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a small thing but it seems like this Arg
creation could be factored out into another method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yes, thought about that and forgot, will do!
return """ | ||
rules: | ||
- patterns: | ||
- pattern-either: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment below but I think this might be redundant with the pattern-not
.
src/core_codemods/docs/pixee_python_enable-jinja2-autoescape.md
Outdated
Show resolved
Hide resolved
src/core_codemods/docs/pixee_python_enable-jinja2-autoescape.md
Outdated
Show resolved
Hide resolved
src/core_codemods/docs/pixee_python_enable-jinja2-autoescape.md
Outdated
Show resolved
Hide resolved
Co-authored-by: Dan D'Avella <[email protected]>
55d183e
to
24a768a
Compare
Overview
Add a codemod that checks if jinja2.Environment enables autoescape
Description
autoescape
, a jinja2 setting to guard against XSS attacks, is disabled by default (and can explicitly be disabled)select_autoescape
function (see bug report here), this codemod does not detect if autoescape is assigned to a callable, such asEnvironment(autoescape=select_autoescape())
. this is the recommended way in the docs. We will cover that later.