@devries-cameron20 / composio-1 / commits / b3f942cb1
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.

feat(py): address security concerns

jkomyno committed Feb 2, 2026 at 20:22 UTC b3f942cb19c972097c47f60774286ef0c56e7c82
3 files changed +396 -22
python/composio/core/models/_files.py
+136 -9
@@ -18,6 +18,7 @@ from composio.client.types import Tool
18 from composio.exceptions import (
19 ErrorDownloadingFile,
20 ErrorUploadingFile,
21 + ResponseTooLargeError,
22 SDKFileNotFoundError,
23 )
24 from composio.utils import mimetypes
@@ -35,6 +36,20 @@ Long filenames (containing hashes, UUIDs, or encoded metadata) are replaced
36 with timestamped filenames to match TypeScript SDK behavior.
37 """
38
39 +_MAX_RESPONSE_SIZE = 100 * 1024 * 1024 # 100 MB default limit
40 +"""
41 +Maximum response size in bytes when fetching files from URLs.
42 +Prevents memory exhaustion attacks from malicious URLs pointing to large files.
43 +"""
44 +
45 +_CONNECT_TIMEOUT = 5 # seconds
46 +_READ_TIMEOUT = 60 # seconds
47 +"""
48 +Separate connect and read timeouts for URL fetching.
49 +Connect timeout is short to fail fast on unreachable hosts.
50 +Read timeout is longer to allow for slower file transfers.
51 +"""
52 +
53 LOCAL_CACHE_DIRECTORY_NAME = ".composio"
54 """
55 Local cache directory name for composio CLI
@@ -73,7 +88,20 @@ Local output file directory name for composio tools
88 """
89
90
76 -def get_md5(file: Path):
91 +def get_md5(file: Path) -> str:
92 + """Calculate MD5 hash of a file for integrity verification.
93 +
94 + Note: MD5 is used here for file integrity checking and deduplication,
95 + not for cryptographic security. The Composio API requires MD5 hashes
96 + for file upload verification. For security-critical applications,
97 + consider using SHA-256 for additional integrity checks.
98 +
99 + Args:
100 + file: Path to file to hash
101 +
102 + Returns:
103 + Hexadecimal MD5 hash string
104 + """
105 obj = hashlib.md5()
106 with file.open("rb") as fp:
107 while True:
@@ -85,8 +113,18 @@ def get_md5(file: Path):
113
114
115 def upload(url: str, file: Path) -> bool:
116 + """Upload file to presigned S3 URL.
117 +
118 + Args:
119 + url: Presigned S3 upload URL
120 + file: Path to file to upload
121 +
122 + Returns:
123 + True if upload succeeded (HTTP 200), False otherwise
124 + """
125 with file.open("rb") as data:
89 - return requests.put(url=url, data=data).status_code in (200, 403)
126 + response = requests.put(url=url, data=data)
127 + return response.status_code == 200
128
129
130 class _FileUploadResponse(_ComposioBaseModel):
@@ -168,19 +206,107 @@ def _truncate_filename(filename: str, max_length: int = _MAX_FILENAME_LENGTH) ->
206 return _generate_timestamped_filename(ext)
207
208
171 -def _fetch_file_from_url(url: str) -> t.Tuple[str, bytes, str]:
172 - """Fetch file content from a URL.
209 +def _sanitize_url_for_logging(url: str) -> str:
210 + """Sanitize URL for safe logging (remove sensitive query params).
211 +
212 + Args:
213 + url: URL to sanitize
214 +
215 + Returns:
216 + URL with query parameters hidden
217 + """
218 + parsed = urlparse(url)
219 + if parsed.query:
220 + return f"{parsed.scheme}://{parsed.netloc}{parsed.path}?[REDACTED]"
221 + return url
222 +
223 +
224 +def _fetch_file_from_url(
225 + url: str,
226 + max_size: int = _MAX_RESPONSE_SIZE,
227 +) -> t.Tuple[str, bytes, str]:
228 + """Fetch file content from a URL with security protections.
229 +
230 + Security features:
231 + - Response size limiting (prevents memory exhaustion)
232 + - Redirects disabled (prevents redirect-based attacks)
233 + - Separate connect/read timeouts
234 +
235 + Args:
236 + url: URL to fetch file from
237 + max_size: Maximum response size in bytes (default: 100MB)
238
239 Returns:
240 Tuple of (filename, content_bytes, mimetype)
241 +
242 + Raises:
243 + ResponseTooLargeError: If response exceeds max_size
244 + ErrorUploadingFile: If fetch fails for other reasons
245 """
177 - response = requests.get(url, timeout=30)
246 + # Make request without following redirects
247 + try:
248 + response = requests.get(
249 + url,
250 + stream=True, # Enable streaming for size limiting
251 + allow_redirects=False, # Disable redirects for security
252 + timeout=(_CONNECT_TIMEOUT, _READ_TIMEOUT),
253 + )
254 + except requests.exceptions.Timeout:
255 + raise ErrorUploadingFile(
256 + f"Request timed out fetching URL: {_sanitize_url_for_logging(url)}"
257 + )
258 + except requests.exceptions.RequestException as e:
259 + raise ErrorUploadingFile(
260 + f"Failed to fetch file from URL: {_sanitize_url_for_logging(url)}. Error: {e}"
261 + )
262 +
263 + # Reject redirects - require direct URL to resource
264 + if response.status_code in (301, 302, 303, 307, 308):
265 + location = response.headers.get("Location", "unknown")
266 + response.close()
267 + raise ErrorUploadingFile(
268 + f"URL returned redirect to {_sanitize_url_for_logging(location)}. "
269 + f"Please provide a direct URL to the file."
270 + )
271 +
272 + # Check for successful response
273 if not response.ok:
274 + response.close()
275 raise ErrorUploadingFile(
180 - f"Failed to fetch file from URL: {url}. Status: {response.status_code}"
276 + f"Failed to fetch file from URL: {_sanitize_url_for_logging(url)}. "
277 + f"Status: {response.status_code}"
278 + )
279 +
280 + # Check Content-Length header first (early abort for oversized files)
281 + content_length = response.headers.get("Content-Length")
282 + if content_length and int(content_length) > max_size:
283 + response.close()
284 + raise ResponseTooLargeError(
285 + f"File size ({int(content_length)} bytes) exceeds maximum allowed "
286 + f"size ({max_size} bytes)"
287 )
288
183 - content = response.content
289 + # Stream response with size tracking
290 + chunks: t.List[bytes] = []
291 + total_bytes = 0
292 + chunk_size = 8192 # 8 KB chunks
293 +
294 + try:
295 + for chunk in response.iter_content(chunk_size=chunk_size):
296 + if chunk:
297 + total_bytes += len(chunk)
298 + if total_bytes > max_size:
299 + response.close()
300 + raise ResponseTooLargeError(
301 + f"Response size exceeds maximum allowed size ({max_size} bytes)"
302 + )
303 + chunks.append(chunk)
304 + finally:
305 + response.close()
306 +
307 + content = b"".join(chunks)
308 +
309 + # Extract mimetype
310 mimetype = response.headers.get("content-type", "application/octet-stream")
311 # Handle mimetypes with charset or other parameters (e.g., "text/html; charset=utf-8")
312 mimetype = mimetype.split(";")[0].strip()
@@ -236,9 +362,10 @@ def _upload_bytes_to_s3(
362 headers={"Content-Type": mimetype},
363 )
364
239 - if upload_response.status_code not in (200, 403):
365 + if upload_response.status_code != 200:
366 raise ErrorUploadingFile(
241 - f"Failed to upload to S3. Status: {upload_response.status_code}"
367 + f"Failed to upload to S3. Status: {upload_response.status_code}. "
368 + f"This may indicate an expired presigned URL or permission issue."
369 )
370
371 return s3meta.key
python/composio/exceptions.py
+6
@@ -172,6 +172,12 @@ class ErrorDownloadingFile(FileError):
172 pass
173
174
175 +class ResponseTooLargeError(FileError):
176 + """Raised when a response exceeds the maximum allowed size."""
177 +
178 + pass
179 +
180 +
181 class TriggerError(ToolkitError):
182 pass
183
python/tests/test_files.py
+254 -13
@@ -18,10 +18,11 @@ from composio.core.models._files import (
18 _truncate_filename,
19 _fetch_file_from_url,
20 _upload_bytes_to_s3,
21 + _sanitize_url_for_logging,
22 _MAX_FILENAME_LENGTH,
23 )
24 from composio.core.models.base import allow_tracking
24 -from composio.exceptions import ErrorUploadingFile
25 +from composio.exceptions import ErrorUploadingFile, ResponseTooLargeError
26
27
28 @pytest.fixture(autouse=True)
@@ -1047,8 +1048,10 @@ class TestFetchFileFromUrl:
1048 """Test successful file fetch from URL."""
1049 mock_response = MagicMock()
1050 mock_response.ok = True
1050 - mock_response.content = b"test file content"
1051 + mock_response.status_code = 200
1052 mock_response.headers = {"content-type": "image/jpeg"}
1053 + mock_response.iter_content.return_value = [b"test file content"]
1054 + mock_response.close = MagicMock()
1055 mock_get.return_value = mock_response
1056
1057 filename, content, mimetype = _fetch_file_from_url(
@@ -1058,15 +1061,22 @@ class TestFetchFileFromUrl:
1061 assert content == b"test file content"
1062 assert mimetype == "image/jpeg"
1063 assert filename == "image.jpg"
1061 - mock_get.assert_called_once_with("https://example.com/image.jpg", timeout=30)
1064 + mock_get.assert_called_once_with(
1065 + "https://example.com/image.jpg",
1066 + stream=True,
1067 + allow_redirects=False,
1068 + timeout=(5, 60),
1069 + )
1070
1071 @patch("composio.core.models._files.requests.get")
1072 def test_fetch_file_from_url_with_charset_in_content_type(self, mock_get):
1073 """Test that charset is stripped from content-type."""
1074 mock_response = MagicMock()
1075 mock_response.ok = True
1068 - mock_response.content = b"<html></html>"
1076 + mock_response.status_code = 200
1077 mock_response.headers = {"content-type": "text/html; charset=utf-8"}
1078 + mock_response.iter_content.return_value = [b"<html></html>"]
1079 + mock_response.close = MagicMock()
1080 mock_get.return_value = mock_response
1081
1082 filename, content, mimetype = _fetch_file_from_url(
@@ -1080,8 +1090,10 @@ class TestFetchFileFromUrl:
1090 """Test filename generation when URL has no filename."""
1091 mock_response = MagicMock()
1092 mock_response.ok = True
1083 - mock_response.content = b"image data"
1093 + mock_response.status_code = 200
1094 mock_response.headers = {"content-type": "image/png"}
1095 + mock_response.iter_content.return_value = [b"image data"]
1096 + mock_response.close = MagicMock()
1097 mock_get.return_value = mock_response
1098
1099 filename, content, mimetype = _fetch_file_from_url("https://example.com/")
@@ -1094,8 +1106,10 @@ class TestFetchFileFromUrl:
1106 """Test filename generation when URL filename has no extension."""
1107 mock_response = MagicMock()
1108 mock_response.ok = True
1097 - mock_response.content = b"pdf data"
1109 + mock_response.status_code = 200
1110 mock_response.headers = {"content-type": "application/pdf"}
1111 + mock_response.iter_content.return_value = [b"pdf data"]
1112 + mock_response.close = MagicMock()
1113 mock_get.return_value = mock_response
1114
1115 filename, content, mimetype = _fetch_file_from_url(
@@ -1111,6 +1125,7 @@ class TestFetchFileFromUrl:
1125 mock_response = MagicMock()
1126 mock_response.ok = False
1127 mock_response.status_code = 404
1128 + mock_response.close = MagicMock()
1129 mock_get.return_value = mock_response
1130
1131 with pytest.raises(ErrorUploadingFile) as exc_info:
@@ -1124,8 +1139,10 @@ class TestFetchFileFromUrl:
1139 """Test that percent-encoded characters in URL filenames are decoded."""
1140 mock_response = MagicMock()
1141 mock_response.ok = True
1127 - mock_response.content = b"document content"
1142 + mock_response.status_code = 200
1143 mock_response.headers = {"content-type": "application/pdf"}
1144 + mock_response.iter_content.return_value = [b"document content"]
1145 + mock_response.close = MagicMock()
1146 mock_get.return_value = mock_response
1147
1148 # URL with percent-encoded spaces and special characters
@@ -1143,8 +1160,10 @@ class TestFetchFileFromUrl:
1160 """Test that percent-encoded unicode characters in URL filenames are decoded."""
1161 mock_response = MagicMock()
1162 mock_response.ok = True
1146 - mock_response.content = b"image data"
1163 + mock_response.status_code = 200
1164 mock_response.headers = {"content-type": "image/jpeg"}
1165 + mock_response.iter_content.return_value = [b"image data"]
1166 + mock_response.close = MagicMock()
1167 mock_get.return_value = mock_response
1168
1169 # URL with percent-encoded unicode (e.g., Japanese characters)
@@ -1160,8 +1179,10 @@ class TestFetchFileFromUrl:
1179 """Test that plus signs in URL paths are preserved (not converted to spaces)."""
1180 mock_response = MagicMock()
1181 mock_response.ok = True
1163 - mock_response.content = b"file content"
1182 + mock_response.status_code = 200
1183 mock_response.headers = {"content-type": "text/plain"}
1184 + mock_response.iter_content.return_value = [b"file content"]
1185 + mock_response.close = MagicMock()
1186 mock_get.return_value = mock_response
1187
1188 # Plus signs in path should remain as plus signs (unquote doesn't convert + to space)
@@ -1531,8 +1552,10 @@ class TestFetchFileFromUrlWithTruncation:
1552 """Long filenames from URLs should be truncated."""
1553 mock_response = MagicMock()
1554 mock_response.ok = True
1534 - mock_response.content = b"test content"
1555 + mock_response.status_code = 200
1556 mock_response.headers = {"content-type": "application/pdf"}
1557 + mock_response.iter_content.return_value = [b"test content"]
1558 + mock_response.close = MagicMock()
1559 mock_get.return_value = mock_response
1560
1561 # Create a very long filename (hash-based, common in public buckets)
@@ -1552,8 +1575,10 @@ class TestFetchFileFromUrlWithTruncation:
1575 """Short filenames should be preserved unchanged."""
1576 mock_response = MagicMock()
1577 mock_response.ok = True
1555 - mock_response.content = b"image data"
1578 + mock_response.status_code = 200
1579 mock_response.headers = {"content-type": "image/jpeg"}
1580 + mock_response.iter_content.return_value = [b"image data"]
1581 + mock_response.close = MagicMock()
1582 mock_get.return_value = mock_response
1583
1584 filename, content, mimetype = _fetch_file_from_url(
@@ -1567,8 +1592,10 @@ class TestFetchFileFromUrlWithTruncation:
1592 """Truncation should happen after extension is appended."""
1593 mock_response = MagicMock()
1594 mock_response.ok = True
1570 - mock_response.content = b"pdf content"
1595 + mock_response.status_code = 200
1596 mock_response.headers = {"content-type": "application/pdf"}
1597 + mock_response.iter_content.return_value = [b"pdf content"]
1598 + mock_response.close = MagicMock()
1599 mock_get.return_value = mock_response
1600
1601 # URL without extension - extension will be added from mimetype
@@ -1586,8 +1613,10 @@ class TestFetchFileFromUrlWithTruncation:
1613 """Generated timestamped filenames (when URL has no filename) should be short enough."""
1614 mock_response = MagicMock()
1615 mock_response.ok = True
1589 - mock_response.content = b"data"
1616 + mock_response.status_code = 200
1617 mock_response.headers = {"content-type": "image/png"}
1618 + mock_response.iter_content.return_value = [b"data"]
1619 + mock_response.close = MagicMock()
1620 mock_get.return_value = mock_response
1621
1622 # URL with no filename - will generate a timestamped one
@@ -1597,3 +1626,215 @@ class TestFetchFileFromUrlWithTruncation:
1626 assert filename.startswith("file_")
1627 assert filename.endswith(".png")
1628 assert len(filename) < 50 # Timestamped names are short
1629 +
1630 +
1631 +class TestResponseSizeLimit:
1632 + """Test response size limiting."""
1633 +
1634 + @patch("composio.core.models._files.requests.get")
1635 + def test_rejects_oversized_content_length(self, mock_get):
1636 + """Files with Content-Length > max_size should be rejected early."""
1637 + mock_response = MagicMock()
1638 + mock_response.ok = True
1639 + mock_response.status_code = 200
1640 + mock_response.headers = {"Content-Length": "200000000"} # 200MB
1641 + mock_response.close = MagicMock()
1642 + mock_get.return_value = mock_response
1643 +
1644 + with pytest.raises(ResponseTooLargeError):
1645 + _fetch_file_from_url(
1646 + "https://example.com/large.zip", max_size=100 * 1024 * 1024
1647 + )
1648 +
1649 + @patch("composio.core.models._files.requests.get")
1650 + def test_rejects_oversized_during_streaming(self, mock_get):
1651 + """Files that exceed max_size during download should be rejected."""
1652 + mock_response = MagicMock()
1653 + mock_response.ok = True
1654 + mock_response.status_code = 200
1655 + mock_response.headers = {} # No Content-Length
1656 + # Return 20MB of data in chunks
1657 + mock_response.iter_content.return_value = [
1658 + b"x" * 1024 * 1024 for _ in range(20)
1659 + ]
1660 + mock_response.close = MagicMock()
1661 + mock_get.return_value = mock_response
1662 +
1663 + with pytest.raises(ResponseTooLargeError):
1664 + _fetch_file_from_url(
1665 + "https://example.com/large.zip", max_size=10 * 1024 * 1024
1666 + )
1667 +
1668 + @patch("composio.core.models._files.requests.get")
1669 + def test_accepts_file_within_limit(self, mock_get):
1670 + """Files within size limit should be accepted."""
1671 + mock_response = MagicMock()
1672 + mock_response.ok = True
1673 + mock_response.status_code = 200
1674 + mock_response.headers = {"content-type": "image/jpeg", "Content-Length": "1000"}
1675 + mock_response.iter_content.return_value = [b"x" * 1000]
1676 + mock_response.close = MagicMock()
1677 + mock_get.return_value = mock_response
1678 +
1679 + filename, content, mimetype = _fetch_file_from_url(
1680 + "https://example.com/image.jpg", max_size=10 * 1024 * 1024
1681 + )
1682 +
1683 + assert len(content) == 1000
1684 + assert mimetype == "image/jpeg"
1685 +
1686 +
1687 +class TestRedirectHandling:
1688 + """Test redirect handling (redirects should be rejected)."""
1689 +
1690 + @patch("composio.core.models._files.requests.get")
1691 + def test_rejects_redirect_302(self, mock_get):
1692 + """302 redirects should be rejected with clear error message."""
1693 + mock_response = MagicMock()
1694 + mock_response.status_code = 302
1695 + mock_response.headers = {"Location": "https://example.com/final.jpg"}
1696 + mock_response.close = MagicMock()
1697 + mock_get.return_value = mock_response
1698 +
1699 + with pytest.raises(ErrorUploadingFile, match="redirect"):
1700 + _fetch_file_from_url("https://example.com/redirect")
1701 +
1702 + @patch("composio.core.models._files.requests.get")
1703 + def test_rejects_redirect_301(self, mock_get):
1704 + """301 redirects should be rejected."""
1705 + mock_response = MagicMock()
1706 + mock_response.status_code = 301
1707 + mock_response.headers = {"Location": "https://example.com/"}
1708 + mock_response.close = MagicMock()
1709 + mock_get.return_value = mock_response
1710 +
1711 + with pytest.raises(ErrorUploadingFile, match="redirect"):
1712 + _fetch_file_from_url("https://example.com/test")
1713 +
1714 + @patch("composio.core.models._files.requests.get")
1715 + def test_rejects_redirect_307(self, mock_get):
1716 + """307 redirects should be rejected."""
1717 + mock_response = MagicMock()
1718 + mock_response.status_code = 307
1719 + mock_response.headers = {"Location": "https://example.com/"}
1720 + mock_response.close = MagicMock()
1721 + mock_get.return_value = mock_response
1722 +
1723 + with pytest.raises(ErrorUploadingFile, match="redirect"):
1724 + _fetch_file_from_url("https://example.com/test")
1725 +
1726 + @patch("composio.core.models._files.requests.get")
1727 + def test_rejects_redirect_308(self, mock_get):
1728 + """308 redirects should be rejected."""
1729 + mock_response = MagicMock()
1730 + mock_response.status_code = 308
1731 + mock_response.headers = {"Location": "https://example.com/"}
1732 + mock_response.close = MagicMock()
1733 + mock_get.return_value = mock_response
1734 +
1735 + with pytest.raises(ErrorUploadingFile, match="redirect"):
1736 + _fetch_file_from_url("https://example.com/test")
1737 +
1738 +
1739 +class TestS3UploadErrorHandling:
1740 + """Test S3 upload error handling."""
1741 +
1742 + @patch("composio.core.models._files.requests.put")
1743 + def test_403_is_treated_as_error(self, mock_put):
1744 + """HTTP 403 should be treated as upload failure."""
1745 + mock_client = MagicMock()
1746 + mock_s3_response = MagicMock()
1747 + mock_s3_response.key = "s3-key"
1748 + mock_s3_response.new_presigned_url = "https://s3.example.com/upload"
1749 + mock_client.post.return_value = mock_s3_response
1750 +
1751 + mock_put_response = MagicMock()
1752 + mock_put_response.status_code = 403
1753 + mock_put.return_value = mock_put_response
1754 +
1755 + with pytest.raises(ErrorUploadingFile, match="403"):
1756 + _upload_bytes_to_s3(
1757 + client=mock_client,
1758 + filename="test.jpg",
1759 + content=b"data",
1760 + mimetype="image/jpeg",
1761 + tool="TEST",
1762 + toolkit="test",
1763 + )
1764 +
1765 + @patch("composio.core.models._files.requests.put")
1766 + def test_200_is_success(self, mock_put):
1767 + """HTTP 200 should be treated as success."""
1768 + mock_client = MagicMock()
1769 + mock_s3_response = MagicMock()
1770 + mock_s3_response.key = "s3-key"
1771 + mock_s3_response.new_presigned_url = "https://s3.example.com/upload"
1772 + mock_client.post.return_value = mock_s3_response
1773 +
1774 + mock_put_response = MagicMock()
1775 + mock_put_response.status_code = 200
1776 + mock_put.return_value = mock_put_response
1777 +
1778 + result = _upload_bytes_to_s3(
1779 + client=mock_client,
1780 + filename="test.jpg",
1781 + content=b"data",
1782 + mimetype="image/jpeg",
1783 + tool="TEST",
1784 + toolkit="test",
1785 + )
1786 + assert result == "s3-key"
1787 +
1788 + @patch("composio.core.models._files.requests.put")
1789 + def test_500_is_treated_as_error(self, mock_put):
1790 + """HTTP 500 should be treated as upload failure."""
1791 + mock_client = MagicMock()
1792 + mock_s3_response = MagicMock()
1793 + mock_s3_response.key = "s3-key"
1794 + mock_s3_response.new_presigned_url = "https://s3.example.com/upload"
1795 + mock_client.post.return_value = mock_s3_response
1796 +
1797 + mock_put_response = MagicMock()
1798 + mock_put_response.status_code = 500
1799 + mock_put.return_value = mock_put_response
1800 +
1801 + with pytest.raises(ErrorUploadingFile, match="500"):
1802 + _upload_bytes_to_s3(
1803 + client=mock_client,
1804 + filename="test.jpg",
1805 + content=b"data",
1806 + mimetype="image/jpeg",
1807 + tool="TEST",
1808 + toolkit="test",
1809 + )
1810 +
1811 +
1812 +class TestUrlSanitization:
1813 + """Test URL sanitization for logging."""
1814 +
1815 + def test_sanitizes_query_params(self):
1816 + """Query parameters should be redacted in logs."""
1817 + url = "https://example.com/file?token=secret123&key=abc"
1818 + sanitized = _sanitize_url_for_logging(url)
1819 + assert "secret123" not in sanitized
1820 + assert "abc" not in sanitized
1821 + assert "[REDACTED]" in sanitized
1822 +
1823 + def test_preserves_url_without_query(self):
1824 + """URLs without query params should be unchanged."""
1825 + url = "https://example.com/path/to/file.jpg"
1826 + sanitized = _sanitize_url_for_logging(url)
1827 + assert sanitized == url
1828 +
1829 + def test_preserves_path(self):
1830 + """Path should be preserved when redacting query params."""
1831 + url = "https://example.com/path/to/file.jpg?token=secret"
1832 + sanitized = _sanitize_url_for_logging(url)
1833 + assert "/path/to/file.jpg" in sanitized
1834 + assert "example.com" in sanitized
1835 +
1836 + def test_handles_empty_query(self):
1837 + """URLs with empty query string should not have [REDACTED]."""
1838 + url = "https://example.com/file.jpg"
1839 + sanitized = _sanitize_url_for_logging(url)
1840 + assert "[REDACTED]" not in sanitized