Fix GET /_matrix/federation/v1/query/profile response (#18593)

Don't send the fields `avatar_url` and `displayname` when they are not
defined for the queried user.

Before this change they would be sent and set to null in the JSON
response object, which would violate the OpenAPI definitions
(https://spec.matrix.org/v1.11/server-server-api/#get_matrixfederationv1queryprofile).
Fixes: #18442 
### Pull Request Checklist

<!-- Please read
https://element-hq.github.io/synapse/latest/development/contributing_guide.html
before submitting your pull request -->

* [x] Pull request is based on the develop branch
* [x] Pull request includes a [changelog
file](https://element-hq.github.io/synapse/latest/development/contributing_guide.html#changelog).
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.
* [x] [Code
style](https://element-hq.github.io/synapse/latest/code_style.html) is
correct (run the
[linters](https://element-hq.github.io/synapse/latest/development/contributing_guide.html#run-the-linters))

---------

Co-authored-by: Quentin Gliech <quenting@element.io>
This commit is contained in:
Alex Durham 2025-07-03 11:59:45 +02:00 committed by GitHub
parent 8f4caeeaf6
commit 0d0f966b31
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 4 deletions

1
changelog.d/18593.bugfix Normal file
View File

@ -0,0 +1 @@
Fix `avatar_url` and `displayname` being sent on federation profile queries when they are not set.

View File

@ -539,11 +539,17 @@ class ProfileHandler:
response: JsonDict = {}
try:
if just_field is None or just_field == ProfileFields.DISPLAYNAME:
response["displayname"] = await self.store.get_profile_displayname(user)
displayname = await self.store.get_profile_displayname(user)
# do not set the displayname field if it is None,
# since then we send a null in the JSON response
if displayname is not None:
response["displayname"] = displayname
if just_field is None or just_field == ProfileFields.AVATAR_URL:
response["avatar_url"] = await self.store.get_profile_avatar_url(user)
avatar_url = await self.store.get_profile_avatar_url(user)
# do not set the avatar_url field if it is None,
# since then we send a null in the JSON response
if avatar_url is not None:
response["avatar_url"] = avatar_url
if self.hs.config.experimental.msc4133_enabled:
if just_field is None:
response.update(await self.store.get_profile_fields(user))