Skip to content

Reject config files with !-prefixed local YAML tags - #4688

Open
anuraaga wants to merge 1 commit into
bufbuild:mainfrom
anuraaga:yaml-reject-tag
Open

anuraaga wants to merge 1 commit into
bufbuild:mainfrom
anuraaga:yaml-reject-tag

Conversation

@anuraaga

@anuraaga anuraaga commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

An unquoted string starting with ! is a YAML type tag to force the following value to a specific type registered by the decoder (as opposed to a built-in type that starts with !!). We don't register any such types so there is no valid usage for this. On the flip side, there are places where a string starting with ! is appropriate such as globs, but when forgetting quotes, it gets parsed as a type tag, which effectively silently replaces the value with an empty string which we then use as is. For globs, this means ignoring ! unexclude globs completely, things that shouldn't be excluded are. This actually affects both v1 and v2 to different degrees.

The approach is to parse the YAML once to a YAML node to first to be able to distinguish type tags from values to find and reject them, before parsing the YAML into the config struct. Unfortunately, there seems to be no way to do it in a single pass since a config struct doesn't preserve type info and no decoder, even in other libraries, have an option to reject local tags. Parse only happens once per operation and is still microseconds for very large configs, I think the problematic case (silent corruption) is significant enough that we need to eat it.

Fixes #3973

@anuraaga
anuraaga requested a review from emcfarlane September 17, 2026 06:39

@emcfarlane emcfarlane left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat.

@emcfarlane
emcfarlane requested a review from doriable September 17, 2026 13:45
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.

buf silently consumes v1 configuration errors

2 participants