GHSA-8637-5Q5Q-HXVW
TemplateContext.Reset retains attacker-controlled array.cycle state in Tags
Texto original en inglés · Ver en español
CVSS:3.1/AV:N/AC:H/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-8637-5Q5Q-HXVW divulgada · CVSS 5.9 (GitHub) | |
| Remediación | Parche 7.6.0 | Scriban · 0 d desde divulgación | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Summary
Pooled `TemplateContext` instances retain attacker-chosen `array.cycle` group strings after `Reset()`, so memory grows per request.
Details
`ArrayFunctions.Cycle` (`src/Scriban/Functions/ArrayFunctions.cs:188-209`) stores `CycleKey(strGroup)` in public `Tags`. `Reset()` (`TemplateContext.cs:1026-1055`) clears output, globals, cultures, source files, `CachedTemplates` and `_memberAccessors`, but not `Tags`.
Suggested fix. Do not store per-render builtin state in the public `Tags` dictionary, or clear only the builtin-owned entries on reset. For example, move `CycleKey` state to a private `Dictionary<CycleKey, int>` on `TemplateContext` and clear it in `Reset()`, and store the `math.random` `Random` in a private field. If `Tags` must remain public for host use, add a small internal registry of builtin keys/prefixes and remove those in `Reset()` without touching host entries.
Proof of concept
Default context, five renders with `ctx.Reset()` between them:
var ctx = new TemplateContext();
ctx.PushGlobal(new ScriptObject());
var template = Template.Parse("{{ for i in 1..1000; s = 'x' * 100000 + math.uuid; array.cycle ['v'] s; end; '' }}");
for (var round = 0; round < 5; round++)
{
template.Render(ctx);
Console.WriteLine($"round={round} tags={ctx.Tags.Count}");
ctx.Reset();
Console.WriteLine($"afterReset tags={ctx.Tags.Count}");
}Observed:
MODE=tags round=0 tags=1000 peakWS=308MB
MODE=tags afterReset round=0 tags=1000 ws=311MB
MODE=tags round=4 tags=5000 peakWS=1210MB
MODE=tags afterReset round=4 tags=5000 ws=1210MB`Tags.Count` grows 1000 → 5000 and is unchanged by `Reset()`; peak working set reaches ~1.2 GB (~100 MB retained per render).
Impact
Unbounded memory retention and OOM in hosts that pool `TemplateContext` and call `Reset()`. Requires context reuse.
Remediation in Scriban 7.6.0
Upgrade either distribution, Scriban or Scriban.Signed, to 7.6.0 or later.
Per-render cycle and random state is now kept in a separate builtin-owned store that TemplateContext.Reset() clears. Host-owned Tags entries are preserved. Hosts pooling contexts must continue to call Reset() between independent uses. This report and GHSA-vhvh-mqjm-8vpg describe overlapping effects of the same state-retention defect.
No CVE identifier is requested for this advisory.
_Remediation notes and package metadata updated by CodeAlta._
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 | 0 d | 7.6.1 no afectada |
nugetScriban.Signed |
Corregida | 7.6.0 | 0 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-8637-5q5q-hxvwLas referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
