Skip to content

Commit

Permalink
Add another bad example of yaml load (#905)
Browse files Browse the repository at this point in the history
The yaml module supports passing the Loader of choice.
Passing yaml.Loader is considered unsafe. This commit
adds that example and ensures Bandit detects it.

Signed-off-by: Eric Brown <eric_wade_brown@yahoo.com>
  • Loading branch information
ericwb committed May 24, 2022
1 parent 9705a71 commit 232d52d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions examples/yaml_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ def test_yaml_load():
def test_json_load():
# no issue should be found
j = json.load("{}")

yaml.load("{}", Loader=yaml.Loader)
4 changes: 2 additions & 2 deletions tests/functional/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,8 @@ def test_django_sql_injection_raw(self):
def test_yaml(self):
"""Test for `yaml.load`."""
expect = {
"SEVERITY": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 1, "HIGH": 0},
"CONFIDENCE": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 0, "HIGH": 1},
"SEVERITY": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 2, "HIGH": 0},
"CONFIDENCE": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 0, "HIGH": 2},
}
self.check_example("yaml_load.py", expect)

Expand Down

0 comments on commit 232d52d

Please sign in to comment.