Skip to content

Fix 500 error when user-interactive auth requests send a null or non-object auth - #20274

Merged
devonh merged 4 commits into
element-hq:developfrom
ankit373:fix-uia-null-auth
Sep 28, 2026
Merged

devonh merged 4 commits into
element-hq:developfrom
ankit373:fix-uia-null-auth

Conversation

@ankit373

@ankit373 ankit373 commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #15871

What was broken

Sending {"auth": null} to any endpoint that requires user-interactive auth (for example POST /keys/device_signing/upload, DELETE /devices/{deviceId} or POST /register) returned a 500 instead of the usual 401 with the available flows. A non-object auth on endpoints that do not validate the body with a model (such as /register) could also 500, e.g. {"auth": ["session"]}.

Root cause

AuthHandler.check_ui_auth did clientdict.pop("auth", {}), so the {} default only applies when the key is missing. An explicit null came through as None and the following "session" in authdict raised TypeError. get_session_id had the same assumption that auth is a dict.

Pull Request Checklist

…object `auth`

Signed-off-by: Ankit Jha <ankit.jha@tradomate.one>
@ankit373
ankit373 requested a review from a team as a code owner September 25, 2026 17:26
@ankit373
ankit373 requested review from devonh and removed request for a team September 25, 2026 17:26
Signed-off-by: Ankit Jha <ankit.jha@tradomate.one>
@MadLittleMods MadLittleMods added the A-Login (also includes logout for now) label Sep 25, 2026

@devonh devonh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is similar to matrix-org/synapse#15944 (comment), matrix-org/synapse#16352, and matrix-org/synapse#16153

They were all closed for the same reason:
"We should be doing validation of the data at the REST layer to ensure that the expected fields exist."
Please follow this suggestion, using the established patterns for the existing endpoints, instead of doing data validation at this layer.

The null checking makes sense to have here, because even with model validation, null is still passed down to this function.
The comment should be updated though to be clearer.
Something like:

        # `auth` is optional, so an explicit `null` means the same as `{}`, ie. no
        # auth stage attempted yet.

Endpoints that pass a raw body to user-interactive auth now validate it with
a UserInteractiveAuthBody model, as endpoints with request models already do.
The handler keeps only the null check, since a validated null still reaches it.

Signed-off-by: Ankit Jha <ankit.jha@tradomate.one>
@ankit373

Copy link
Copy Markdown
Contributor Author

Thanks @devonh, reworked in f9e5d27 along those lines.

  • The type check is gone from the handler. The endpoints that pass a raw body to UIA (/keys/device_signing/upload, /register and /login/get_token) now validate it with a small UserInteractiveAuthBody model built on the existing AuthenticationData, using validate_json_object the same way KeyUploadRequestBody already does. Endpoints with request models (devices, account) already had this.
  • check_ui_auth keeps only the null check, with your comment.
  • Added a test for /keys/device_signing/upload, the issue's original repro. It returns 500 on develop and passes now.

trial on the auth, register, keys, devices and login-token tests plus tests.handlers.test_auth passes 105/105, and ruff and mypy are clean.

@ankit373

Copy link
Copy Markdown
Contributor Author

@devonh I've moved the validation to the REST layer as you suggested (f9e5d27): a UserInteractiveAuthBody model is applied in the three servlets that were passing a raw body to UIA, and the handler keeps only the null check with your wording. Ready for another look when you have a moment. CI is still waiting on workflow approval for the fork.

@devonh devonh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few smaller change requests this time. Otherwise this is looking in good shape.

Comment thread tests/rest/client/test_register.py Resolved
Comment thread tests/rest/client/test_register.py Resolved
Comment thread synapse/rest/client/keys.py Resolved
…te call sites

Signed-off-by: Ankit Jha <ankit.jha@tradomate.one>
@devonh
devonh merged commit 18c10b8 into element-hq:develop Sep 28, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Login (also includes logout for now)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

500 error when auth is null for a UIA request

3 participants