-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detect
mark_safe
usages in decorators (#9887)
## Summary Django's `mark_safe` can also be used as a decorator, so we should detect usages of `@mark_safe` for the purpose of the relevant Bandit rule. Closes #9780.
- Loading branch information
1 parent
ed07fa0
commit f76a3e8
Showing
5 changed files
with
88 additions
and
2 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
crates/ruff_linter/resources/test/fixtures/flake8_bandit/S308.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from django.utils.safestring import mark_safe | ||
|
||
|
||
def some_func(): | ||
return mark_safe('<script>alert("evil!")</script>') | ||
|
||
|
||
@mark_safe | ||
def some_func(): | ||
return '<script>alert("evil!")</script>' | ||
|
||
|
||
from django.utils.html import mark_safe | ||
|
||
|
||
def some_func(): | ||
return mark_safe('<script>alert("evil!")</script>') | ||
|
||
|
||
@mark_safe | ||
def some_func(): | ||
return '<script>alert("evil!")</script>' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...rules/flake8_bandit/snapshots/ruff_linter__rules__flake8_bandit__tests__S308_S308.py.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/flake8_bandit/mod.rs | ||
--- | ||
S308.py:5:12: S308 Use of `mark_safe` may expose cross-site scripting vulnerabilities | ||
| | ||
4 | def some_func(): | ||
5 | return mark_safe('<script>alert("evil!")</script>') | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S308 | ||
| | ||
|
||
S308.py:8:1: S308 Use of `mark_safe` may expose cross-site scripting vulnerabilities | ||
| | ||
8 | @mark_safe | ||
| ^^^^^^^^^^ S308 | ||
9 | def some_func(): | ||
10 | return '<script>alert("evil!")</script>' | ||
| | ||
|
||
S308.py:17:12: S308 Use of `mark_safe` may expose cross-site scripting vulnerabilities | ||
| | ||
16 | def some_func(): | ||
17 | return mark_safe('<script>alert("evil!")</script>') | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S308 | ||
| | ||
|
||
S308.py:20:1: S308 Use of `mark_safe` may expose cross-site scripting vulnerabilities | ||
| | ||
20 | @mark_safe | ||
| ^^^^^^^^^^ S308 | ||
21 | def some_func(): | ||
22 | return '<script>alert("evil!")</script>' | ||
| | ||
|
||
|