[flake8-bandit] Don't flag BaseLoader/CBaseLoader as unsafe in preview (S506)#23510
Merged
ntBre merged 2 commits intoastral-sh:mainfrom Feb 23, 2026
Merged
[flake8-bandit] Don't flag BaseLoader/CBaseLoader as unsafe in preview (S506)#23510ntBre merged 2 commits intoastral-sh:mainfrom
[flake8-bandit] Don't flag BaseLoader/CBaseLoader as unsafe in preview (S506)#23510ntBre merged 2 commits intoastral-sh:mainfrom
Conversation
…preview (`S506`) `yaml.BaseLoader` and `yaml.CBaseLoader` use `BaseConstructor` + `BaseResolver`, which do not resolve tags or construct arbitrary Python objects. They are strictly less capable than `SafeLoader`, not less safe. Gate the change behind preview mode to avoid breaking existing `noqa` comments. Closes astral-sh#13604
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
yaml.BaseLoaderandyaml.CBaseLoaderuseBaseConstructor+BaseResolver, which do not resolve tags or construct arbitrary Python objects — they only produce basic types (lists, dicts, strings). They are strictly less capable thanSafeLoader, not less safe.Currently, S506 flags
yaml.load(..., Loader=yaml.BaseLoader)as unsafe. This is a false positive.This PR adds
BaseLoaderandCBaseLoader(the C-accelerated variant fromyaml.cyaml) to the list of recognized safe loaders, gated behind preview mode per maintainer guidance.Closes #13604
Test Plan
BaseLoader/CBaseLoadervia all import paths (yaml.*,yaml.loader.*,yaml.cyaml.*, aliased imports)assert_diagnostics_diff!to verify BaseLoader diagnostics are suppressed only in preview modecargo test -p ruff_linter,cargo clippy, anduvx prek run -a