diff --git a/crates/ruff_linter/resources/test/fixtures/flake8_bandit/S506.py b/crates/ruff_linter/resources/test/fixtures/flake8_bandit/S506.py index b332cbe143..9fd87de3e3 100644 --- a/crates/ruff_linter/resources/test/fixtures/flake8_bandit/S506.py +++ b/crates/ruff_linter/resources/test/fixtures/flake8_bandit/S506.py @@ -2,7 +2,7 @@ import json import yaml from yaml import CSafeLoader from yaml import SafeLoader -from yaml import SafeLoader as NewSafeLoader +from yaml.loader import SafeLoader as NewSafeLoader def test_yaml_load(): @@ -29,3 +29,8 @@ yaml.load("{}", yaml.SafeLoader) yaml.load("{}", CSafeLoader) yaml.load("{}", yaml.CSafeLoader) yaml.load("{}", NewSafeLoader) +yaml.load("{}", Loader=SafeLoader) +yaml.load("{}", Loader=yaml.SafeLoader) +yaml.load("{}", Loader=CSafeLoader) +yaml.load("{}", Loader=yaml.CSafeLoader) +yaml.load("{}", Loader=NewSafeLoader) diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/unsafe_yaml_load.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/unsafe_yaml_load.rs index 68b8f59647..22b100c1d8 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/unsafe_yaml_load.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/unsafe_yaml_load.rs @@ -70,7 +70,11 @@ pub(crate) fn unsafe_yaml_load(checker: &mut Checker, call: &ast::ExprCall) { .semantic() .resolve_call_path(loader_arg) .is_some_and(|call_path| { - matches!(call_path.as_slice(), ["yaml", "SafeLoader" | "CSafeLoader"]) + matches!( + call_path.as_slice(), + ["yaml", "SafeLoader" | "CSafeLoader"] + | ["yaml", "loader", "SafeLoader" | "CSafeLoader"] + ) }) { let loader = match loader_arg {