| 1 |
--- |
| 2 |
title: Why does StrictYAML not parse direct representations of Python objects? |
| 3 |
--- |
| 4 |
|
| 5 |
Regular YAML allows the direct representation of Python objects. |
| 6 |
|
| 7 |
For example: |
| 8 |
|
| 9 |
```yaml |
| 10 |
--- !python/hash:UserObject |
| 11 |
email: [email protected] |
| 12 |
password: passwordtoset |
| 13 |
type: admin |
| 14 |
``` |
| 15 |
|
| 16 |
If we load this YAML formatted string in, we get a user object. This was |
| 17 |
how YAML was intended to work since it allows the ability to write objects |
| 18 |
to and read them from, say, a database. |
| 19 |
|
| 20 |
By itself, this behavior isn't necessarily capable of enacting a successful |
| 21 |
attack, so not all code that parses untrusted YAML is insecure, |
| 22 |
but it can be used, especially in conjunction with metaprogramming to execute |
| 23 |
arbitrary code on your system. |
| 24 |
|
| 25 |
This shares a lot in common with the pickle module's behavior, which is why |
| 26 |
its use with [untrusted input is strongly recommended against in the Python |
| 27 |
docs](https://docs.python.org/3/library/pickle.html). |
| 28 |
|
| 29 |
This anti-feature led to Ruby on Rails' spectacular [security fail](https://codeclimate.com/blog/rails-remote-code-execution-vulnerability-explained/). |