Ruby "Psych::DisallowedClass" loading YAML in CI
Newer Psych makes YAML.load safe by default, refusing to instantiate arbitrary classes. Loading a YAML document that contains a tagged object (a Symbol, Time, or custom class) raises Psych::DisallowedClass unless that class is explicitly permitted.
What this error means
Code or a fixture load fails with "Psych::DisallowedClass: Tried to load unspecified class: X", often after a Ruby/Psych upgrade where YAML.load became strict.
Psych::DisallowedClass: Tried to load unspecified class: Symbol
from /usr/local/lib/ruby/3.3.0/psych/class_loader.rb:...Common causes
Psych made YAML.load safe by default
A newer Psych version routes YAML.load through safe loading, so previously-loadable tagged classes are now rejected.
The YAML contains non-permitted types
The document embeds Symbols, Time, or custom objects that are not in the default allowlist.
How to fix it
Permit the classes you actually need
- Switch to safe_load with an explicit permitted_classes list.
- Add only the classes the document legitimately contains.
- Enable aliases only if the YAML uses anchors.
YAML.safe_load(text, permitted_classes: [Symbol, Time], aliases: true)Use unsafe_load only for fully trusted input
If the source is entirely trusted (your own fixtures), unsafe_load restores the old behavior, but never use it on external input.
YAML.unsafe_load(File.read('config/trusted.yml'))How to prevent it
- Prefer safe_load with an explicit permitted_classes list.
- Avoid embedding arbitrary Ruby objects in YAML.
- Reserve unsafe_load for input you fully control.