/

CVE-2026-33938

Severity:

HIGH RISK

(8.1)

Code Injection in Handlebars Server-Side Templates

CVE-2026-33938

Modified

Vulnerability type

Category:

Code Injection

CWE:

CWE-94, CWE-843, CWE-917

Impact:

Server-Side Remote Code Execution

Severity:

HIGH RISK

(8.1)

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 code injection flaw in Handlebars 4.0.0–4.7.8 allows helpers to overwrite the @partial-block special variable with a crafted Handlebars AST, which is later compiled and executed when {{> @partial-block}} is invoked.

In server-side rendering contexts where helpers can write arbitrary values into the data context and templates or context data are influenced by untrusted input, this can lead to arbitrary JavaScript execution on the server.

Affected context

This issue affects Node.js applications and other JavaScript environments that:

  • Use Handlebars versions 4.0.0 through 4.7.8
  • Render templates on the server (or in privileged runtimes) using the full Handlebars build with compile()
  • Employ helpers that accept and write arbitrary objects into the template data context
  • Utilize the @partial-block special variable and the {{> @partial-block}} syntax

The risk increases in deployments where templates, helper arguments, or context data can be influenced—directly or indirectly—by untrusted or semi-trusted user input.

Exploit preconditions

  • Attack surface: Server-side template rendering using Handlebars 4.0.0–4.7.8.
  • Required access: Ability to influence template content, helper arguments, or context data passed into helpers that can mutate the data context.
  • Trigger point: A helper overwrites @partial-block with a crafted Handlebars AST object, followed by a later template execution that invokes {{> @partial-block}}.
  • Why exploitation is possible: The @partial-block special variable is stored in the mutable data context. When overwritten with a Handlebars AST, the subsequent partial expansion compiles and executes that AST as code, rather than treating it as inert data.

Why this happens

The vulnerability stems from treating a control-structure reference (@partial-block) as a mutable data field within the template context.

In vulnerable versions, @partial-block is stored in the data context object that helpers can modify. Helpers that accept arbitrary objects may overwrite this field with attacker-controlled content representing a Handlebars abstract syntax tree (AST). When the template later executes {{> @partial-block}}, Handlebars falls back to compiling this AST and executing it.

This behavior maps to CWE-94: Improper Control of Generation of Code, because user-influenced data is allowed to become executable Handlebars code, and to CWE-843: Access of Resource Using Incompatible Type, because a value expected to be a specific internal type is replaced with a different, attacker-controlled object that is nonetheless processed as valid code.

Potential impact

  • Arbitrary JavaScript execution on the server-side rendering process
  • Reading, modifying, or exfiltrating sensitive data handled during template rendering
  • Pivoting to broader server compromise depending on runtime capabilities and sandboxing
  • Template defacement, logic manipulation, or data integrity violations in rendered views
  • Abuse of server-side resources (e.g., denial-of-service via expensive injected logic)

General mitigation guidance

Effective mitigation involves constraining both Handlebars capabilities and how helpers interact with the context:

  • Prefer the runtime-only Handlebars build (handlebars/runtime) in server-side environments, which omits compile() and removes the vulnerable compilation path.
  • Treat the template context as effectively immutable within helpers; avoid writing arbitrary values into context objects, especially for special variables such as @partial-block.
  • Limit or avoid using @partial-block in contexts where helpers can be influenced by untrusted input, or where helper behavior is not tightly controlled.
  • Strictly vet and minimize helper registrations; avoid helpers from untrusted or general-purpose third-party packages in high-risk contexts where templates or context data may be attacker-controlled.
  • Apply least-privilege principles to the templating environment (e.g., sandboxed execution, limited filesystem and network access) so that, even if code execution occurs, its impact is reduced.

How teams detect issues like this

Detection often combines code-level analysis with configuration review:

  • Use static analysis or pattern-based searches to identify:
  • Handlebars 4.0.0–4.7.8 usage in server-side code
  • Direct use of the full handlebars package with compile() in privileged contexts
  • Helpers that modify the template data context or write to special variables (e.g., referencing or assigning @partial-block or its underlying property)
  • During code review, scrutinize:
  • Custom helpers that accept arbitrary objects or pass-through user input
  • Any helper logic that treats context data as writable, especially when using this, options.data, or similar constructs
  • Registration of broad, third-party helper sets in areas processing untrusted data
  • Integrate automated dependency and configuration scanners in CI to flag:
  • Outdated Handlebars versions
  • Server-side templates using @partial-block combined with mutable context helpers

Sources

SourceLink
github.comgithub.com/handlebars-lang/handlebars.js/commit/68d8df5a88e0a26fe9e6084c5c6aaebe67b07da2
github.comgithub.com/handlebars-lang/handlebars.js/releases/tag/v4.7.9
github.comgithub.com/handlebars-lang/handlebars.js/security/advisories/GHSA-3mfm-83xf-c92r
access.redhat.comaccess.redhat.com/errata/RHSA-2026:10175
access.redhat.comaccess.redhat.com/errata/RHSA-2026:34342
access.redhat.comaccess.redhat.com/security/cve/CVE-2026-33938
bugzilla.redhat.combugzilla.redhat.com/show_bug.cgi?id=2452525
security.access.redhat.comsecurity.access.redhat.com/data/csaf/v2/vex/2026/cve-2026-33938.json

Frequently asked

questions

Yes, in many setups. If an attacker can influence template content, helper arguments, or context data consumed by helpers that write to the data context, they may be able to trigger this issue remotely via normal application entry points (e.g., HTTP requests).

An attacker needs sufficient influence over the data that flows into Handlebars helpers which can modify the context, or over the templates themselves. Direct server access is not required if the application exposes such helpers to user-controlled input.

Move server-side rendering to the runtime-only Handlebars build without compile(), upgrade to a fixed Handlebars version, and refactor helpers so they treat the context as read-only—never overwriting special variables like @partial-block.

Establish a design rule that data must never be transformed into executable code, especially in templating engines. Enforce read-only semantics for template contexts in helper implementations, tightly control which helpers are registered, and include dependency/version checks and secure templating patterns in your standard code review and CI policies.

Find out what's already
exploitable in your codebase.