Skip to content

Commit 512b3f5

Browse files
authored
Update MSC4326 error code (#18947)
1 parent 35c9cbb commit 512b3f5

4 files changed

Lines changed: 6 additions & 4 deletions

File tree

changelog.d/18947.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update error code used when an appservice tries to masquerade as an unknown device using [MSC4326](https://github.com/matrix-org/matrix-spec-proposals/pull/4326). Contributed by @tulir @ Beeper.

synapse/api/auth/base.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,12 +354,10 @@ async def get_appservice_user(
354354
effective_user_id, effective_device_id
355355
)
356356
if device_opt is None:
357-
# For now, use 400 M_EXCLUSIVE if the device doesn't exist.
358-
# This is an open thread of discussion on MSC3202 as of 2021-12-09.
359357
raise AuthError(
360358
400,
361359
f"Application service trying to use a device that doesn't exist ('{effective_device_id}' for {effective_user_id})",
362-
Codes.EXCLUSIVE,
360+
Codes.UNKNOWN_DEVICE,
363361
)
364362

365363
return create_requester(

synapse/api/errors.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ class Codes(str, Enum):
149149
)
150150
MSC4306_NOT_IN_THREAD = "IO.ELEMENT.MSC4306.M_NOT_IN_THREAD"
151151

152+
# Part of MSC4326
153+
UNKNOWN_DEVICE = "ORG.MATRIX.MSC4326.M_UNKNOWN_DEVICE"
154+
152155

153156
class CodeMessageException(RuntimeError):
154157
"""An exception with integer code, a message string attributes and optional headers.

tests/api/test_auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def test_get_user_by_req_appservice_valid_token_invalid_device_id(self) -> None:
304304

305305
failure = self.get_failure(self.auth.get_user_by_req(request), AuthError)
306306
self.assertEqual(failure.value.code, 400)
307-
self.assertEqual(failure.value.errcode, Codes.EXCLUSIVE)
307+
self.assertEqual(failure.value.errcode, Codes.UNKNOWN_DEVICE)
308308

309309
def test_get_user_by_req__puppeted_token__not_tracking_puppeted_mau(self) -> None:
310310
self.store.get_user_by_access_token = AsyncMock(

0 commit comments

Comments
 (0)