Skip to content

fix(python): make pybars4 an optional dependency under handlebars extra (#14802) - #14803

Open
MOHAMMED WASIM KHAN (wasim-builds) wants to merge 1 commit into
microsoft:mainfrom
wasim-builds:fix/issue-14802-pybars4-optional-handlebars
Open

MOHAMMED WASIM KHAN (wasim-builds) wants to merge 1 commit into
microsoft:mainfrom
wasim-builds:fix/issue-14802-pybars4-optional-handlebars

Conversation

@wasim-builds

Copy link
Copy Markdown
Contributor

Motivation and Context

Resolves #14802

The Python package declared pybars4 ~= 0.9 as a mandatory dependency in python/pyproject.toml.
However, all releases of pybars4 through 0.9.13 are affected by CVE-2026-119716 (untrusted template code injection in pybars/_compiler.py).

Applications using Semantic Kernel that do not use Handlebars prompt templates (e.g., standard semantic-kernel or Jinja2 templates) should not be forced to install or retain a vulnerable package with unpatched RCE risk.

Description

  • Moved pybars4 ~= 0.9 from [project.dependencies] to [project.optional-dependencies] under the handlebars extra.
  • Safely wrapped from pybars import Compiler, PybarsError in semantic_kernel/prompt_template/handlebars_prompt_template.py in a try/except block.
  • When pybars4 is not installed, instantiating HandlebarsPromptTemplate or invoking render raises an informative ImportError instructing the user to install semantic-kernel[handlebars].
  • Updated python/uv.lock accordingly.
  • Added unit tests in test_handlebars_prompt_template.py verifying that HandlebarsPromptTemplate raises ImportError with an actionable message when pybars is not installed.

Contribution Checklist

Copilot AI balanced review requested due to automatic review settings November 16, 2026 17:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: Bug: mandatory pybars4 dependency affected by CVE-2026-119716

2 participants