GHSA-JHV7-5X5P-VH8W
ScriptObject string conversion bypasses the string length limit and can allocate multi-gigabyte strings
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-JHV7-5X5P-VH8W 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
Rendering a `ScriptObject` with many members bypasses `LimitToString` during `IFormattable` conversion.
Details
`TemplateContext.ObjectToString` dispatches `IFormattable` to `ToString` (`src/Scriban/TemplateContext.Helpers.cs:187-191`). `ScriptObject` implements `IFormattable` (`ScriptObject.cs:29`) and its `ToString` (`ScriptObject.cs:362-402`) concatenates members without cumulative length tracking; the outer check (`TemplateContext.Helpers.cs:125-132`) runs only after the allocation and appends `...` instead of truncating.
Enforce the limit while building in `ScriptObject.ToString` (and any other `IFormattable` implementation that formats an object graph), not only after the fact. For example, before each append:
var itemText = context.ObjectToString(item.Value, true) ?? string.Empty;
if (context.LimitToString > 0 &&
(long)result.Length + itemText.Length + 4 > context.LimitToString)
{
if (context.OnStringLimit == ScriptLimitBehavior.Throw)
throw new ScriptRuntimeException(context.CurrentSpan,
$"String conversion reaches LimitToString `{context.LimitToString}`.");
var remaining = Math.Max(0, context.LimitToString - result.Length - 4);
result.Append(itemText.AsSpan(0, Math.Min(itemText.Length, remaining)));
result.Append("...");
break;
}
result.Append(itemText);Also change the outer fallback at `TemplateContext.Helpers.cs:131` to truncate the result (or throw) rather than returning `result + "..."` for an already oversized string.
A simpler immediate fix is to check `stream.Length` at the start of each `WriteValue`/after each member append and throw once it exceeds `LimitToString * 4` bytes, then verify the decoded string length before returning. The exact byte/char conversion should be documented because `LimitToString` is measured in UTF-16 characters.
Proof of concept
Default context, no host objects:
var ctx = new TemplateContext();
ctx.PushGlobal(new ScriptObject());
var members = string.Join(",", Enumerable.Range(0, 300).Select(i => $"k{i}:s"));
var template = "{{ s = 'a' * 1000000; o = {" + members + "}; o }}";
Template.Parse(template).Render(ctx);Observed:
MODE=scriptobject OK resultChars=1048579 elapsedMs=1239 peakWS=2030MBThe output is truncated to 1,048,579 chars, but ~300 MB was already built inside `ScriptObject.ToString` before the outer check ran.
Impact
Memory exhaustion/OOM from a ~2 KB template; `OnStringLimit = Throw` is also too late.
Remediation in Scriban 7.6.0
Upgrade either distribution, Scriban or Scriban.Signed, to 7.6.0 or later.
ScriptObject and enumerable string formatting now share the remaining conversion budget with nested values, check each append, and stop visiting members when the budget is exhausted. ObjectToString clips over-limit results before appending its compatibility ellipsis. OnStringLimit.Throw reports a ScriptRuntimeException; the default truncation policy is preserved.
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-jhv7-5x5p-vh8wLas referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
