NewApp Monitoring is liveSign up free
AgentbeamBeta
AI agent vulnerability · Haystack

CVE-2024-41950: Insecure Jinja2 templates rendered in Haystack Components can lead to RCE

highCVSS 4.0 7.7 · 3.1 7.5GHSA-hx9v-6r9f-w677

Haystack (`haystack-ai`) before 2.3.1 renders Jinja2 templates in several components without restriction. Anyone who can create and run a pipeline, or supply the template, can execute arbitrary Python on the machine that runs it. Upgrade to haystack-ai 2.3.1, or stop untrusted users from using the affected components.

Published Jul 31, 2024 · Analysis Nov 1, 2026

What an attacker can do

Several Haystack components take a Jinja2 template string and render it on the host. A template is code: with an unrestricted Jinja environment it can reach Python objects and call functions. If a user controls the template, the user controls what runs.

The risk is for applications that let users build or edit pipelines from scratch, such as a pipeline builder UI or an API that accepts pipeline YAML. The attacker needs an account that may create and run a pipeline, which matches the low-privileges CVSS vector. High attack complexity reflects that the app must expose this ability. The result is code execution as the Haystack process, with access to its environment variables, model and vector store keys, files and network. Applications that fix their templates in code and never take them from users are not exposed by this route.

Who is affected

Affected: haystack-ai < 2.3.1. The release notes name the components: PromptBuilder, ChatPromptBuilder, DynamicPromptBuilder, DynamicChatPromptBuilder, OutputAdapter and ConditionalRouter. The PipelineTemplate class had the same problem. Exposure needs a path for untrusted input to reach a template.

pip show haystack-ai

haystack-ai

Ecosystem
PyPI
Affected
< 2.3.1
Fixed in
2.3.1
Check
pip show haystack-ai

How to fix it

Upgrade to haystack-ai 2.3.1, which contains pull requests 8095 and 8096.

pip install --upgrade "haystack-ai>=2.3.1"

Upgrade note from the release: OutputAdapter and ConditionalRouter can now only return Python literal types (strings, bytes, numbers, tuples, lists, dicts, sets, booleans, None, Ellipsis). Types such as ChatMessage, Document and Answer are no longer allowed as output types, so check pipelines that used them.

Workaround from the advisory: prevent users from running the affected components, or let them use only preselected templates.

How to tell if you were hit

Inventory every place user input can become a template or a pipeline definition: pipeline YAML uploads, builder endpoints and init_parameters for the components listed above. Look in application logs for pipeline definitions containing Jinja constructs that reach Python internals, such as __class__, __globals__, __subclasses__, import or os.system. Unexpected child processes or outbound connections from the Haystack service are signs of exploitation.

Original advisory

From the GitHub Advisory Database (CC BY 4.0).

Impact

Haystack clients that let their users create and run Pipelines from scratch are vulnerable to remote code executions.

Certain Components in Haystack use Jinja2 templates, if anyone can create and render that template on the client machine they run any code.

Patches

The problem has been fixed with PRs deepset-ai/haystack#8095 and deepset-ai/haystack#8096.

Both have been released with Haystack 2.3.1.

Workarounds

Prevent users from running the affected Components, or only let users use preselected templates.

References

The list of impacted Components can be found in the release notes for 2.3.1. https://github.com/deepset-ai/haystack/releases/tag/v2.3.1

Questions

Is every Haystack application affected by CVE-2024-41950?

No. The advisory concerns clients that let users create and run pipelines from scratch. If your templates are fixed in code and users only supply variables, there is no template injection path.

Which version fixes it?

haystack-ai 2.3.1. Both fixes, pull requests 8095 and 8096, shipped in that release.

Will upgrading break my pipelines?

It can. OutputAdapter and ConditionalRouter now return only Python literal types, so output types like ChatMessage or Document stop working.

References

How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. The analysis is written by an AI model from the sources listed above and checked by automated rules before it is published. Check versions against the vendor's advisory before you act. Methodology