Deprecate yaml.load and add FullLoader and UnsafeLoader classes#257
Closed
ingydotnet wants to merge 2 commits intomasterfrom
Closed
Deprecate yaml.load and add FullLoader and UnsafeLoader classes#257ingydotnet wants to merge 2 commits intomasterfrom
ingydotnet wants to merge 2 commits intomasterfrom
Conversation
b48390a to
3cca84b
Compare
Member
Author
|
The warning issued by |
This was referenced Feb 28, 2019
Closed
Closed
3cca84b to
8de78b6
Compare
The `load` and `load_all` methods will issue a warning when they are
called without the 'Loader=' parameter. The warning will point to a URL
that is always up to date with the latest information on the usage of
`load`.
There are several ways to stop the warning:
* Use `full_load(input)` - sugar for `yaml.load(input, FullLoader)`
* FullLoader is the new safe but complete loader class
* Use `safe_load(input)` - sugar for `yaml.load(input, SafeLoader)`
* Make sure your input YAML consists of the 'safe' subset
* Use `unsafe_load(input)` - sugar for `yaml.load(input, UnsafeLoader)`
* Make sure your input YAML consists of the 'safe' subset
* Use `yaml.load(input, Loader=yaml.<loader>)`
* Or shorter `yaml.load(input, yaml.<loader>)`
* Where '<loader>' can be:
* FullLoader - safe, complete Python YAML loading
* SafeLoader - safe, partial Python YAML loading
* UnsafeLoader - more explicit name for the old, unsafe 'Loader' class
* yaml.warnings({'YAMLLoadWarning': False})
* Use this when you use third party modules that use `yaml.load(input)`
* Only do this if input is trusted
The above `load()` expressions all have `load_all()` counterparts.
You can get the original unsafe behavior with:
* `yaml.unsafe_load(input)`
* `yaml.load(input, Loader=yaml.UnsafeLoader)`
In a future release, `yaml.load(input)` will raise an exception.
The new loader called FullLoader is almost entirely complete as
Loader/UnsafeLoader but it does it avoids all known code execution
paths. It is the preferred YAML loader, and the current default for
`yaml.load(input)` when you get the warning.
Here are some of the exploits that can be triggered with UnsafeLoader
but not with FullLoader:
```
python -c 'import os, yaml; yaml.full_load("!!python/object/new:os.system [echo EXPLOIT!]")'`
python -c 'import yaml; print yaml.full_load("!!python/object/new:abs [-5]")'
python -c 'import yaml; yaml.full_load("!!python/object/new:eval [exit(5)]")' ; echo $?
python -c 'import yaml; yaml.full_load("!!python/object/new:exit [5]")' ; echo $?
8de78b6 to
2869cea
Compare
Member
This was referenced Mar 14, 2019
fblackburn1
added a commit
to wazo-platform/wazo-auth
that referenced
this pull request
Apr 16, 2019
reason: with pyyaml >= 5, the load function without Loader is deprecated. Even if we do not use version 5 for now, we should use good practices. https://pyyaml.org/wiki/PyYAMLDocumentation#loading-yaml yaml/pyyaml#257
fblackburn1
added a commit
to wazo-platform/wazo-auth-keys
that referenced
this pull request
Apr 16, 2019
reason: with pyyaml >= 5, the load function without Loader is deprecated. Even if we do not use version 5 for now, we should use good practices. https://pyyaml.org/wiki/PyYAMLDocumentation#loading-yaml yaml/pyyaml#257
fblackburn1
added a commit
to wazo-platform/wazo-confd
that referenced
this pull request
Apr 16, 2019
reason: with pyyaml >= 5, the load function without Loader is deprecated. Even if we do not use version 5 for now, we should use good practices. https://pyyaml.org/wiki/PyYAMLDocumentation#loading-yaml yaml/pyyaml#257
fblackburn1
added a commit
to wazo-platform/wazo-confgend
that referenced
this pull request
Apr 16, 2019
reason: with pyyaml >= 5, the load function without Loader is deprecated. Even if we do not use version 5 for now, we should use good practices. https://pyyaml.org/wiki/PyYAMLDocumentation#loading-yaml yaml/pyyaml#257
fblackburn1
added a commit
to wazo-platform/wazo-dird
that referenced
this pull request
Apr 16, 2019
reason: with pyyaml >= 5, the load function without Loader is deprecated. Even if we do not use version 5 for now, we should use good practices. https://pyyaml.org/wiki/PyYAMLDocumentation#loading-yaml yaml/pyyaml#257
fblackburn1
added a commit
to wazo-platform/wazo-plugind
that referenced
this pull request
Apr 16, 2019
reason: with pyyaml >= 5, the load function without Loader is deprecated. Even if we do not use version 5 for now, we should use good practices. https://pyyaml.org/wiki/PyYAMLDocumentation#loading-yaml yaml/pyyaml#257
This was referenced Mar 9, 2021
This was referenced Mar 17, 2021
Max0709202
pushed a commit
to Max0709202/py-automl
that referenced
this pull request
Dec 18, 2025
yaml.load() [was](yaml/pyyaml#257) [deemed](https://github.com/yaml/pyyaml/wiki/PyYAML-yaml.load(input)-Deprecation) [unsafe](https://nvd.nist.gov/vuln/detail/CVE-2017-18342). This fixes that issue.
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.
This addresses CVE-2017-18342
YAML is cross-programming language serialization language. YAML happens to be
used quite often as a configuration format. PyYAML is an implementation of YAML
that provides human friendly (plain text) data serialization for Python.
The CVE asserts that
yaml.load()can execute arbitrary code. This is true.Here are some trivial examples:
This PR prevents arbitrary code execution for
yaml_load().YAML has always had a
safe_loadmethod that can load a subset of YAMLwithout the risk of code execution. CVE-2017-18342 seems to suggest that
loadshould call
safe_loadby default. This is not feasible, because it will breakcode that is using PyYAML as a full serialization language, not just for simple
config.
Since PyYAML was created as serialization module for Python, it was heavily
influenced by Python's primary (but not human readable) serialization
format/module, Pickle. Pickle has the same problems of code execution on
untrusted data, yet there isn't a similar CVE for Pickle.
The PyYAML maintainers have decided that the plain usage of
yaml.load()hasto be deprecated. We can't make it call
safe_loadand it is unsafe bydefault. Even though it has been loudly documented as being unsafe from the
very beginning (just like Pickle), the Python community is raising red flags.
Here is how things will work in 5.1:
yaml.load()will issue a warning unless you call it with theLoader=parameter. The available Loaders are:
You can also use the sugar methods:
There are methods to disable the warning when you use modules that use
yaml.load()that you can't change.The end result is that you need to declare which Loader you want to use.
We added a new loader class called FullLoader, and we made it the default for
load(). This class is almost as complete for serialization asUnsafeLoader/Loader, but it avoids arbitrary code execution. We don't expect it
will break any code in the wild.
We still recommend that people choose SafeLoader for untrusted data, but
aribitrary code execution will no longer be possible using
yaml.load()withthe default loader (FullLoader). FullLoader will instantiate objects of classes
that you have imported. Since object instantiation runs the class's constructor
code, that may be exploitable.
In a future release (after 5.1) yaml.load() will raise an exception if you don't
explicitly choose the Loader to use.