Agent Zero AI framework
Bound attachment metadata percent decoding
TerminallyLazy37093f588806
diff --git a/plugins/_a0_connector/api/ws_connector.py b/plugins/_a0_connector/api/ws_connector.pyindex d2e3d92b4..2b46e0aaf 100644--- a/plugins/_a0_connector/api/ws_connector.py+++ b/plugins/_a0_connector/api/ws_connector.py@@ -74,6 +74,7 @@ WS_FEATURES = [_SNAPSHOT_REPLAY_PAGE_SIZE = 50_TAIL_HISTORY_PAGE_SIZE = 100_LIVE_STREAM_PAGE_SIZE = 100+_ATTACHMENT_METADATA_DECODE_LIMIT = 3def _attachment_log_metadata(attachments: list[str]) -> dict[str, list[str]]:@@ -87,7 +88,14 @@ def _attachment_log_metadata(attachments: list[str]) -> dict[str, list[str]]:except ValueError:continuepath = parsed.path if parsed.scheme else normalized.split("?", 1)[0].split("#", 1)[0]- path = unquote(path).replace("\\", "/")+ for _ in range(_ATTACHMENT_METADATA_DECODE_LIMIT):+ decoded_path = unquote(path)+ if decoded_path == path:+ break+ path = decoded_path+ else:+ continue+ path = path.replace("\\", "/")path = path.split("?", 1)[0].split("#", 1)[0]if path.endswith("/"):continuediff --git a/tests/test_a0_connector_attachment_metadata.py b/tests/test_a0_connector_attachment_metadata.pyindex e67299c66..55fd07a1c 100644--- a/tests/test_a0_connector_attachment_metadata.py+++ b/tests/test_a0_connector_attachment_metadata.py@@ -52,6 +52,30 @@ def test_attachment_log_metadata_strips_encoded_query_and_fragment_suffixes() ->) == {"attachments": ["report", "image"]}+def test_attachment_log_metadata_decodes_double_encoded_separators() -> None:+ assert _attachment_log_metadata(+ [+ "https://host/%252Fhome%252Fuser%252Fsecret.png",+ "https://host/C:%255CUsers%255CAlice%255Csecret.png",+ ]+ ) == {"attachments": ["secret.png", "secret.png"]}+++def test_attachment_log_metadata_strips_double_encoded_delimiter_suffixes() -> None:+ assert _attachment_log_metadata(+ [+ "https://host/report%253Ftoken%253Dredacted.png",+ "https://host/image%2523private-fragment.png",+ ]+ ) == {"attachments": ["report", "image"]}+++def test_attachment_log_metadata_omits_paths_exceeding_decode_limit() -> None:+ assert _attachment_log_metadata(+ ["https://host/%25252Fhome%25252Fuser%25252Fsecret.png"]+ ) == {}++class RecordingLog:def __init__(self) -> None:self.calls: list[dict[str, object]] = []