Scriban Template Engine Remote Denial-of-Service via Uncontrolled Memory Allocation
The Scriban template engine is vulnerable to a denial-of-service attack due to missing validation in the `string.pad_left` and `string.pad_right` functions, allowing unauthenticated attackers to trigger excessive memory allocation and crash the service by sending a crafted HTTP request to a vulnerable endpoint that processes untrusted Scriban templates.
Triage facts
Revision 2- Evidence
- Unknown
- Severity
- High
- Sources
- 1 public source
- Freshness
- Revision 2Jan 23, 12:00 UTC
- Detection
- 1 rule
Revision history 1 entry · Revision 2
- Revision 2
Repaired a legacy canonical identity collision
Changed: slug
Scriban is a .NET template engine similar to Liquid. Versions prior to 7.0.0 are vulnerable to a denial-of-service attack. The string.pad_left and string.pad_right template functions in Scriban lack validation on the width parameter. This allows an attacker to control the size of a string allocation, leading to a potential OutOfMemoryException. The vulnerability is triggered when Scriban is used to render untrusted template input. A publicly accessible Scriban playground, Scriban.AppService, deployed on Azure is vulnerable, allowing an unauthenticated attacker to crash the service by sending a specially crafted HTTP request. A 39-byte payload is sufficient to trigger a ~1GB memory allocation, crashing the service. Rate limiting is present at 30 requests/minute but is insufficient to mitigate the attack as each request still triggers a large memory allocation.
Attack Chain
- An attacker crafts a malicious Scriban template containing either the
string.pad_leftorstring.pad_rightfunction with a largewidthvalue (e.g., 500000000). - The attacker sends an HTTP POST request to the
/api/renderendpoint of a vulnerable Scriban application such asScriban.AppService. - The POST request body contains a JSON payload with the "template" field set to the malicious Scriban template.
- The vulnerable application receives the request and extracts the template from the JSON payload.
- The application calls the
template.Render()function to process the Scriban template. - During template rendering, the
string.pad_leftorstring.pad_rightfunction is called with the attacker-controlledwidthvalue. - The application attempts to allocate a string of the specified
widthin memory. Due to the largewidthvalue, this allocation can be on the order of gigabytes. - If the allocation exceeds available memory, the .NET runtime throws an
OutOfMemoryException, crashing the application process and causing a denial of service.
Impact
This vulnerability allows an unauthenticated attacker to remotely crash any application that renders untrusted Scriban templates. In the specific case of the official Scriban playground (scriban-a7bhepbxcrbkctgf.canadacentral-01.azurewebsites.net), a single HTTP request can trigger an OutOfMemoryException and crash the service. Sustained requests at the rate limit (30/min) can create continuous memory pressure (~30GB/min), preventing the service from recovering. Successful exploitation leads to a denial of service, rendering the application unavailable to legitimate users.
Recommendation
- Apply the vendor-supplied patch to upgrade Scriban to version 7.0.0 or later, which includes validation on the
widthparameter forStringFunctions.PadLeftandStringFunctions.PadRightto prevent excessive memory allocation. - For web applications using Scriban, implement input validation on the template data received from users to prevent injection of arbitrary
pad_leftandpad_rightcalls. - Monitor web server logs (category:
webserver, product:linux) for suspicious POST requests to the/api/renderendpoint with unusually large values in thetemplateparameter, as indicated by the rule "Detect Scriban PadLeft/PadRight DoS Attempt". - Deploy the Sigma rule "Detect Scriban PadLeft/PadRight DoS Attempt" to identify attempts to exploit this vulnerability in real-time.
- Consider implementing resource limits (e.g., memory limits) on the Scriban rendering process to prevent a single malicious request from consuming excessive resources.
Detection coverage 1
Detect Scriban PadLeft/PadRight DoS Attempt
highDetects attempts to exploit the Scriban `pad_left` or `pad_right` denial-of-service vulnerability by identifying HTTP requests with large width parameters.
Detection queries are available on the platform. Get full rules →