17 lines
1,003 B
Markdown
17 lines
1,003 B
Markdown
# synapse-0002: CWE-407 in synapse — sync handler get_users_in_room Sequence linear scan
|
||
|
||
**Severity:** HIGH
|
||
**File:** `synapse/handlers/sync.py:1439`
|
||
**Pattern:**
|
||
```python
|
||
for room_id, event in mem_last_change_by_room_id.items(): # O(R) rooms changed
|
||
...
|
||
if event.membership == Membership.JOIN:
|
||
user_ids_in_room = await self.store.get_users_in_room(room_id) # returns Sequence[str] (List)
|
||
if user_id in user_ids_in_room: # O(U) linear scan
|
||
mutable_joined_room_ids.add(room_id)
|
||
```
|
||
**Complexity:** O(R × U) — for each of R rooms that changed membership, scans all U users in the room
|
||
**Fix:** `set(await self.store.get_users_in_room(room_id))` or restructure to avoid the membership check entirely
|
||
**Speedup:** 100–10000× at large room size (U=10000 users, R=10 rooms → 100000 comparisons vs 10 hash lookups)
|
||
**Hot path:** `_generate_sync_entry_for_rooms()` — called on every sync request when membership changes occur
|