GHSA-VQM7-RM7V-QQ3F
object.to_json ignores the string length limit and allows multi-gigabyte JSON allocation
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-VQM7-RM7V-QQ3F divulgada · CVSS 7.5 (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
`object.to_json` writes to an unbounded `MemoryStream`; only .NET's JSON length cap limits output.
Details
`ObjectFunctions.ToJson` (`src/Scriban/Functions/ObjectFunctions.cs:576-596`) and its `WriteValue` helper (`lines 598-680`) never check `context.LimitToString`. Repeated serialization re-escapes backslashes and control characters, amplifying a 1 MB input.
Suggested fix. Enforce the limit while writing. Use a `Stream` wrapper passed to `Utf8JsonWriter` that counts bytes and throws once the output cannot fit `LimitToString` (taking UTF-8/UTF-16 worst case into account), or check `stream.Length` after each `WriteValue` and before `GetString`:
// Conceptual: reject before the buffer grows past the configured limit.
private sealed class LimitStream : Stream
{
private readonly Stream _inner;
private readonly long _maxBytes;
public override void Write(ReadOnlySpan<byte> buffer)
{
if (_inner.Length + buffer.Length > _maxBytes)
throw new ScriptRuntimeException(span,
$"JSON output exceeds LimitToString `{limit}`.");
_inner.Write(buffer);
}
// ...
}Proof of concept
Default context, no host objects:
var ctx = new TemplateContext();
ctx.PushGlobal(new ScriptObject());
var template = """{{ s = '\n' * 1000000; for i in 1..9; s = s | object.to_json; end; s | string.size }}""";
Template.Parse(template).Render(ctx);Observed:
MODE=tojson OK resultChars=9 elapsedMs=2707 peakWS=3377MBThe result is `257000592` chars. A 10th pass throws the .NET JSON length error only after the same ~3.4 GB allocation.
Impact
An ~85-byte template causes a 3.4 GB heap peak and is repeatable; memory-exhaustion DoS.
Remediation in Scriban 7.6.0
Upgrade either distribution, Scriban or Scriban.Signed, to 7.6.0 or later.
object.to_json now checks LimitToString incrementally using the UTF-16 character length of the JSON output, including escape sequences. It bounds individual string and property-name inputs before reserving escape buffers and flushes tokens to a bounded stream. An over-limit operation throws rather than returning truncated, invalid JSON. ScriptObject serialization also follows the guarded traversal.
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-vqm7-rm7v-qq3fLas referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
