Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 21, 22:15 UTC
fix(security): apply SEC-316 defense-in-depth to RemoteFile.save()
`RemoteFile.save()` in `tool_router_session_files.py` shares the same trust-boundary shape as the `FileDownloadable.download()` path traversal fixed in SEC-316: the default save location is built as `~/.composio/files/<self.filename>`, where `self.filename` is `Path(mount_relative_path).name` derived from the (potentially compromised or MITM'd) tool-router API response. Today the basename strip alone makes this safe-by-OS-error — a server returning `mount_relative_path == ".."` produces `filename == ".."`, which collapses the resolved path to `~/.composio/` and `write_bytes()` fails with `IsADirectoryError`. That's a non-security bug surface, but it leaks intent through a confusing error and relies on a happy accident of `Path` semantics. Mirror the SEC-316 pattern: after building the default `save_path`, verify `save_path.resolve().is_relative_to(default_dir.resolve())` and raise `ValidationError` on mismatch. The check only runs on the default-location branch — a caller-supplied `path` is fully trusted and writes wherever the SDK user chooses. Adds `test_save_default_location_rejects_dotdot_filename` covering the `mount_relative_path="foo/.."` case (where `Path("foo/..").name == ".."`) and asserting nothing is written under the cache dir.