Psych::DisallowedClass while updating a rails ActiveModel entry

Viewed 1256

This is a little weird, I am trying to update an ActiveModel entry via rails_admin console and updating any attribute on the model throws the error Psych::DisallowedClass. Looks to me like the error is only thrown when the Model has some serialized fields. I am not sure how the Psych library gets in the serialization scene under the hood, so looking for some pointers here.

Thanks!

2 Answers

I ran into the same problem after updating from rails 5.2.5 to 5.2.8.

I solved it by adding

config.active_record.yaml_column_permitted_classes = [Symbol]

in my config/application.rb.

From gem version psych 4.0, there are the strict approach for parsing the YAML files. So either use older versions of psych, pass the permitted_classes args to the #load method to allow the class, which you've got the exception for:

YAML.load(txt, permitted_classes: [Gem::Specification, Symbol])

The code is required to load YAML document with a specific non standard classes. Because loader prevents user from loading some unsafe classes. More information can be inferred from the sources of YAML.

Related