element-hq / element-hq/synapse

Synapse does not reject an attempt to upload keys for device A from device B

Open
#11,720 0 comments 0 reactions 0 assignees View on GitHub
P4 S-Tolerable T-Defect z-cross-signing
Dominant language
Python
Stars
4.6k
Forks
600
Avg merge
5d 22h
Merged PRs (30d)
51

Description

This issue has been migrated from [#11720](https://github.com/matrix-org/synapse/issues/11720).

---

Discovered when playing around writing a stress test.

Synapse seems to treat the contents of `/keys/upload` as an opaque blob. But the spec is pretty explicit that it should have [a certain shape](https://spec.matrix.org/v1.1/client-server-api/#post_matrixclientv3keysupload), and that you must include a device_id which matches "the one when logging in".

As proof, I offer the following debug line
```
* 2022-01-10 18:21:09,180 - synapse.handlers.device - 251 - WARNING - GET-4 - DMR: stream_id=6, devices=[{'device_id': 'MEVKUJOZQV* ', 'keys': {'algorithms': [], 'device_id': 'alice_1', 'keys': {}, 'signatures': {}, 'user_id': '@alice:hs1'}}]
```

which came from

```
async def on_federation_query_user_devices(self, user_id: str) -> JsonDict:
stream_id, devices = await self.store.get_e2e_device_keys_for_federation_query(
user_id
)
logger.warning(f"DMR: {stream_id=}, {devices=}")
```

Contributor guide

Open the contributing guide

Research direction

Start at the /keys/upload client-server API handling and compare its validation with the Matrix specification linked in the issue. Also inspect on_federation_query_user_devices, which is shown as producing the malformed device data; done means mismatched device uploads are rejected and the required request shape is enforced.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend, security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.