-
Notifications
You must be signed in to change notification settings - Fork 0
Add depth limit to template AST validation walkers #7
Copy link
Copy link
Open
Labels
area/templatingTemplate parsing, validation, or evaluation changes.Template parsing, validation, or evaluation changes.good first issueSmall, well-scoped tasks for new contributors.Small, well-scoped tasks for new contributors.help wantedLooking for community contributions.Looking for community contributions.kind/featureNew functionality or enhancement request.New functionality or enhancement request.priority/mediumNormal priority item.Normal priority item.
Metadata
Metadata
Assignees
Labels
area/templatingTemplate parsing, validation, or evaluation changes.Template parsing, validation, or evaluation changes.good first issueSmall, well-scoped tasks for new contributors.Small, well-scoped tasks for new contributors.help wantedLooking for community contributions.Looking for community contributions.kind/featureNew functionality or enhancement request.New functionality or enhancement request.priority/mediumNormal priority item.Normal priority item.
Problem statement
The template evaluation layer enforces
maxResolveDepth = 128during value resolution, but the validation AST walkers (walkTemplateNode,walkStepRefs,walkJSONTemplates) have no depth guard. A deeply nested template (thousands of{{if}}/{{with}}/{{range}}blocks) could exhaust the goroutine stack during admission validation before the evaluator's depth limit ever applies.Proposed change
Add a
depth intparameter (or a shared constant likemaxASTDepth = 256) to the recursive walkers invalidation.goandstep_refs.go. When depth is exceeded, append an error and return instead of recursing further.Apply the same pattern to:
walkStepRefsinstep_refs.gowalkJSONTemplatesinvalidation.gorootNameFromNode/rootNameFromCommand/rootNameFromPipemutual recursion invalidation.goAffected area
templatingCompatibility / migration
No API change. Internal safety hardening only. All existing tests should continue to pass.
Alternatives considered
Additional context
The evaluator already has
maxResolveDepth = 128(inevaluator.go). This issue brings validation walkers to the same standard. Identified during code review of thecoretransport and templating changes.