CVE-2026-119716
Code injection in pybars3 templates via unescaped bracketed path segments.
- CVSS 9.2
- CWE-94
- Input Validation and Sanitization
- Remote
pybars3 through 0.9.7 contains a code injection vulnerability in pybars/_compiler.py that allows template authors to execute Python code via unescaped bracketed path segments. Attackers can supply Handlebars templates with crafted segments in helper or block arguments to break out of string literals and execute Python in the application process.
- CWE
- CWE-94
- CVSS base score
- 9.2
- Published
- 2026-10-30
- OWASP
- A03 Injection
- Orthogonal defect classification
- Checking
- Code defect classification
- Missing Check
- Category
- Input Validation and Sanitization
- Subcategory
- Command Injection
- Accessibility scope
- Remote
- Impact
- Arbitrary Code Execution
- Affected component
- pybars3
- Fixed by upgrading
- Yes
Solution
Upgrade pybars3 to version 1.0.0 (or later).
Vulnerable code sample
import re
class SimpleCompiler:
def __init__(self):
self._var_regex = re.compile(r'\[([^\]]+)\]') # matches [path]
def compile(self, template: str):
"""
Very small subset of pybars3 compilation: replace bracketed path segments
with Python variable lookups, then exec the generated code.
"""
code = "def render(context):\n return f'''"
# VULNERABLE: unescaped bracketed segment allows injection
def replacer(match):
expr = match.group(1) # user‑controlled expression
return f'{{{{ {expr} }}}}' # inserted directly into f‑string
code += self._var_regex.sub(replacer, template)
code += "'''"
namespace = {}
exec(code, {}, namespace)
return namespace['render']
# Example usage (vulnerable):
# tmpl = "Hello [__import__('os').system('echo exploited')]"
# render = SimpleCompiler().compile(tmpl)
# render({})Patched code sample
import re
import ast
class SimpleCompiler:
def __init__(self):
self._var_regex = re.compile(r'\[([^\]]+)\]') # matches [path]
def compile(self, template: str):
"""
Very small subset of pybars3 compilation: replace bracketed path segments
with Python variable lookups, then exec the generated code.
"""
code = "def render(context):\n return f'''"
# FIX: sanitize bracketed segment to prevent code injection
def replacer(match):
raw = match.group(1)
# Allow only simple attribute/lookup names, reject any code constructs
if not re.fullmatch(r'[A-Za-z_][A-Za-z0-9_\.]*', raw):
raise ValueError("Invalid template expression")
# Safely embed as a literal string lookup
return f'{{{{ {raw} }}}}'
code += self._var_regex.sub(replacer, template)
code += "'''"
namespace = {}
exec(code, {}, namespace)
return namespace['render']Cite this entry
@misc{vaitp:cve2026119716,
title = {{Code injection in pybars3 templates via unescaped bracketed path segments.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-119716},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-119716/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.
The supreme art of war is to subdue the enemy without fighting.
Sun Tzu – “The Art of War”
:: Shaping the future through research and ingenuity ::
