[flake8-bandit] Fix false positive when using non-standard CSafeLoader path (S506).#21830
Merged
MichaReiser merged 1 commit intoastral-sh:mainfrom Dec 7, 2025
Merged
Conversation
…r path (S506).
Using `CSafeLoader` from non-standard path i.e `yaml.cyaml.CSafeLoader`
resulted in false reporting of `unsafe-yaml-load`.
Example:
```py
import yaml
yaml.load("{}", Loader=yaml.cyaml.CSafeLoader)
```
resulted in:
```sh
S506 Probable use of unsafe loader `CSafeLoader` with `yaml.load`.
Allows instantiation of arbitrary objects. Consider `yaml.safe_load`.
--> /Users/foo/ruff-input/main.py:5:24
|
3 | import yaml
4 |
5 | yaml.load("{}", Loader=yaml.cyaml.CSafeLoader)
| ^^^^^^^^^^^^^^^^^^^^^^
```
The PR fixes the bug by considering `yaml.cyaml.CSafeLoader` as a
possible way to use `CSafeLoader`.
Fixes astral-sh#21673.
Signed-off-by: Prakhar Pratyush <prakhar1144@gmail.com>
d4ccbcd to
23b0512
Compare
|
dcreager
added a commit
that referenced
this pull request
Dec 7, 2025
* origin/main: [ty] Add test case for fixed panic (#21832) [ty] Avoid double-analyzing tuple in `Final` subscript (#21828) [flake8-bandit] Fix false positive when using non-standard `CSafeLoader` path (S506). (#21830) Add minimal-size build profile (#21826) [ty] Allow `tuple[Any, ...]` to assign to `tuple[int, *tuple[int, ...]]` (#21803) [ty] Support renaming import aliases (#21792) [ty] Add redeclaration LSP tests (#21812) [ty] more detailed description of "Size limit on unions of literals" in mdtest (#21804) [ty] Complete support for `ParamSpec` (#21445) [ty] Update benchmark dependencies (#21815)
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Using
CSafeLoaderfrom non-standard path i.eyaml.cyaml.CSafeLoaderresulted in false reporting ofunsafe-yaml-load.Example:
resulted in:
The PR fixes the bug by considering
yaml.cyaml.CSafeLoaderas a possible way to useCSafeLoader.Fixes #21673.
Test Plan
Added example scenarios in
crates/ruff_linter/resources/test/fixtures/flake8_bandit/S506.py.