Project

General

Profile

Actions

Bug #7780

closed

Marshal & YAML should deserialize only basic types by default.

Added by marcandre (Marc-Andre Lafortune) about 11 years ago. Updated over 6 years ago.

Status:
Closed
Target version:
ruby -v:
r39035
[ruby-core:51834]

Description

YAML is a wonderful, powerful and expressive format to serialize data in a human readable way.

It can be used, for example, to read and write nice configuration files, to store strings, numbers, dates & times in a hash.

YAML.load will, by default, instantiate any user class and set instance variables directly.

On the other hand, this can make apparently innocent code lead to major vulnerabilities, as was clearly illustrated by different exploits recently.

I feel YAML.load should, by default, be safe to use, for example by instantiating only known core classes.

The same can be said for Marshal, even though it would more rarely be used as a public interface to exchange data.

Maybe the following transition path could be taken:

  1. Have {YAML|Marshal}.load issue a warning (once) that next minor will only deserialize basic types.
  2. Create {YAML|Marshal}.unsafe_load, which does the same thing as current load, without a warning of course.
    As these changes are compatible and extremely minor, I would like them to be considered for Ruby 2.0.0. They also make for a

"Secure by default" is not a new concept.
Rails 3.0 has XSS protection by default, for example. The fact that one needs to do extra processing like calling raw when that security needs to be bypassed makes XSS attacks less likely.
I believe the typical use of Yaml.load is to load basic types.
We should expect users to use the easiest solution, so that should be the safe way.
If a tool makes the safe way of doing things the default, and makes it easy to do more complex deserializing (e.g. whitelisting some user classes), this can only lead to less vulnerabilities.

I hope nobody will take offence that I've tagged this issue as a "bug". The current behavior is as speced, but it can be argued that a design that is inherently insecure is a defect.


Related issues 2 (0 open2 closed)

Related to Ruby master - Feature #7677: YAML load mode that does instantiate Ruby Closedtenderlovemaking (Aaron Patterson)01/09/2013Actions
Related to Ruby master - Bug #7759: Marshal.load is not documented to be dangerousClosed01/31/2013Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0