Repository navigation
Fix 500 error when user-interactive auth requests send a null or non-object auth - #20274
Conversation
…object `auth` Signed-off-by: Ankit Jha <ankit.jha@tradomate.one>
Signed-off-by: Ankit Jha <ankit.jha@tradomate.one>
devonh
left a comment
There was a problem hiding this comment.
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>
|
Thanks @devonh, reworked in f9e5d27 along those lines.
|
|
@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
left a comment
There was a problem hiding this comment.
A few smaller change requests this time. Otherwise this is looking in good shape.
…te call sites Signed-off-by: Ankit Jha <ankit.jha@tradomate.one>
Fixes #15871
What was broken
Sending
{"auth": null}to any endpoint that requires user-interactive auth (for examplePOST /keys/device_signing/upload,DELETE /devices/{deviceId}orPOST /register) returned a 500 instead of the usual 401 with the available flows. A non-objectauthon 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_authdidclientdict.pop("auth", {}), so the{}default only applies when the key is missing. An explicitnullcame through asNoneand the following"session" in authdictraisedTypeError.get_session_idhad the same assumption thatauthis a dict.Pull Request Checklist