Skip to content

Refuse catalog YAML that safe loading rejects as an invalid document - #714

Merged
TonsOfFun merged 1 commit into
activeagents:mainfrom
yorzi:fix/catalog-yaml-disallowed-class
Nov 17, 2026
Merged

TonsOfFun merged 1 commit into
activeagents:mainfrom
yorzi:fix/catalog-yaml-disallowed-class

Conversation

@yorzi

@yorzi yorzi commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

What this does

Catalog.parse turned only Psych::SyntaxError into Catalog::InvalidDocument. YAML.safe_load refuses two other things with sibling Psych::Exception subclasses: a tag naming a class outside the permitted list (Psych::DisallowedClass, for example --- !ruby/object:Object {}), and an alias to an anchor the document never defines (Psych::BadAlias). Every caller rescues only InvalidDocument, so these documents escaped:

  • the catalog import and preview endpoints, as a 500,
  • the catalogs_import and catalogs_preview MCP tools, as an internal error rather than a tool error,
  • the exploration and catalog-entry paths that parse a catalog.

The rescue is now Psych::Exception, their common parent. ScenarioParser, the CLI credentials reader and the sandbox config readers already use it. These documents now get the same 422 "the catalog is not valid YAML: ..." as a syntax error. What safe loading permits (Symbol, aliases) is unchanged, and Catalog.load (trusted files, rake tasks) is untouched.

Tests:

  • test/evals/catalog_test.rb: a disallowed class at the root and nested, and an undefined alias, are each refused as InvalidDocument with the reason. Symbols and anchors/aliases still parse.
  • actionagent/test/scenario_catalogs_api_test.rb: import and preview of !ruby/object:Object answer 422 and create nothing.
  • actionagent/test/mcp_dashboard_tools_test.rb: catalogs_import and catalogs_preview answer with isError: true.
  • All three fail before the change: Psych::DisallowedClass raised from the parser and the controller, and no tool error from MCP.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Performance improvement

Scope check

  • I read the contributing guide
  • This fits activeagent's stated focus
  • This isn't application-specific logic that belongs in user code
  • This benefits most users, not just my use case

Related issue

None filed.

Quality check

  • The project's hooks and linters pass (bin/rubocop on the changed files)
  • The new tests fail before this change and pass after it
  • The full test suite passes. Framework suite (Rails 8.1): 2585 runs, 0 failures, 0 errors. Engine suite: 0 failures, and 11 errors, all in CliContractTest (rack-session undefined method 'id' for Hash), which fail identically on an untouched main in this environment
  • I updated documentation where needed (CHANGELOG only)
  • I didn't edit generated files by hand

Ownership

  • I understand every line of this change and can answer questions about it

API changes

  • Breaking change
  • New public methods or classes
  • Changed method signatures
  • No API changes

Catalog.parse rescued only Psych::SyntaxError. YAML.safe_load refuses a
tag naming a class outside the permitted list (Psych::DisallowedClass) and
an alias to an undefined anchor (Psych::BadAlias) with errors that are not
syntax errors, so a document such as `--- !ruby/object:Object {}` escaped
ScenarioCatalogImport as a 500 from the catalog import and preview
endpoints, and as an internal error from the catalogs_import and
catalogs_preview MCP tools.

The rescue is now Psych::Exception, their common parent, as ScenarioParser
and the CLI credentials reader already do, so these documents get the
same "the catalog is not valid YAML" 422 as a syntax error. The permitted
classes and aliases are unchanged.
TonsOfFun added a commit that referenced this pull request Nov 17, 2026
@TonsOfFun
TonsOfFun merged commit a995f19 into activeagents:main Nov 17, 2026
18 checks passed
@TonsOfFun TonsOfFun added this to the 1.9.9 milestone Nov 17, 2026
@TonsOfFun TonsOfFun mentioned this pull request Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants