Repository navigation
security: cap text-level CSS parser recursion/output on calc(), :not(), :is() - #273
Merged
Merged
Conversation
calcParser's grammar (expr/term/factor, the standard mutually-
recursive expression-parser shape) recurses from factor straight
back into expr for each '(' with no depth check. Unlike deep HTML
element nesting, nothing upstream bounds how many parens a single
calc(...) value's own source text can carry -- a style="..."
attribute on the main document (capped only at 32MB) can trivially
carry millions.
Confirmed live: a synthetic 3,000,000-deep calc((((...1...))))
crashes with an unrecoverable "fatal error: stack overflow" (not a
panic -- recover() cannot catch it) where 1,000,000 does not yet.
factor now caps its own recursion at 256 levels, failing the same
way this parser already fails on any other malformed input rather
than recursing further.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This was referenced Oct 11, 2026
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
calcParser's grammar (expr/term/factor, the standard mutually-recursive expression-parser shape) recurses fromfactorstraight back intoexprfor each(with no depth check.calc(...)value's own source text can carry — astyle="..."attribute on the main document (capped only at 32MB) can trivially carry millions.calc((((...1...))))crashes with an unrecoverablefatal error: stack overflow(not a panic —recover()cannot catch it) where 1,000,000 does not yet.factornow caps its own recursion at 256 levels, failing the same way this parser already fails on any other malformed input rather than recursing further.Test plan
go build ./...go test ./...(all packages pass)TestResolveCalcDoesNotCrashOnPathologicallyDeepParenscsspackage coverage unaffected (99.5% before/after);factor's own coverage rises slightly (92.0%→95.0%)🤖 Generated with Claude Code