-
-
Notifications
You must be signed in to change notification settings - Fork 415
feat: remediation for Python SSTI #4145
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
Conversation
This commit include the following: - Add new rule to the generic attack category to block the Python SSTI payloads - Add Some test cases to check if the rule works fine or not
📊 Quantitative test results for language: |
Although the quantitative testing in CI didn't find any problems, I suspect that regexp is too loose, and may cause false positives in the real world. A bit of searching found this post:
which would trigger a false positive. There are surely other examples. See for example commit 2ac26cc You want tests for actual harmful requests, too, not just probes like {{ 7 * 7 }}. Note also that when one adds a regexp, one is expected to provide regex assembly source; the commit I linked to does this in file util/regexp-assemble/data/934100.data etc. |
#3780 is about bash; this is about SSTI. They may look similar because of the braces, but they're very different. |
Thank you for providing this PR and also the associated issue. The PR already looks great, and there's even a test file. |
It seems {{ }} is used by a large number of template languages, e.g.:
so you might want to either change the name of the rule to "Generic SSTI", or add keywords to make it specific to Flask and call it "Flask SSTI" (following the example set by a different SSTI rule in #2578 ). Also, it's used in non-template language:
thus crs standard advice "disable any rule that causes false positives for your users" will apply to this rule. |
@franbuehler |
@dkegel-fastly But regarding your claim that the double parentheses is used in a lot of things, what is the point that some users may pass such expression in a query parameter for example or for a cookie?? Even if there is a case and it is very rare, I think they can be bypassed by the folks whoever will face any issue for this rule, what do you think? |
I'm more worried about it happening in the body; that's where long user input goes. |
This is already covered by rule 941380:
|
We need to update our documentation so that users stop reporting bypasses at PL1, when they're covered at higher PLs. Closing. |
That's true. I didn't test for it.
However, case 2 is not covered yet:
Do we want to extend the existing rule 941380 so that this case is covered as well? |
Yes, that'd make sense. Also, we need to update the comments to mention that the payload covers other template/non-template languages as mentioned by @dkegel-fastly. UPDATE: I just tested with spaces, and the code is unable to evaluate due to incorrect syntax. The curly braces need to be close, atleast for Python, which I've tested. |
I just checked, and we need to cover the the https://jinja.palletsprojects.com/en/stable/templates/#list-of-control-structures
|
We could cover this with: So this would be enough when the curly braces need to be close. |
Not sure how to implement this, rule 941380 is XSS related, although still a template injection vuln. What do you suggest, remove that rule, maintain this PR. and change the title to Template Injection, to make it generic. |
@Xhoenix Are you sure that the rule: |
@franbuehler I see that this rule:
|
@Xhoenix I'm not entirely sure, but I think we should move the rule to the right place. The downside is that some users may have written tuning rules to this rule 941180. Now the rule will be moved to a different ID, and the tuning rule will no longer apply. Maybe other opinions?
@TheRubick Yes, the regex of rule 941380 is almost the same:
@TheRubick Yes, this would also be the solution to match the second test case: |
@franbuehler all options are available on the table :) |
- Add the {%%} and <%%> regex to the rule 934180 - Add more regression tests - Removed some unnecessary comments
@franbuehler @Xhoenix
Also, can we be confirmed from removing the old rule from the XSS?? I have added the angle brackets plus percentage sign test case and regex as well as I have found this statement in the Jinja2 template official documents: As well as I have found some SSTI payload can be exploited using this type of regex e.g. |
In my humble opinion, this fact should be concerned in every open source project :) I mean this may happen to someone who is using an open source library but didn't check the release notes. Does that make sense?? I see that we can remove the old rule and broadcast that we have changed to something else, folks/users should be synced to the latest change. |
tests/regression/tests/REQUEST-934-APPLICATION-ATTACK-GENERIC/934180.yaml
Outdated
Show resolved
Hide resolved
@franbuehler I have added all the changes that we have agreed upon from the monthly meeting :) |
I will add a comment to the existing rule 941380 once this PR is ready. |
I have added a comment already, did you check it? |
Linting fails because of trailing spaces in tests/regression/tests/REQUEST-934-APPLICATION-ATTACK-GENERIC/934180.yaml. |
@TheRubick Can you fix the test's yaml? |
@franbuehler @fzipi Done, waiting for your sweet lgtm :) |
Linting is still complaining about a trailing space. |
@franbuehler done |
Co-authored-by: Xhoenix <86168235+Xhoenix@users.noreply.github.com>
Updated the action version, done :) |
Co-authored-by: Felipe Zipitría <3012076+fzipi@users.noreply.github.com>
Co-authored-by: Felipe Zipitría <3012076+fzipi@users.noreply.github.com>
@fzipi I have added the new tag, hopefully so I have adjusted it appropriately :) |
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.
LGTM
This commit include the following: