/

CVE-2026-119717

Severity:

HIGH RISK

(8.1)

Code Injection (CWE-94) in pybars4 Handlebars Templates

CVE-2026-119717

Deferred

Vulnerability type

Category:

Code Injection

CWE:

CWE-94

Impact:

Arbitrary 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 vulnerability in pybars4 allows crafted Handlebars template expressions to alter generated Python code during compilation. If an attacker can control or influence a template containing specially formed bracketed path segments, they may execute arbitrary Python code in the application's process.

A code injection vulnerability in pybars4 allows crafted Handlebars template expressions to alter generated Python code during compilation. If an attacker can control or influence a template containing specially formed bracketed path segments, they may execute arbitrary Python code in the application's process.

Affected context

The vulnerability occurs in applications that use pybars4 to compile attacker-influenced Handlebars templates, particularly when helper or block arguments contain bracketed path segments. Risk depends on whether untrusted users can submit templates or modify template content that is later compiled within a privileged application process.

The vulnerability occurs in applications that use pybars4 to compile attacker-influenced Handlebars templates, particularly when helper or block arguments contain bracketed path segments. Risk depends on whether untrusted users can submit templates or modify template content that is later compiled within a privileged application process.

Exploit preconditions

  • Attack surface: Handlebars template compilation through pybars4
  • Required access: Ability to provide or modify a template, or otherwise control relevant template arguments
  • Trigger point: Compilation of a crafted helper or block argument
  • Why exploitation is possible: Unescaped bracketed path segments can break out of a generated Python string literal and alter the compiled code
  • Attack surface: Handlebars template compilation through pybars4
  • Required access: Ability to provide or modify a template, or otherwise control relevant template arguments
  • Trigger point: Compilation of a crafted helper or block argument
  • Why exploitation is possible: Unescaped bracketed path segments can break out of a generated Python string literal and alter the compiled code

Why this happens

The underlying bug is insufficient escaping and context-aware encoding of template path segments before they are inserted into generated Python source code. This allows data intended to remain a literal value to affect the structure of the generated program, matching CWE-94: Improper Control of Generation of Code, commonly referred to as code injection.

The underlying bug is insufficient escaping and context-aware encoding of template path segments before they are inserted into generated Python source code. This allows data intended to remain a literal value to affect the structure of the generated program, matching CWE-94: Improper Control of Generation of Code, commonly referred to as code injection.

Potential impact

  • An attacker may execute arbitrary Python code in the application process.
  • Sensitive application data, credentials, or environment variables could be exposed.
  • Application integrity could be compromised through unauthorized file or data changes.
  • The vulnerable process could be used to access connected services or internal resources.
  • An attacker may execute arbitrary Python code in the application process.
  • Sensitive application data, credentials, or environment variables could be exposed.
  • Application integrity could be compromised through unauthorized file or data changes.
  • The vulnerable process could be used to access connected services or internal resources.

General mitigation guidance

Mitigation generally focuses on preventing untrusted template content from reaching code-generation paths and ensuring generated source remains structurally isolated from input.

Common defensive patterns include:

  • Treating templates as trusted application code rather than user-provided data.
  • Applying context-appropriate escaping and strict allowlisting to path segments and helper arguments.
  • Using rendering approaches that do not generate executable source code from untrusted values.
  • Separating template compilation from sensitive application privileges and runtime credentials.
  • Running template-processing components with least privilege and restricting filesystem and network access.
  • Validating templates before compilation while recognizing that validation alone should not replace safe code-generation boundaries.

Mitigation generally focuses on preventing untrusted template content from reaching code-generation paths and ensuring generated source remains structurally isolated from input.

Common defensive patterns include:

  • Treating templates as trusted application code rather than user-provided data.
  • Applying context-appropriate escaping and strict allowlisting to path segments and helper arguments.
  • Using rendering approaches that do not generate executable source code from untrusted values.
  • Separating template compilation from sensitive application privileges and runtime credentials.
  • Running template-processing components with least privilege and restricting filesystem and network access.
  • Validating templates before compilation while recognizing that validation alone should not replace safe code-generation boundaries.

How teams detect issues like this

Detection can include static analysis for string concatenation or interpolation of template-derived values into generated Python source, especially around compiler and resolver logic. Code reviews should examine escaping at every code-generation boundary, handling of bracketed path syntax, and whether untrusted templates can reach compilation. Organizations can also enforce policies that prohibit user-controlled templates in privileged processes and use automated security review tools to flag dynamic code-generation patterns.

Detection can include static analysis for string concatenation or interpolation of template-derived values into generated Python source, especially around compiler and resolver logic. Code reviews should examine escaping at every code-generation boundary, handling of bracketed path syntax, and whether untrusted templates can reach compilation. Organizations can also enforce policies that prohibit user-controlled templates in privileged processes and use automated security review tools to flag dynamic code-generation patterns.

Sources

SourceLink
github.comgithub.com/up9inc/pybars4
github.comgithub.com/up9inc/pybars4/blob/0.9.13/pybars/_compiler.py#L153-L154
github.comgithub.com/vladko312/advisories/blob/702e98db9642ece70d9e2150076d8014ffec2db3/pybars3.md
vulncheck.comvulncheck.com/advisories/pybars4-through-0.9.13-code-injection-via-bracketed-path-segments

Frequently asked

questions

It can be remotely exploitable when an application accepts attacker-controlled Handlebars templates or exposes template authoring functionality. Applications using only fixed, trusted templates have a narrower exposure.

The attacker generally needs the ability to submit, modify, or otherwise influence a template that pybars4 compiles. The exact access requirement depends on the application's template storage and authorization model.

Keep untrusted input out of code-generation paths, use context-aware escaping, and prefer rendering designs that do not turn template-derived data into executable Python source.

Treat templates as code, enforce strong trust boundaries, review compiler changes for generated-code injection risks, apply least privilege to rendering processes, and add security tests for special-character and delimiter handling.

It can be remotely exploitable when an application accepts attacker-controlled Handlebars templates or exposes template authoring functionality. Applications using only fixed, trusted templates have a narrower exposure.

The attacker generally needs the ability to submit, modify, or otherwise influence a template that pybars4 compiles. The exact access requirement depends on the application's template storage and authorization model.

Keep untrusted input out of code-generation paths, use context-aware escaping, and prefer rendering designs that do not turn template-derived data into executable Python source.

Treat templates as code, enforce strong trust boundaries, review compiler changes for generated-code injection risks, apply least privilege to rendering processes, and add security tests for special-character and delimiter handling.

Find out what's already
exploitable in your codebase.