Skip to content

Add maxPartialDepth to bound partial recursion - #1220

Merged
jknack merged 1 commit into
masterfrom
1219
Nov 25, 2026
Merged

jknack merged 1 commit into
masterfrom
1219

Conversation

@jknack

@jknack jknack commented Nov 25, 2026

Copy link
Copy Markdown
Owner

The infinite-loop guard compares raw TemplateSource.filename() strings, so aliases of the same template (e.g. "a", "x/../a") evade detection. Recursion through a data-driven dynamic partial such as {{> (lookup '.' 'p')}} then ends in an uncaught StackOverflowError.

Add Handlebars.maxPartialDepth (default 256) with setter and fluent accessor. Partial now throws a HandlebarsException when the invocation stack reaches that depth, before loading the next partial. The limit applies only while infiniteLoops is false.

Add a regression test to InfiniteLoopTest that recurses through aliased names for one template.

fixes #1219

The infinite-loop guard compares raw TemplateSource.filename()
strings, so aliases of the same template (e.g. "a", "x/../a") evade
detection. Recursion through a data-driven dynamic partial such as
{{> (lookup '.' 'p')}} then ends in an uncaught StackOverflowError.

Add Handlebars.maxPartialDepth (default 256) with setter and fluent
accessor. Partial now throws a HandlebarsException when the invocation
stack reaches that depth, before loading the next partial. The limit
applies only while infiniteLoops is false.

Add a regression test to InfiniteLoopTest that recurses through
aliased names for one template.

fixes #1219
@jknack jknack added the bug label Nov 25, 2026
@jknack jknack added this to the 4.5.9 milestone Nov 25, 2026
@jknack
jknack merged commit ae71cc8 into master Nov 25, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

partials: Partial recursion guard bypassed via aliased template locations, causing StackOverflowError

1 participant