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(python-sdk): prevent cross-tenant credential access in CustomTool [SEC-365] (#3302)
# Description Fixes the cross-tenant credential access vulnerability tracked in [SEC-365](https://linear.app/composio/issue/SEC-365/cross-tenant-credential-access) (CWE-639) reported against `python/composio/core/models/custom_tools.py`. ## What was wrong `CustomTool.__call__` extracted `user_id` directly from the same `**kwargs` dict that carries LLM-supplied tool arguments: ```python def __call__(self, **kwargs: t.Any) -> t.Any: user_id = kwargs.pop("user_id", None) or "default" # untrusted! request = self.request_model.model_validate(kwargs) ... auth_credentials=self.__get_auth_credentials(user_id), ``` Pydantic's `model_validate` ignores fields not declared in the schema, so an LLM (or prompt-injection input) could include `user_id` in its tool-call arguments and `__get_auth_credentials` would happily look up that other tenant's OAuth tokens. ## What changed - **`CustomTools.execute`** strips `user_id` from the LLM-supplied `request` dict at the trust boundary, so only the explicit, server-side `user_id` parameter reaches credential lookup. The original caller-owned dict is left untouched. - **`CustomTool`** now exposes a trusted internal entry point `_invoke(user_id, request_kwargs)` where `user_id` is passed structurally separate from the request kwargs dict (so an LLM-controlled key inside the dict can never be promoted to override the trusted value). - **`CustomTool.__call__`** no longer reads `user_id` from `**kwargs` at all and always uses the safe `"default"` user, with a docstring directing direct callers to `CustomTools.execute` for trusted multi-tenant use. # How did I test this PR Added `python/tests/test_custom_tools_security.py` with six regression tests: - `test_execute_strips_user_id_from_llm_request` — request dict containing `user_id="victim-user"` is stripped; lookup uses the trusted `user_id="trusted-user"`. - `test_execute_falls_back_to_default_when_user_id_missing` — when no trusted `user_id` is supplied, lookup uses `"default"` (NOT the LLM-supplied value). - `test_execute_does_not_mutate_caller_request_dict` — sanitization is non-destructive on the caller's dict. - `test_call_drops_user_id_smuggled_in_kwargs_dict` — `tool(**llm_dict)` with `user_id` smuggled inside falls back to `"default"`. - `test_invoke_uses_trusted_user_id_separate_from_request` — trusted internal entry point passes the explicit `user_id` through. - `test_execute_unknown_slug_raises` — sanity check, unknown slugs still surface `NotFoundError`. ```bash $ source .venv/bin/activate $ python -m pytest tests/test_custom_tools_security.py -v ============================== 6 passed in 0.04s =============================== ``` Full Python test suite (excluding type-inference-only sessions, which require all provider packages and run via `nox -s type_inference`): ```bash $ python -m pytest tests/ --ignore=tests/test_type_inference_* ============================== 639 passed, 1 warning in 5.09s ============================== ``` Lint + type-check on changed files: ```bash $ ruff check --config config/ruff.toml composio/core/models/custom_tools.py tests/test_custom_tools_security.py All checks passed! $ ruff format --config config/ruff.toml --check composio/core/models/custom_tools.py tests/test_custom_tools_security.py 2 files already formatted $ mypy --config-file config/mypy.ini composio/core/models/custom_tools.py tests/test_custom_tools_security.py Success: no issues found in 2 source files ``` Triggered by: srujan@composio.dev | Source: slack Session: https://zen-api-production-4c98.up.railway.app/dashboard/#/chat/zen-34868b976538
No changes.