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(sdk): write server-provided file names portably instead of rejecting them (#4690)
This PR: - fixes ordinary file names rejected since https://github.com/ComposioHQ/composio/pull/4487 (TS `RemoteFile.save()` with no path) and https://github.com/ComposioHQ/composio/pull/4144 (Python automatic file downloads), e.g. `report_2026-09-29T10:30:00.csv`, `What is this?.png`, `invoice "final".pdf`, or a name over 128 bytes - changes `safeBasename` / `safe_basename` to make unportable names portable on every platform, with the same rules in the same order in both SDKs: - Windows-reserved and control characters become `_` - device names get a `_` prefix (`NUL.txt` → `_NUL.txt`) - names over 128 bytes are truncated by whole code points, keeping an extension of up to 32 bytes - trailing spaces and dots are dropped, as Windows would - a name any rule changed is tagged with a 64-bit FNV-1a digest of the original before its extension (`report?.png` → `report_-05fcb95aa5b918e9.png`), to distinguish ordinary normalization collisions; already-portable names are unchanged - prevents a literal server filename from spoofing a digest-tagged destination: Python automatic downloads and default session-file saves in both SDKs create files exclusively, then try a copy number before the extension if the destination already exists. This also preserves repeated and concurrent downloads, including long Unicode names within the 128-byte bound - still refuses a NUL byte, invalid Unicode, or no usable basename (`""`, `.`, `..`, `. .`); traversal is still reduced to the basename and the Python containment check is unchanged. Both helpers only ever receive server-provided names, so explicit caller paths are unaffected - makes Python automatic downloads follow redirects again through `safe_request`, which validates and pins every hop, matching the TS `ssrfSafeFetch`. https://github.com/ComposioHQ/composio/pull/4146 had turned them off, so a presigned URL answering 307 failed. URL uploads and session file URL fetches still refuse redirects on purpose - a failed Python auto-download raised `ErrorDownloadingFile` after the remote tool had already run, so the result was lost ## Verification - reproduced the literal-tag collision on the previous PR head; all six new Python collision regressions fail against that head and pass with this fix - tests cover both collision orders, concurrent default saves, repeated long Unicode names, and cleanup that preserves an existing file after a failed download - TypeScript: `RemoteFile.test.ts`, `safePath.test.ts`, `platform/node.test.ts`, and `ToolRouterSessionFilesMount.test.ts`: 153 passed; both core typechecks, oxlint, and Prettier passed - Python: `test_files.py`, `test_safe_path.py`, `test_tool_router_session_files.py`, and `test_path_join_guardrail.py`: 391 passed, 1 skipped; Ruff check/format passed; mypy passed for all three changed source files
No changes.