/

CVE-2026-33287

Severity:

HIGH RISK

(7.5)

Resource Exhaustion / Denial of Service in LiquidJS

CVE-2026-33287

Analyzed

Vulnerability type

Category:

Resource Exhaustion / Denial of Service

CWE:

CWE-20, CWE-400

Impact:

Denial of Service through uncontrolled memory consumption during template rendering

Severity:

HIGH RISK

(7.5)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

A resource exhaustion vulnerability in LiquidJS's replace_first filter allows attackers to amplify output size far beyond the configured memoryLimit by abusing JavaScript's String.prototype.replace() back references.

By crafting templates that generate exponential string growth while appearing to stay within memory budgets, an attacker can trigger out-of-memory conditions and cause denial-of-service in applications using LiquidJS for template rendering.

Affected context

This issue affects applications that:

  • Use LiquidJS as a template engine in Node.js or browser-based environments
  • Enable or rely on the replace_first filter within user-controlled or partially user-controlled templates
  • Enforce rendering limits using memoryLimit as a safety mechanism

The vulnerability becomes relevant when templates can be influenced by untrusted input (e.g., user-generated pages, theme customizations, or CMS-driven content) and are rendered on shared or constrained infrastructure where memory exhaustion can impact service availability.

Exploit preconditions

  • Attack surface: Template rendering layer where LiquidJS processes templates.
  • Required access: Ability to provide or influence LiquidJS templates or filter arguments (e.g., via user-editable content, themes, or template variables).
  • Trigger point: Execution of the replace_first filter on an attacker-controlled string that causes String.prototype.replace() to emit output much larger than the input by using $& back references or similar constructs.
  • Why exploitation is possible: The memoryLimit accounting logic only considers the input string length, not the size of the expanded output produced by replace_first. This mismatch allows an attacker to stay within the configured memoryLimit while causing exponential output growth and consuming excessive memory.

Why this happens

The underlying issue is incorrect resource accounting combined with an API that can expand output non-linearly relative to its input.

LiquidJS's replace_first filter internally uses String.prototype.replace(), which treats $& as a back reference to the full match and can therefore replicate matched content multiple times, leading to amplification.

The implementation only charges memory usage based on the original input string length and does not account for the actual size of the generated output.

This maps to CWE-400: Uncontrolled Resource Consumption, with a contributing factor of CWE-20: Improper Input Validation, because user-controlled template content is not constrained in a way that prevents pathological memory amplification behavior.

Potential impact

  • Application process may consume excessive memory and be terminated by the runtime or container orchestrator.
  • Rendering requests can hang or fail, leading to partial or full denial-of-service for affected endpoints.
  • Shared infrastructure may experience reduced capacity or cascading failures if multiple services compete for exhausted memory.
  • Watchdog mechanisms or health checks might restart processes frequently, degrading system stability and performance.

General mitigation guidance

Effective mitigation focuses on correcting resource accounting and reducing the potential for unbounded output expansion during template rendering.

Recommended defensive patterns include:

  • Accounting for the actual length of rendered output when enforcing memoryLimit or similar quotas, including intermediate strings produced by filters.
  • Introducing stricter limits on template complexity, maximum expansion depth, and output size, independent of input length.
  • Restricting or sanitizing filter usage on untrusted input, especially filters that can cause string amplification (e.g., replace-like operations, loops, and concatenations).
  • Applying defense-in-depth controls at the platform level: per-request timeouts, process-level memory limits, and isolation (e.g., separate workers) for template rendering.
  • Designing template execution policies that distinguish between trusted templates (e.g., shipped with the application) and untrusted or user-generated templates, applying stricter safeguards to the latter.

How teams detect issues like this

Detection typically combines code analysis with runtime monitoring:

  • Static analysis / code review:
  • Look for template filters or helpers that call String.prototype.replace() or similar APIs without accounting for potential output amplification.
  • Flag resource-limiting logic that bases limits only on input sizes instead of actual output size or overall memory usage.
  • Review template engine wrappers for missing safeguards around user-supplied templates or filter arguments.
  • Runtime monitoring:
  • Track memory usage patterns during template rendering and alert on abnormal spikes correlated with specific templates or user inputs.
  • Log and analyze requests that trigger unusually long render times or cause worker restarts due to out-of-memory conditions.
  • Policy enforcement:
  • Use automated security checks in CI/CD to enforce output-size caps and complexity limits in template engines.
  • Integrate SAST or linting tools that know about dangerous template filter patterns or unchecked resource limits to prevent similar issues at review time.

Sources

SourceLink
github.comgithub.com/harttle/liquidjs/commit/35d523026345d80458df24c72e653db78b5d061d
github.comgithub.com/harttle/liquidjs/security/advisories/GHSA-6q5m-63h6-5x4v

Frequently asked

questions

Yes, if templates or their filter arguments can be influenced via remote inputs (such as user-generated content or theme customization fields). In such cases, remote users can craft content that triggers memory amplification during rendering.

An attacker typically needs the ability to supply or modify templates, or to control values passed into the replace_first filter. This may be available to regular users in systems that expose template editing, content blocks, or similar functionality.

The most robust fix is to update the resource accounting logic so that memoryLimit reflects actual rendered output size (and intermediate steps) rather than just input lengths, and to bound the expansion potential of filters like replace_first. Additionally, ensure that any string manipulation filter cannot grow output unboundedly without being charged against memory limits.

When designing template engines or similar processing pipelines, treat output size, not just input size, as a first-class resource. Introduce conservative limits on rendered output, depth of expansion, and filter usage; validate and constrain untrusted template content; and add monitoring and safeguards so pathological templates cannot degrade system availability.

Find out what's already
exploitable in your codebase.