Skip to content

fix: refuse YAML aliases and accept single-use CAPTCHA tokens only - #476

Merged
polterguy merged 2 commits into
masterfrom
fix/yaml-aliases-single-use-captcha
Dec 5, 2026
Merged

polterguy merged 2 commits into
masterfrom
fix/yaml-aliases-single-use-captcha

Conversation

@polterguy

@polterguy polterguy commented Dec 5, 2026 •

Copy link
Copy Markdown
Owner

YAML

yaml2lambda and yaml2json now refuse aliases. Markdown front matter goes through yaml2lambda, so it is covered too. A few hundred bytes of aliases that refer to other aliases expand into gigabytes ("billion laughs"), which caused the OutOfMemoryException in the external review. Capping the number of aliases doesn't bound the expansion, and data YAML has no need for aliases, so they are refused outright. Anchors that nothing refers to are still accepted.

YamlGuard.Ensure checks for aliases in a separate scan before deserializing, the same way HtmlDepth.Ensure checks HTML. It can't be done inside the deserializer, because YamlDotNet wraps anything its parser throws in a generic "Exception during deserialization". Deep nesting needs no guard of ours: YamlDotNet's deserializer already throws MaximumRecursionLevelReachedException, which can be caught.

XML needed no change: xml2lambda already prohibits DTDs.

CAPTCHA

magic.auth.captcha-verify now accepts challenge-based tokens only:

  • Why: the age-based mode never recorded tokens it had accepted, so one token could be replayed any number of times within its 10-second window.
  • What changed: every token must carry a c_ challenge issued by /magic/system/misc/challenge, and the challenge is removed from the cache on first use. The [age] argument is gone from the slot and from the mcaptcha workflow action.
  • Client library: magic-captcha.js and its endpoint are removed. magic-captcha-challenge.js, which the chat widget already uses, has the same mcaptcha.token(callback, workload) API.

Checked on a local backend: a fresh token is accepted, the same token replayed is refused, an age-style token is refused, magic-captcha.js returns 404 and magic-captcha-challenge.js returns 200.

Other

  • Tests added in JsonTests.cs: aliases are refused in both slots, and an unused anchor is still accepted.
  • Bumps the version to v24.5.5.

🤖 Generated with Claude Code

YAML: yaml2lambda and yaml2json (and markdown front matter, which goes
through yaml2lambda) now parse through SafeYamlParser, which refuses
aliases, since a few hundred bytes of aliases referring to aliases expand
into gigabytes, and refuses documents nested deeper than 256 levels, since
a stack overflow kills the process.

CAPTCHA: magic.auth.captcha-verify accepts challenge-based tokens only. The
age-based mode accepted the same token any number of times within its
window, so it is removed along with its client library, magic-captcha.js.
magic-captcha-challenge.js has the same API.

Bumps the version to v24.5.5.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The deserializer wrapped the alias error thrown from inside its parser in a
YamlException, so callers saw "Exception during deserialization". Aliases
are now refused by YamlGuard in a separate scan before deserializing, giving
a plain "YAML aliases are not supported" error. The depth limit is dropped,
since YamlDotNet's deserializer already refuses runaway nesting itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sonarqubecloud

sonarqubecloud Bot commented Dec 5, 2026

Copy link
Copy Markdown

@polterguy
polterguy merged commit 9e9011b into master Dec 5, 2026
9 checks passed
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.

1 participant