fix: URL-encode user_id in Synapse admin API paths

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Christian Gick
2026-03-23 19:11:19 +02:00
parent 07d781d101
commit b3e6ae65de

View File

@@ -14,6 +14,7 @@ import os
import subprocess
import sys
import time
from urllib.parse import quote
import httpx
@@ -49,8 +50,9 @@ async def list_devices(
client: httpx.AsyncClient, homeserver: str, headers: dict, user_id: str,
) -> list[dict]:
"""List all devices for a user via Synapse Admin API."""
encoded_user = quote(user_id, safe="")
resp = await client.get(
f"{homeserver}/_synapse/admin/v2/users/{user_id}/devices",
f"{homeserver}/_synapse/admin/v2/users/{encoded_user}/devices",
headers=headers,
)
resp.raise_for_status()
@@ -65,8 +67,9 @@ async def delete_devices_batch(
device_ids: list[str],
) -> int:
"""Bulk-delete devices. Returns count deleted."""
encoded_user = quote(user_id, safe="")
resp = await client.post(
f"{homeserver}/_synapse/admin/v2/users/{user_id}/delete_devices",
f"{homeserver}/_synapse/admin/v2/users/{encoded_user}/delete_devices",
headers=headers,
json={"devices": device_ids},
)
@@ -186,7 +189,7 @@ def main():
parser.add_argument(
"--homeserver",
default=os.environ.get("MATRIX_HOMESERVER", "https://matrix.agiliton.eu"),
help="Homeserver URL",
help="Homeserver URL (use http://CONTAINER_IP:8008 when running on the matrix VM)",
)
parser.add_argument("--keep", type=int, default=1, help="Number of most recent devices to keep")
parser.add_argument("--max-age-days", type=int, default=None, help="Only delete devices older than N days")