GHSA-WMMR-QJC6-RP53
string.literal bypasses LimitToString via unguarded Escape(), enabling memory-exhaustion DoS
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 |
|---|---|---|---|
| Remediación | Parche 7.6.0 | Scriban · -1 d desde divulgación | |
| Divulgación | Publicada | GHSA-WMMR-QJC6-RP53 divulgada · CVSS 7.5 (GitHub) | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Summary
The `string.literal` builtin in Scriban allocates its output without any `LimitToString` check, allowing a template author to exhaust process memory. `string.literal` calls the internal `Escape()` helper directly, and `Escape()` doubles the length of all-backslash input on each call. When the follow-up fix for GHSA-95w2-9mjq-6c74 (release 7.5.3) wrapped `string.escape` with a limit-aware guard, it left `string.literal`, which reaches the same `Escape()` code, unguarded. An attacker who can supply a Scriban template can grow a string past .NET's maximum object size within a handful of loop iterations under default settings, producing an `OutOfMemoryException` that crashes the hosting process.
Root Cause
Scriban exposes a configurable `TemplateContext.LimitToString` safety limit (default 1 MB) that is meant to cap the size of strings produced by builtins. The limit can only be enforced by a function that receives the `TemplateContext`. `string.literal` is bound to a static helper with no `TemplateContext` parameter, so no limit check is possible at that call site, and the helper calls `Escape()` directly rather than the limit-aware `EscapeWithLimit` wrapper used by `string.escape`.
src/Scriban/Functions/StringFunctions.cs:430-433
public static string? Literal(string? text)
=> text is null ? null : $"\"{Escape(text)}\"";
src/Scriban/Functions/StringFunctions.cs:43-47 (constructor)
SetValue("escape", DynamicCustomFunction.Create(
new Func<TemplateContext, string?, string?>(EscapeWithLimit)), true);
// only "escape" is overridden; "literal" keeps its unguarded static binding
src/Scriban/Functions/StringFunctions.cs:104 (inside Escape)
case '\\': appendText = @"\\"; // each backslash expands to two charactersBecause `Escape()` emits two characters for every backslash, repeatedly piping an all-backslash string through `string.literal` roughly doubles its length each time, with no limit applied.
Impact
Any component that renders attacker-influenced Scriban templates under default `TemplateContext` settings is affected; template input is commonly accepted in content management, report generation, and email or notification templating. No authentication beyond the ability to submit a template is required, and no user interaction is needed because rendering runs automatically. A single short template drives allocation past the .NET maximum object size, raising `OutOfMemoryException`. The failure terminates the hosting process, so all concurrent requests served by that process are lost (denial of service). There is no confidentiality or integrity impact.
Proof of Concept
No external dependencies are required beyond the Scriban package (release 7.5.3) and default `TemplateContext` settings (`LimitToString` = 1048576, `LoopLimit` = 1000).
using Scriban;
// Seed: 262,144 backslashes (under the 1 MB LimitToString).
// Each string.literal pass roughly doubles the length; ~12 passes exceed
// .NET's 2 GB maximum object size and raise OutOfMemoryException.
var template = Template.Parse(
"{{ x = \"\\\\\" | string.pad_left 262144 }}" +
"{{ for i in 1..20 }}{{ x = x | string.literal }}{{ end }}");
var result = template.Render();Unhandled exception. System.OutOfMemoryException:
Exception of type 'System.OutOfMemoryException' was thrown.
at System.String.Concat(...)
at Scriban.Functions.StringFunctions.Escape(String)
at Scriban.Functions.StringFunctions.Literal(String)Attack Chain
- Exposure: The host renders an attacker-supplied Scriban template through `Template.Parse(...).Render()`; the template language itself is the input surface, so arbitrary builtins and loops are available.
- Control: The attacker constructs a seed string of 262,144 backslash characters. The string-multiplication guard in `ScriptBinaryExpression.CalculateToString()` (`src/Scriban/Syntax/Expressions/ScriptBinaryExpression.cs:346`) permits it because 262,144 is below the 1,048,576 limit.
- Path: Inside a `for` loop, each iteration pipes the variable through `string.literal`. The pipe resolves directly to `StringFunctions.Literal()` with no intermediate size check (`src/Scriban/Syntax/Expressions/ScriptPipeCall.cs`), and the result is stored back into the variable without any `Write` or `ObjectToString` conversion, so output-stage limits never run.
- Guard: `Literal()` (`src/Scriban/Functions/StringFunctions.cs:430`) calls `Escape()` directly and has no `TemplateContext` parameter, so the `LimitToString` check applied to `string.escape` is absent on this path.
- Primitive: `Escape()` doubles the all-backslash string on each pass (`src/Scriban/Functions/StringFunctions.cs:104`), giving unbounded exponential growth of a single in-memory string.
- Result: After roughly 12 iterations the intermediate string exceeds the .NET maximum object size, raising `OutOfMemoryException` and crashing the process. The loop needs only about a dozen of the default 1000 allowed iterations.
Bypass Evidence
The GHSA-95w2-9mjq-6c74 fix (release 7.5.3) re-registered `string.escape` with the context-aware `EscapeWithLimit`, which calls `VerifyResultStringLength` and throws before building an oversized string. That override is installed only for `escape` in the `StringFunctions` constructor (`src/Scriban/Functions/StringFunctions.cs:43-47`); `string.literal` was not re-registered and still resolves to the static `Literal()` helper that calls the same `Escape()` without a limit. As a negative control, substituting `string.escape` for `string.literal` in the proof of concept raises the expected "exceeds the configured LimitToString" error, confirming the guard exists for one entry point but not the other. Attempts to find an alternate guard (the cumulative `OutputLimit`, `ObjectToString` truncation, the binary-expression multiplication check, and the function-invocation pipeline) all failed because none of them inspect a builtin's return value stored into a variable.
Affected Versions
- Ecosystem: `nuget`
- Package: `Scriban`
- Confirmed affected range: `<= 7.5.3`
- Latest release checked: `7.5.3` (NuGet
https://www.nuget.org/packages/Scriban/7.5.3) - Fix status: fixed in 7.6.0
The `string.literal` builtin reaches `Escape()` without a limit in every available release through 7.5.3. The `LimitToString` guard mechanism and the `EscapeWithLimit` wrapper were introduced in 7.5.3 for `string.escape` only, so 7.5.3 remains vulnerable through the `string.literal` entry point. The signed distribution `Scriban.Signed` shares the same code and is affected identically.
Suggested Fix
Enforce `LimitToString` on the `string.literal` path, as was already done for `string.escape`. Re-register `literal` in the `StringFunctions` constructor with a context-aware wrapper that computes the escaped length (the existing `GetEscapedLength` helper) and calls `VerifyResultStringLength` before building the result, so the quote-wrapped escaped string is bounded by the configured limit. The guard should account for the two surrounding quote characters and continue to respect `LimitToString <= 0` as "disabled." As a general hardening measure, auditing every string-producing builtin that calls `Escape()` or performs size-expanding transformations for a matching limit check would prevent similar omissions.
Reported by zx.
Patches
Fixed in Scriban and Scriban.Signed 7.6.0: `string.literal` now enforces `TemplateContext.LimitToString` before building its result. Users should upgrade to 7.6.0 or later. As a workaround on older versions, do not render untrusted templates, or remove `string.literal` from the builtins exposed to them.
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.6.0 | -1 d | 7.6.1 no afectada |
nugetScriban.Signed |
Corregida | 7.6.0 | -1 d | 7.6.1 no afectada |
7.6.0Arsenal 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-wmmr-qjc6-rp53Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
