astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
33.14k stars 1.11k forks source link

[flake8-bandit/S506] Dont report violation when using BaseLoader #13604

Open mcmitch opened 1 month ago

mcmitch commented 1 month ago

From https://pyyaml.org/wiki/PyYAMLDocumentation

For our project we are using the Baseloader, and do not want to use safeLoader, as this would not leave integer values as strings. The baseloader is not the unsafe FullLoader, and should not be flagged as an exception to S506.

Code to reproduce:

with open('testfile.yaml') as fhandle:
  loader_yaml = yaml.load(fhandle, Loader=yaml.Baseloader)

Ruff setting: [select = "S506"] Ruff version: 0.6.8

AlexWaygood commented 1 month ago

From my reading of the pyyaml docs, your rationale makes sense to me. I'm not a security expert, however, and it looks like we match bandit's original behaviour here (and it looks like they've had this behaviour for a long time).

Digging into the source code for pyyaml a bit:

@ericwb, sorry for the ping -- I don't suppose you'd be able to shed light on this behaviour from bandit, would you? Is there a reason why SafeLoader would be safer than BaseLoader?

asears commented 3 weeks ago

There's a SO post here with some useful info, though not much clarity in Bandit repo issues on the topic.

https://stackoverflow.com/questions/73958193/are-there-any-cases-to-use-pyyaml-fullloader-or-baseloader-instead-of-safeloader