Summary
LiquidJS's template sandbox can be tricked into bypassing its memoryLimit mechanism using reverse range expressions, allowing templates to allocate unbounded memory.
When combined with string-flattening operations such as the replace filter, a single crafted template rendered from one HTTP request can trigger a V8 fatal error and crash the Node.js process, resulting in a complete denial of service.
Affected context
This vulnerability affects applications that:
- Use LiquidJS as a server-side template engine (for example, in Node.js web services).
- Allow users, tenants, or other external parties to influence or supply template content or template fragments.
- Rely on LiquidJS's
memoryLimitas a safety mechanism to constrain resource usage.
The issue is triggered when the template syntax permits reverse range expressions (like (100000000..1)) that are not correctly accounted for by the engine's memory-limiting logic, especially when combined with expensive string operations such as replace.
Exploit preconditions
- Attack surface: HTTP endpoints or APIs that cause LiquidJS to render templates.
- Required access: Ability to inject or control template content, template variables, or filters to introduce reverse ranges and heavy string operations.
- Trigger point: Rendering of a LiquidJS template containing a reverse range expression combined with a string-flattening operation (for example,
replace). - Why exploitation is possible: The
memoryLimitcontrol does not correctly account for reverse ranges, allowing the engine to allocate memory without effective bounds. When merged with costly string operations, this leads to excessive memory use, causing V8 to hit a fatal error and terminate the Node.js process.
Why this happens
The root cause is an incomplete resource-limiting mechanism in the LiquidJS engine that fails to cover all syntactic constructs, particularly reverse range expressions.
Instead of treating all forms of ranges consistently with respect to memory accounting, the implementation allows expressions like (100000000..1) to escape the intended memoryLimit.
This behavior corresponds to CWE-400: Uncontrolled Resource Consumption, where an attacker can drive the system to consume excessive memory, and CWE-20: Improper Input Validation, because the engine does not robustly validate or constrain user-controlled template constructs that can lead to unbounded resource use.
Conceptually, the bug class is: "relying on partial input validation and incomplete resource accounting for sandboxed, user-controllable template expressions."
Potential impact
- The Node.js process can crash due to a V8 fatal error triggered by excessive memory allocation.
- The application or service can become completely unavailable (denial of service) from a single crafted HTTP request.
- Automated restart mechanisms may enter crash loops, amplifying downtime or resource waste.
- Multi-tenant environments may experience cross-tenant impact if one tenant can submit malicious templates that affect shared application processes.
General mitigation guidance
Effective mitigation focuses on strengthening resource controls and tightening trust boundaries around templates:
- Treat all user-controlled template content as untrusted and restrict which Liquid constructs (e.g., ranges, loops, filters) are allowed in user-supplied templates.
- Apply robust resource-limiting strategies that cover all expressions and operations, including reverse ranges and nested filters, rather than relying on a single
memoryLimitknob. - Introduce execution guards such as maximum loop iterations, maximum collection sizes, and limits on filter chaining, especially for string-heavy operations.
- Enforce strict validation or whitelisting of template syntax before rendering, rejecting patterns that can cause unbounded memory usage.
- Run template rendering in isolated worker processes or sandboxes with strict memory and time quotas so that a crash or exhaustion does not take down the main service.
- Apply least-privilege to the rendering environment and ensure that the service architecture can degrade gracefully if a single worker fails.
How teams detect issues like this
Detection can combine code-level review with runtime monitoring:
- Static analysis & code review:
- Flag server endpoints that pass user-controlled strings directly into LiquidJS without validation or templating policy enforcement.
- Review uses of
memoryLimitwhere it is treated as a complete safety boundary, and identify missing checks for ranges, loops, and filter chains. - Establish guidelines for permitted Liquid constructs and use automated checks or linters to enforce them in stored templates.
- Runtime monitoring & observability:
- Track memory usage and process crashes for services that render LiquidJS templates, alerting on spikes tied to specific requests or tenants.
- Log rendered template content or templates IDs on errors so that suspicious patterns (e.g., huge ranges or deeply nested filters) can be identified.
- Testing & policy enforcement:
- Add regression tests that include large and reverse ranges combined with string operations to confirm that resource limits are honored.
- Use automated security testing or fuzzing against template endpoints to surface unbounded resource consumption patterns early in development.

