@devries-cameron20 / composio-1 / commits / 2428a9554
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

fix(security): prevent path traversal in Python SDK FileDownloadable.download() (SEC-316) (#3352)

# Description Fixes [SEC-316](https://linear.app/composio/issue/SEC-316/composio-path-traversal-in-composio-python-sdk-allows-arbitrary-file) — **HIGH severity (CVSS 8.2)** path traversal in the Composio Python SDK. `FileDownloadable.download()` in `python/composio/core/models/_files.py` constructed the output path as `outdir / self.name`, where `self.name` comes directly from the Composio API response. A compromised or man-in-the-middle'd API server can return a filename like `../../../../PWNED.sh` and write arbitrary files outside the configured cache directory on the user's machine — leading to potential code execution, configuration tampering, or data compromise. The TypeScript SDK is **not** vulnerable: `downloadFileFromS3` in `ts/packages/core/src/utils/fileUtils.node.ts` generates its own filename via `generateTimestampedFilename()` and `saveFile` strips path components with `platform.basename()` (line 428). ## What changed `FileDownloadable.download()`: - Strip directory components from `self.name` via `Path(...).name` so traversal sequences (`../`, absolute paths, `\` on POSIX) collapse to a basename. - As a second-line defense, verify the resolved output path is contained within `outdir` using `Path.is_relative_to()` (correct directory-containment semantics — naive `str.startswith()` would be vulnerable to sibling-prefix attacks like `outdir_evil/`). This mirrors the equivalent fix already landed in `mercury`'s legacy `FileDownloadable` (commits `e3915b82c3` + `c3d675dbcc` from PRs ComposioHQ/mercury#20641 and #20654). ## How did I test this PR - Added 4 unit tests in `TestFileDownloadablePathTraversal` covering: - **Relative traversal** (`../../../PWNED.sh`) — collapsed to basename, written inside `outdir`, file does NOT appear at the parent path. - **Absolute path** (`/etc/passwd`) — basename strip yields `passwd`, written inside `outdir`. - **Dotdot-only name** (`..`) — `Path('..').name == '..'` survives basename strip; the `is_relative_to()` check then rejects it with `ErrorDownloadingFile`. - **Safe filename** (`report.pdf`) — pass-through unchanged. - Ran `pytest tests/test_files.py -v` (110/110 passing — full file, no regressions). ``` $ python -m pytest tests/test_files.py::TestFileDownloadablePathTraversal -v tests/test_files.py::TestFileDownloadablePathTraversal::test_relative_traversal_is_neutralized PASSED tests/test_files.py::TestFileDownloadablePathTraversal::test_absolute_path_is_neutralized PASSED tests/test_files.py::TestFileDownloadablePathTraversal::test_dotdot_only_name_is_rejected PASSED tests/test_files.py::TestFileDownloadablePathTraversal::test_safe_filename_passes_through PASSED ========================= 4 passed in 0.18s ========================== ``` ## Reference - CWE-22: https://cwe.mitre.org/data/definitions/22.html - CVSS Vector: `CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:H/A:N` --- Triggered by: srujan@composio.dev | Source: slack Session: https://zen-api-production-4c98.up.railway.app/dashboard/#/chat/zen-3b30311d7b50

Alberto Schiabel committed May 6, 2026 at 14:14 UTC 2428a95549d6e54082d9bc37f498695ca517d02e

No changes.