mirror of
https://github.com/ComposioHQ/composio.git
synced 2026-09-22 11:46:35 +08:00
27ed0c9bd6
## Summary Security-hardening for automatic file upload in `@composio/core` (patch release per changeset). ### Changes - **Default denylist** for local paths before auto-upload / `files.upload`: blocks common credential directories (e.g. `.ssh`, `.aws`) and credential-like filenames (e.g. `.env`, default SSH private keys). Resolves symlinks when the path exists. - **Config:** `sensitiveFileUploadProtection`, `fileUploadPathDenySegments` on `Composio`. - **`beforeFileUpload`** hook (e.g. with `composio.tools.get` / `tools.execute`): rewrite path, return `false` to abort, or throw. - **Errors:** `ComposioSensitiveFilePathBlockedError`, `ComposioFileUploadAbortedError`; file modifier errors exported from `@composio/core` errors entry. - **Changeset:** patch bump for `@composio/core`. ### Notes - URLs and `File` blobs are not subject to the path denylist (unchanged). - Opt out of path checks only if required: `sensitiveFileUploadProtection: false`. ### Tests - `pnpm test` in `ts/packages/core` (799 tests) passed locally before commit. Made with [Cursor](https://cursor.com)
107 lines
2.3 KiB
Python
107 lines
2.3 KiB
Python
import os
|
|
|
|
from composio import (
|
|
Composio,
|
|
after_execute,
|
|
before_execute,
|
|
before_file_upload,
|
|
schema_modifier,
|
|
)
|
|
from composio.types import Tool, ToolExecuteParams, ToolExecutionResponse
|
|
|
|
composio = Composio()
|
|
|
|
|
|
@before_execute(tools=["HACKERNEWS_GET_USER"])
|
|
def before_execute_modifier(
|
|
tool: str,
|
|
toolkit: str,
|
|
params: ToolExecuteParams,
|
|
) -> ToolExecuteParams:
|
|
# Perform modifications on the request
|
|
print("before_execute_modifier", tool, toolkit)
|
|
return params
|
|
|
|
|
|
@before_file_upload(tools=["HACKERNEWS_GET_USER"])
|
|
def rewrite_upload_path(path: str, tool: str, toolkit: str) -> str:
|
|
"""Optional: same pattern as before_execute; use for per-tool file path policy."""
|
|
return path
|
|
|
|
|
|
@after_execute(tools=["HACKERNEWS_GET_USER"])
|
|
def after_execute_modifier(
|
|
tool: str,
|
|
toolkit: str,
|
|
response: ToolExecutionResponse,
|
|
) -> ToolExecutionResponse:
|
|
return {
|
|
**response,
|
|
"data": {
|
|
"karama": response["data"]["karama"],
|
|
},
|
|
}
|
|
|
|
|
|
# execute tool
|
|
response = composio.tools.execute(
|
|
user_id="default",
|
|
slug="HACKERNEWS_GET_USER",
|
|
arguments={"username": "pg"},
|
|
modifiers=[
|
|
before_execute_modifier,
|
|
rewrite_upload_path,
|
|
after_execute_modifier,
|
|
],
|
|
)
|
|
print(response)
|
|
|
|
|
|
@schema_modifier(tools=["HACKERNEWS_GET_USER"])
|
|
def modify_schema(
|
|
tool: str,
|
|
toolkit: str,
|
|
schema: Tool,
|
|
) -> Tool:
|
|
# Perform modifications on the schema
|
|
print("modify_schema", tool, toolkit)
|
|
return schema
|
|
|
|
|
|
tools = composio.tools.get(
|
|
user_id="default",
|
|
slug="HACKERNEWS_GET_USER",
|
|
modifiers=[modify_schema],
|
|
)
|
|
print(tools)
|
|
|
|
|
|
@before_execute(toolkits=["NOTION"])
|
|
def add_custom_auth(
|
|
tool: str,
|
|
toolkit: str,
|
|
params: ToolExecuteParams,
|
|
) -> ToolExecuteParams:
|
|
if params["custom_auth_params"] is None:
|
|
params["custom_auth_params"] = {"parameters": []}
|
|
|
|
params["custom_auth_params"]["parameters"].append( # type: ignore
|
|
{
|
|
"name": "x-api-key",
|
|
"value": os.getenv("NOTION_API_KEY"),
|
|
"in": "header",
|
|
}
|
|
)
|
|
return params
|
|
|
|
|
|
result = composio.tools.execute(
|
|
user_id="default",
|
|
slug="NOTION_GET_DATABASES",
|
|
arguments={},
|
|
modifiers=[
|
|
add_custom_auth,
|
|
],
|
|
)
|
|
print(result)
|