fix(expand): bound the total nodes produced by for-each - #261
Merged
Merged
Conversation
53 tasks
LeadcodeDev
force-pushed
the
fix/media-protocol-allowlist
branch
from
September 22, 2026 06:11
3e4b39f to
e9965fc
Compare
LeadcodeDev
force-pushed
the
fix/expand-node-budget
branch
from
September 22, 2026 06:11
62393d5 to
4dc047f
Compare
LeadcodeDev
force-pushed
the
fix/media-protocol-allowlist
branch
from
September 22, 2026 08:36
e9965fc to
edd1852
Compare
LeadcodeDev
force-pushed
the
fix/expand-node-budget
branch
from
September 22, 2026 08:36
4dc047f to
9daff5f
Compare
LeadcodeDev
force-pushed
the
fix/media-protocol-allowlist
branch
from
September 22, 2026 08:45
edd1852 to
50f6268
Compare
LeadcodeDev
force-pushed
the
fix/expand-node-budget
branch
from
September 22, 2026 08:46
9daff5f to
226b364
Compare
LeadcodeDev
changed the base branch from
fix/media-protocol-allowlist
to
chantier/audit-2026-09
September 22, 2026 08:54
LeadcodeDev
force-pushed
the
fix/expand-node-budget
branch
from
September 22, 2026 09:02
226b364 to
690c00b
Compare
`MAX_EXPANSION_DEPTH` bounds how deeply directives may nest, not how many nodes they produce, and nesting one `for-each` inside another's `template` is explicitly supported (`use_template_can_contain_a_nested_for_each`, expand.rs:1005). Each nesting level costs exactly +1 depth (resolve_entry recurses with `depth + 1` per produced node, while `walk_children` forwards `depth` unchanged), so up to 64 levels are legal and the output is the product of the array lengths. Four nested levels of 50 elements is 6.25M nodes from a file under 1 KB; eight levels of 10 is 10^8. Each iteration does a full `Value` deep-clone of the template plus a `substitute` walk, so the process hangs and OOMs during `expand_directives` — before validation, before any render, and with no diagnostic. An LLM-authored or third-party scenario reaches this through the documented public syntax; `--no-validate` is not needed. Refs #220
LeadcodeDev
force-pushed
the
fix/expand-node-budget
branch
from
September 22, 2026 09:06
690c00b to
958bbdb
Compare
LeadcodeDev
added a commit
that referenced
this pull request
Sep 22, 2026
`MAX_EXPANSION_DEPTH` bounds how deeply directives may nest, not how many nodes they produce, and nesting one `for-each` inside another's `template` is explicitly supported (`use_template_can_contain_a_nested_for_each`, expand.rs:1005). Each nesting level costs exactly +1 depth (resolve_entry recurses with `depth + 1` per produced node, while `walk_children` forwards `depth` unchanged), so up to 64 levels are legal and the output is the product of the array lengths. Four nested levels of 50 elements is 6.25M nodes from a file under 1 KB; eight levels of 10 is 10^8. Each iteration does a full `Value` deep-clone of the template plus a `substitute` walk, so the process hangs and OOMs during `expand_directives` — before validation, before any render, and with no diagnostic. An LLM-authored or third-party scenario reaches this through the documented public syntax; `--no-validate` is not needed. Refs #220
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.
Severity Low, category security. Location:
crates/rustmotion-core/src/expand.rs:157Impact
MAX_EXPANSION_DEPTHbounds how deeply directives may nest, not how many nodes they produce, and nesting onefor-eachinside another'stemplateis explicitly supported (use_template_can_contain_a_nested_for_each, expand.rs:1005). Each nesting level costs exactly +1 depth (resolve_entry recurses withdepth + 1per produced node, whilewalk_childrenforwardsdepthunchanged), so up to 64 levels are legal and the output is the product of the array lengths. Four nested levels of 50 elements is 6.25M nodes from a file under 1 KB; eight levels of 10 is 10^8. Each iteration does a fullValuedeep-clone of the template plus asubstitutewalk, so the process hangs and OOMs duringexpand_directives— before validation, before any render, and with no diagnostic. An LLM-authored or third-party scenario reaches this through the documented public syntax;--no-validateis not needed.Fix
Thread a mutable node/iteration budget through
resolve_entry(e.g. a&mut u64counter decremented per produced node, ceiling in the low millions) and fail with a named error when it is exhausted, exactly asExpansionDepthExceededdoes for depth. Capitems.len()per directive as a cheap first line of defence.Evidence the audit read
Part of the September 2026 audit remediation chantier. Refs #220 (RM-43).