Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an equivalent to yaml.safe_load in Ruby?

A rather high-profile security vulnerability in Rails recently illuminated the potential dangers of parsing user-supplied YAML in a Ruby application.

A quick Google search reveals that Python's YAML library includes a safe_load method which will only deserialize "simple Python objects like integers or lists" and not objects of any arbitrary type.

Does Ruby have an equivalent? Is there any way to safely accept YAML input in a Ruby application without hand-writing a custom parser?

like image 779
Dan Tao Avatar asked Dec 26 '22 11:12

Dan Tao


1 Answers

Following Jim's advice I went ahead and wrote safe_yaml, a gem which adds the YAML.safe_load method and uses Psych internally to do the heavy lifting.

like image 165
Dan Tao Avatar answered Jan 09 '23 22:01

Dan Tao