Replace unsafe pyyaml
loader with SafeLoader
#8
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.
The default loaders in PyYAML are not safe to use with untrusted data. They potentially make your application vulnerable to arbitrary code execution attacks. If you open a YAML file from an untrusted source, and the file is loaded with the default loader, an attacker could execute arbitrary code on your machine.
This codemod hardens all
yaml.load()
calls against such attacks by replacing the default loader withyaml.SafeLoader
. This is the recommended loader for loading untrusted data. For most use cases it functions as a drop-in replacement for the default loader.Calling
yaml.load()
without an explicit loader argument is equivalent to calling it withLoader=yaml.Loader
, which is unsafe. This usage [has been deprecated](https://github.com/yaml/pyyaml/wiki/PyYAML-yaml.load(input\)-Deprecation) since PyYAML 5.1. This codemod will add an explicitSafeLoader
argument to allyaml.load()
calls that don't use an explicit loader.The changes from this codemod look like the following:
More reading
I have additional improvements ready for this repo! If you want to see them, leave the comment:
... and I will open a new PR right away!
🧚🤖 Powered by Pixeebot
💬Feedback | 👥Community | 📚Docs | Codemod ID: pixee:python/harden-pyyaml