Configuration: Support YAML anchors and aliases in .herb.yml#1632
Open
matiasleidemer wants to merge 1 commit intomarcoroth:mainfrom
Open
Configuration: Support YAML anchors and aliases in .herb.yml#1632matiasleidemer wants to merge 1 commit intomarcoroth:mainfrom
matiasleidemer wants to merge 1 commit intomarcoroth:mainfrom
Conversation
`Herb::Configuration#load_config` calls `YAML.safe_load_file` without `aliases: true`, which raises `Psych::AliasesNotEnabled` when a project's `.herb.yml` uses anchors and aliases. This is a common ergonomics pattern for config files with repeated rule definitions. The fix mirrors how Rails loads `database.yml`, `credentials.yml`, and how RuboCop loads `.rubocop.yml` — developer-authored local config is trusted input, so the DoS-protection rationale behind Psych's default doesn't apply here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1631 —
Herb::Configuration#load_configraisesPsych::AliasesNotEnabledat runtime when.herb.ymluses YAML anchors and aliases.The fix is a one-character addition: pass
aliases: truetoYAML.safe_load_file. Added a regression test that exercises the anchor/alias case end-to-end throughHerb::Configuration.load.Rationale
Psych.safe_loaddefaultsaliases: falseto mitigate the "billion laughs" DoS against untrusted YAML. But.herb.ymlis developer-authored local config — same trust model asdatabase.yml,credentials.yml, and.rubocop.yml, all of which enable aliases. Anchors/aliases are a common ergonomics pattern for config files with repeated rule definitions (the project I hit this on has ~60 aliases in its.herb.yml).Reproduction
Before this PR, loading a config like:
raises
Psych::AliasesNotEnabled. After this PR, it loads cleanly and bothincludeandexcluderesolve to the aliased list. See the new testloads configuration using YAML anchors and aliasesintest/configuration_test.rb.Changes
lib/herb/configuration.rb: addaliases: trueto theYAML.safe_load_filecalltest/configuration_test.rb: new regression testTest plan
bundle exec rake testlocally forConfigurationTest(full suite needs native build; maintainer CI will exercise it end-to-end)aliases: trueagainst a minimal YAML fixture