Skip to content
Latchkey

Ruby "Psych::BadAlias" / YAML Aliases Disabled in CI

Newer Psych (Ruby’s YAML library) loads YAML safely by default - it rejects aliases and arbitrary classes. Files or fixtures that rely on YAML anchors/aliases, or serialize objects, now raise unless you opt in.

What this error means

Loading a YAML file (a config, a fixture, a CI cache) fails with Psych::BadAlias "Unknown alias", or Psych::DisallowedClass "Tried to load unspecified class". The same YAML loaded on an older Ruby/Psych.

Ruby traceback
Psych::BadAlias: Unknown alias: default
	from .../psych/visitors/to_ruby.rb:...
# or
Psych::DisallowedClass: Tried to load unspecified class: Symbol

Common causes

Aliases disabled by default in safe load

YAML.load (now safe_load under the hood) disables anchors/aliases unless aliases: true is passed. YAML using *alias references then raises Psych::BadAlias.

Non-permitted classes in the YAML

safe_load only allows a small set of core types. YAML that serializes Symbols, Dates, or custom objects raises Psych::DisallowedClass unless those classes are permitted.

How to fix it

Opt into aliases and permitted classes

Enable aliases and list the classes the file legitimately needs.

Ruby
YAML.safe_load(File.read(path), aliases: true,
  permitted_classes: [Symbol, Date, Time])
# trusted, non-user-supplied file only:
# YAML.unsafe_load(File.read(path))

Or remove the aliases from the YAML

  1. For config you control, expand the anchored/aliased values inline so no alias is needed.
  2. Avoid serializing Symbols/objects into YAML that is loaded safely.
  3. Keep user-supplied YAML on safe_load with a minimal permitted set.

How to prevent it

  • Load YAML with safe_load and explicit aliases/permitted_classes.
  • Reserve unsafe_load for fully trusted, in-repo files.
  • Avoid YAML anchors/aliases in files loaded safely.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →