Skip to content

Return 403 instead of 400 when profile changes are disabled - #20173

Merged
erikjohnston merged 3 commits into
element-hq:developfrom
barodeur:fix-forbidden-change-displayname-errcode
Sep 2, 2026
Merged

Return 403 instead of 400 when profile changes are disabled#20173
erikjohnston merged 3 commits into
element-hq:developfrom
barodeur:fix-forbidden-change-displayname-errcode

Conversation

@barodeur

@barodeur barodeur commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

With enable_set_displayname: false (or enable_set_avatar_url: false), refusing a profile change returned the right errcode with the wrong status:

PUT /_matrix/client/v3/profile/@alice:example.com/displayname   (displayname already set)
→ 400 {"errcode": "M_FORBIDDEN", "error": "Changing display name is disabled on this server"}

DELETE /_matrix/client/v3/profile/@alice:example.com/displayname
→ 400 {"errcode": "M_FORBIDDEN", "error": "Changing display name is disabled on this server"}

With this fix:

PUT /_matrix/client/v3/profile/@alice:example.com/displayname   (displayname already set)
→ 403 {"errcode": "M_FORBIDDEN", "error": "Changing display name is disabled on this server"}

DELETE /_matrix/client/v3/profile/@alice:example.com/displayname
→ 403 {"errcode": "M_FORBIDDEN", "error": "Changing display name is disabled on this server"}

The spec defines the 403 response of PUT /_matrix/client/v3/profile/{userId}/{keyName} as "The server is unwilling to perform the operation, either due to insufficient permissions or because profile modifications are disabled", while 400 is reserved for malformed input (M_BAD_JSON, M_MISSING_PARAM, …).

Clients seem to rely on errcode field more than the HTTP Status Code, that change seems safe.

Pull Request Checklist

  • Pull request is based on the develop branch
  • Pull request includes a changelog file. The entry should:
    • Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from EventStore to EventWorkerStore.".
    • Use markdown where necessary, mostly for code blocks.
    • End with either a period (.) or an exclamation mark (!).
    • Start with a capital letter.
    • Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry.
  • Code style is correct (run the linters)

With enable_set_displayname: false / enable_set_avatar_url: false, the
spec requires PUT/DELETE on the corresponding profile field to be
refused with HTTP 403 M_FORBIDDEN, not 400. Assert the status code in
the existing handler tests and add REST-level coverage for PUT and
DELETE on displayname and avatar_url.
The spec defines the 403 response of
PUT|DELETE /_matrix/client/v3/profile/{userId}/{keyName} as "The server
is unwilling to perform the operation, either due to insufficient
permissions or because profile modifications are disabled", while 400
is reserved for malformed input. Synapse raised these refusals with
HTTP 400 and errcode M_FORBIDDEN; use 403 to match the errcode and the
spec, consistent with the other profile refusals (disallowed avatars,
custom profile fields).
@barodeur
barodeur marked this pull request as ready for review September 1, 2026 15:53
@barodeur
barodeur requested a review from a team as a code owner September 1, 2026 15:53
@barodeur
barodeur requested review from erikjohnston and removed request for a team September 1, 2026 15:53
@erikjohnston
erikjohnston merged commit f94abb6 into element-hq:develop Sep 2, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants