@devries-cameron20 / composio-1 / commits / 43545ec88
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(python): block sensitive paths hidden by symlinks

jkomyno committed Aug 25, 2026 at 20:49 UTC 43545ec8891c19eb2bee8345b53b3f96f45c70b9
2 files changed +77 -25
python/composio/utils/sensitive_file_upload_paths.py
+34 -25
@@ -25,19 +25,26 @@ _DEFAULT_PRIVATE_KEY_BASENAME = re.compile(
25 )
26
27
28 -def _normalize_path_segments(file_path: t.Union[str, Path]) -> t.List[str]:
29 - p = Path(file_path).expanduser()
30 - try:
31 - resolved = p.resolve()
32 - except OSError:
33 - resolved = p
34 - parts = [part for part in resolved.as_posix().split("/") if part]
28 +def _path_segments(path: Path) -> list[str]:
29 + parts = [part for part in path.as_posix().split("/") if part]
30 if parts and parts[0].endswith(":"):
31 # Windows path: "C:/Users/..." -> drop drive letter segment
37 - parts = parts[1:]
32 + return parts[1:]
33 return parts
34
35
36 +def _normalize_path_segments(
37 + file_path: str | Path,
38 +) -> tuple[list[str], list[str]]:
39 + """Return resolved and written segments so neither can hide a denied name."""
40 + written = Path(file_path).expanduser().absolute()
41 + try:
42 + resolved = written.resolve()
43 + except OSError:
44 + resolved = written
45 + return _path_segments(resolved), _path_segments(written)
46 +
47 +
48 def _get_block_reason(
49 file_path: t.Union[str, Path],
50 additional_deny_segments: t.Optional[t.Sequence[str]] = None,
@@ -46,23 +53,25 @@ def _get_block_reason(
53 deny: t.Set[str] = {s.lower() for s in BUILTIN_FILE_UPLOAD_PATH_DENY_SEGMENTS}
54 deny.update(s.lower() for s in extra)
55
49 - segments = _normalize_path_segments(file_path)
50 - # Case-insensitive segment match: lower each path component once per check.
51 - for seg, key in zip(segments, (s.lower() for s in segments), strict=True):
52 - if key in deny:
53 - return f'path segment "{seg}" is in the sensitive file upload denylist'
54 -
55 - if not segments:
56 - return None
57 - basename = segments[-1]
58 - if _SECRET_LIKE_BASENAME.search(basename) or _DEFAULT_PRIVATE_KEY_BASENAME.match(
59 - basename
60 - ):
61 - return (
62 - f'file name "{basename}" looks like a credential, env, or private key file'
63 - )
64 - if basename.lower() == "credentials":
65 - return 'file name "credentials" is often used for cloud/API credential stores'
56 + resolved_segments, written_segments = _normalize_path_segments(file_path)
57 + for segments in (resolved_segments, written_segments):
58 + # Case-insensitive segment match: lower each path component once per check.
59 + for seg, key in zip(segments, (s.lower() for s in segments), strict=True):
60 + if key in deny:
61 + return f'path segment "{seg}" is in the sensitive file upload denylist'
62 +
63 + for segments in (resolved_segments, written_segments):
64 + if not segments:
65 + continue
66 + basename = segments[-1]
67 + if _SECRET_LIKE_BASENAME.search(
68 + basename
69 + ) or _DEFAULT_PRIVATE_KEY_BASENAME.match(basename):
70 + return f'file name "{basename}" looks like a credential, env, or private key file'
71 + if basename.lower() == "credentials":
72 + return (
73 + 'file name "credentials" is often used for cloud/API credential stores'
74 + )
75 return None
76
77
python/tests/test_sensitive_file_upload_paths.py
+43
@@ -73,6 +73,49 @@ def test_blocks_after_symlink_resolves_to_sensitive_dir() -> None:
73 assert is_blocked_sensitive_file_upload_path(link) is True
74
75
76 +def test_blocks_sensitive_symlinked_directory_with_plain_target(tmp_path: Path) -> None:
77 + store = tmp_path / "state" / "claude"
78 + store.mkdir(parents=True)
79 + (store / "settings.json").write_text("{}", encoding="utf-8")
80 + home = tmp_path / "home"
81 + home.mkdir()
82 + link = home / ".claude"
83 + try:
84 + link.symlink_to(store, target_is_directory=True)
85 + except OSError:
86 + pytest.skip("symlinks not supported")
87 +
88 + sensitive_path = link / "settings.json"
89 + assert is_blocked_sensitive_file_upload_path(sensitive_path) is True
90 + with pytest.raises(SensitiveFilePathBlockedError):
91 + assert_safe_local_file_upload_path(sensitive_path)
92 +
93 +
94 +def test_blocks_sensitive_symlinked_basename_with_plain_target(tmp_path: Path) -> None:
95 + target = tmp_path / "plain-config"
96 + target.write_text("SECRET=1", encoding="utf-8")
97 + link = tmp_path / ".env"
98 + try:
99 + link.symlink_to(target)
100 + except OSError:
101 + pytest.skip("symlinks not supported")
102 +
103 + assert is_blocked_sensitive_file_upload_path(link) is True
104 +
105 +
106 +def test_allows_ordinary_file_through_symlinked_directory(tmp_path: Path) -> None:
107 + store = tmp_path / "store"
108 + store.mkdir()
109 + (store / "document.pdf").write_text("x", encoding="utf-8")
110 + link = tmp_path / "docs"
111 + try:
112 + link.symlink_to(store, target_is_directory=True)
113 + except OSError:
114 + pytest.skip("symlinks not supported")
115 +
116 + assert is_blocked_sensitive_file_upload_path(link / "document.pdf") is False
117 +
118 +
119 def test_assert_safe_raises() -> None:
120 p = Path.home() / ".ssh" / "id_rsa"
121 with pytest.raises(SensitiveFilePathBlockedError):