@devries-cameron20 / composio-1 / commits / 701824b00
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): confine the deprecated toolkit header and keep siblings of an empty item (PLEN-4352)

Review follow-ups on #4884: - Return None from _parse_item for an empty item such as ";;" instead of letting the unpack raise and discard every valid sibling. - Mirror the composio_client._deprecation module's confinement: ignore a header longer than 2048 characters or carrying a control character, and stop recording new keys once 1024 are tracked. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

Sankaran committed Oct 15, 2026 at 19:48 UTC 701824b00d55f2e32606867ec3e3b67230901c86
2 files changed +58 -2
python/composio/utils/toolkit_deprecation.py
+16 -2
@@ -39,6 +39,15 @@ DOCS_URL = "https://docs.composio.dev/docs/tools-direct/toolkit-versioning#depre
39 #: Versions named per toolkit before the formatter collapses the rest into "and N more".
40 _MAX_VERSIONS_PER_LINE = 5
41
42 +#: The three limits below mirror the ``composio_client._deprecation`` module,
43 +#: which reads the same kind of server-controlled header.
44 +#: A header longer than this is ignored whole rather than parsed.
45 +_MAX_HEADER_LENGTH = 2048
46 +#: A header holding any of these is ignored whole, so nothing partially cleaned reaches the log.
47 +_CONTROL_CHARACTERS = re.compile(r"[\x00-\x1f\x7f]")
48 +#: Keys the process will ever record; past this, new versions are neither recorded nor warned about.
49 +_MAX_TRACKED_VERSIONS = 1024
50 +
51 _logger = logging.getLogger(__name__)
52
53 _SF_STRING = re.compile(r'^"((?:[^"\\]|\\.)*)"$')
@@ -130,7 +139,10 @@ def _decode_sf_date(raw: str) -> t.Optional[datetime]:
139
140 def _parse_item(item: str) -> t.Optional[DeprecatedToolkit]:
141 """Parse one list item; ``None`` when the slug or a known parameter is invalid."""
133 - head, *params = _split_outside_quotes(item, ";")
142 + pieces = _split_outside_quotes(item, ";")
143 + if not pieces:
144 + return None
145 + head, *params = pieces
146 slug = _decode_sf_string(head)
147 if not slug:
148 return None
@@ -257,11 +269,13 @@ def warn_deprecated_toolkits(headers: httpx.Headers, docs_url: str = DOCS_URL) -
269 value = headers.get(HEADER)
270 if not value:
271 return
272 + if len(value) > _MAX_HEADER_LENGTH or _CONTROL_CHARACTERS.search(value):
273 + return
274 entries = parse_deprecated_toolkits_header(value)
275 fresh: list[DeprecatedToolkit] = []
276 with _lock:
277 for entry in entries:
264 - if entry.key in _warned:
278 + if entry.key in _warned or len(_warned) >= _MAX_TRACKED_VERSIONS:
279 continue
280 _warned.add(entry.key)
281 fresh.append(entry)
python/tests/test_toolkit_deprecation.py
+42
@@ -124,6 +124,11 @@ class TestParse:
124 '"GMAIL";version="20250114_00";severity=3;flag;note="x"'
125 ) == [DeprecatedToolkit(slug="GMAIL", version="20250114_00")]
126
127 + def test_empty_item_is_dropped_but_siblings_kept(self):
128 + assert parse_deprecated_toolkits_header('"GMAIL";version="1", ;;') == [
129 + DeprecatedToolkit(slug="GMAIL", version="1")
130 + ]
131 +
132 def test_item_without_version_is_dropped_but_siblings_kept(self):
133 assert parse_deprecated_toolkits_header(
134 f'"GMAIL";deprecated=@1779840000, {BARE_ITEM}'
@@ -255,6 +260,24 @@ class TestWarnOnce:
260 warn_deprecated_toolkits(headers)
261 assert len(_deprecations(caught)) == 2
262
263 + def test_stops_recording_after_1024_keys_without_evicting(self):
264 + def send(version: int) -> None:
265 + warn_deprecated_toolkits(
266 + httpx.Headers({HEADER: f'"GMAIL";version="{version}"'})
267 + )
268 +
269 + with warnings.catch_warnings(record=True) as caught:
270 + warnings.simplefilter("always")
271 + for version in range(1, 1025):
272 + send(version)
273 + assert len(_deprecations(caught)) == 1024
274 + send(1025)
275 + assert len(_deprecations(caught)) == 1024
276 + for version in range(1, 1025):
277 + send(version)
278 + assert len(_deprecations(caught)) == 1024
279 + assert len(td._warned) == 1024
280 +
281 def test_two_threads_one_warning(self):
282 headers = httpx.Headers({HEADER: FULL_ITEM})
283 barrier = threading.Barrier(2)
@@ -281,6 +304,25 @@ class TestResponseHook:
304 response_hook(response)
305 assert len(_deprecations(caught)) == 1
306
307 + def test_oversized_header_is_ignored_and_body_kept(self):
308 + oversized = '"GMAIL";version="1";reason="' + "x" * 2048 + '"'
309 + response = httpx.Response(200, headers={HEADER: oversized}, json={})
310 + with warnings.catch_warnings(record=True) as caught:
311 + warnings.simplefilter("always")
312 + response_hook(response)
313 + assert response.json() == {}
314 + assert _deprecations(caught) == []
315 +
316 + def test_control_character_in_header_is_ignored_and_body_kept(self):
317 + response = httpx.Response(
318 + 200, headers={HEADER: '"GMAIL";version="1";reason="\x1b[2J"'}, json={}
319 + )
320 + with warnings.catch_warnings(record=True) as caught:
321 + warnings.simplefilter("always")
322 + response_hook(response)
323 + assert response.json() == {}
324 + assert _deprecations(caught) == []
325 +
326 def test_never_raises(self, caplog: pytest.LogCaptureFixture):
327 class _Broken:
328 @property