third_party_pyyaml/lib/yaml
Riccardo Schirone 5080ba5133
Prevents arbitrary code execution during python/object/new constructor (#386)
* Prevents arbitrary code execution during python/object/new constructor

In FullLoader python/object/new constructor, implemented by
construct_python_object_apply, has support for setting the state of a
deserialized instance through the set_python_instance_state method.
After setting the state, some operations are performed on the instance
to complete its initialization, however it is possible for an attacker
to set the instance' state in such a way that arbitrary code is executed
by the FullLoader.

This patch tries to block such attacks in FullLoader by preventing
set_python_instance_state from setting arbitrary properties. It
implements a blacklist that includes `extend` method (called by
construct_python_object_apply) and all special methods (e.g. __set__,
__setitem__, etc.).

Users who need special attributes being set in the state of a
deserialized object can still do it through the UnsafeLoader, which
however should not be used on untrusted input. Additionally, they can
subclass FullLoader and redefine `get_state_keys_blacklist()` to
extend/replace the list of blacklisted keys, passing the subclassed
loader to yaml.load.

* Make sure python/object/new constructor does not set some properties

* Add test to show how to subclass FullLoader with new blacklist
2020-03-17 19:09:55 +01:00
..
__init__.py Changes for 5.3 2020-01-06 20:37:50 +01:00
composer.py Fix typos 2017-08-08 06:05:28 -05:00
constructor.py Prevents arbitrary code execution during python/object/new constructor (#386) 2020-03-17 19:09:55 +01:00
cyaml.py Make default_flow_style=False 2019-03-08 09:09:48 -08:00
dumper.py Make default_flow_style=False 2019-03-08 09:09:48 -08:00
emitter.py Fix logic for quoting special characters (#276) 2019-11-18 11:59:54 +01:00
error.py scanner: use infinitive verb after auxiliary word could 2015-04-04 13:25:24 -03:00
events.py scanner: use infinitive verb after auxiliary word could 2015-04-04 13:25:24 -03:00
loader.py fix typos and stylistic nit 2019-12-03 23:58:55 +01:00
nodes.py scanner: use infinitive verb after auxiliary word could 2015-04-04 13:25:24 -03:00
parser.py scanner: use infinitive verb after auxiliary word could 2015-04-04 13:25:24 -03:00
reader.py Fix reader for Unicode code points over 0xFFFF (#351) 2019-12-20 20:38:46 +01:00
representer.py remove some unused imports (#260) 2019-12-20 20:38:46 +01:00
resolver.py Adding an implicit resolver to a derived loader should not affect the base loader (fixes issue #57). 2016-08-25 17:42:41 -05:00
scanner.py Fix up small typo 2019-12-04 00:31:05 +01:00
serializer.py scanner: use infinitive verb after auxiliary word could 2015-04-04 13:25:24 -03:00
tokens.py scanner: use infinitive verb after auxiliary word could 2015-04-04 13:25:24 -03:00