Scriban Stack Overflow via Nested Array Initializers
Scriban versions before 7.0.0 are vulnerable to a stack overflow exception due to deeply nested array initializers bypassing the ExpressionDepthLimit, leading to uncontrolled recursion and process termination when parsing templates with untrusted input, similar to GHSA-wgh7-7m3c-fx25.
Triage facts
Revision 2- Evidence
- Unknown
- Severity
- High
- Sources
- 1 public source
- Freshness
- Revision 2Jan 24, 12:00 UTC
- Detection
- 2 rules
Revision history 1 entry · Revision 2
- Revision 2
Repaired a legacy canonical identity collision
Changed: slug
Scriban, a .NET templating engine, is susceptible to a stack overflow vulnerability in versions prior to 7.0.0. This flaw arises from the insufficient protection against deeply nested array initializers within Scriban templates. Specifically, the fix implemented for GHSA-wgh7-7m3c-fx25, which introduced an ExpressionDepthLimit, does not effectively prevent recursion through the ParseArrayInitializer function when handling such nested structures. The vulnerability can be triggered by crafting malicious templates containing deeply nested array initializers (e.g., [[[[...). Exploitation leads to a StackOverflowException, abruptly terminating the process and potentially causing denial-of-service conditions in applications utilizing Scriban for template processing. The vulnerability impacts any application calling Template.Parse with untrusted input, even with the ExpressionDepthLimit enabled.
Attack Chain
- An attacker crafts a Scriban template containing deeply nested array initializers (e.g.,
{{[[[[[...1]]]]]}}). - The application utilizes the
Template.Parsemethod from the Scriban library to parse the attacker-controlled template. - During parsing, the
ParseArrayInitializerfunction is invoked to handle the array initializer. ParseArrayInitializerrecursively callsParseExpressionto evaluate the nested expressions within the array.ParseExpressioncallsParseArrayInitializeragain, creating a recursive loop.- This recursion continues without being limited by the
ExpressionDepthLimit, which is designed to prevent uncontrolled recursion in other parsing paths. - The excessive recursion consumes stack memory, eventually leading to a
StackOverflowException. - The
StackOverflowExceptioncannot be caught in .NET, resulting in immediate termination of the application process, causing a denial-of-service.
Impact
The stack overflow vulnerability in Scriban can lead to denial-of-service attacks. Successful exploitation results in immediate process termination of the application using the Scriban library to parse templates. This vulnerability impacts any application that utilizes Scriban to process potentially untrusted template input. Given the nature of a StackOverflowException, the impact is severe as it abruptly halts the affected service, which could affect availability and stability. This is especially critical in web applications or services that rely on template parsing for rendering content or processing user inputs.
Recommendation
- Upgrade to Scriban version 7.0.0 or later to address the vulnerability (reference: Affected Packages).
- Implement input validation and sanitization to prevent the parsing of templates from untrusted sources that may contain deeply nested array initializers (reference: Overview).
- Deploy the Sigma rule to detect attempts to exploit this vulnerability by monitoring for abnormally deep expression nesting during Scriban template parsing (reference: rules).
- Review and harden any existing Scriban template parsing implementations to ensure that they are not processing untrusted input directly (reference: Overview).
Detection coverage 2
Detect Scriban Stack Overflow Attempt via Nested Array Initializers
highDetects attempts to exploit the Scriban stack overflow vulnerability by identifying deeply nested array initializers in templates.
Detect Scriban Template Parsing with Excessive Recursion
mediumDetects potential stack overflow exploitation attempts by monitoring for unusual call stack depth within Scriban template parsing operations.
Detection queries are available on the platform. Get full rules →