Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Unexplained KeyError 'destination_is' #12690

Closed
DMRobertson opened this issue May 10, 2022 · 1 comment · Fixed by #13041
Closed

Unexplained KeyError 'destination_is' #12690

DMRobertson opened this issue May 10, 2022 · 1 comment · Fixed by #13041
Labels
P4 (OBSOLETE: use S- labels.) Okay backlog: will not schedule, will accept patches S-Minor Blocks non-critical functionality, workarounds exist. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues.

Comments

@DMRobertson
Copy link
Contributor

Internal users: https://sentry.matrix.org/sentry/synapse-matrixorg/issues/247960/?query=is%3Aunresolved%20destination_is

StopIteration: DestinationRetryTimings(failure_ts=1568794598907, retry_last_ts=1591706354703, retry_interval=126355483270)
  File "twisted/internet/defer.py", line 1660, in _inlineCallbacks
    result = current_context.run(gen.send, result)

StopIteration: DestinationRetryTimings(failure_ts=1568794598907, retry_last_ts=1591706354703, retry_interval=126355483270)
  File "twisted/internet/defer.py", line 1660, in _inlineCallbacks
    result = current_context.run(gen.send, result)

KeyError: 'destination_is'
  File "synapse/http/server.py", line 298, in _async_render_wrapper
    callback_return = await self._async_render(request)
  File "synapse/http/server.py", line 500, in _async_render
    callback_return = await raw_callback_return
  File "synapse/rest/client/directory.py", line 57, in on_GET
    res = await self.directory_handler.get_association(room_alias_obj)
  File "synapse/handlers/directory.py", line 257, in get_association
    ignore_backoff=True,
  File "synapse/federation/federation_client.py", line 184, in make_query
    ignore_backoff=ignore_backoff,
  File "synapse/federation/transport/client.py", line 272, in make_query
    ignore_backoff=ignore_backoff,
  File "synapse/http/matrixfederationclient.py", line 1068, in get_json
    timeout=timeout,
  File "synapse/http/matrixfederationclient.py", line 389, in _send_request_with_optional_trailing_slash
    response = await self._send_request(request, **send_request_args)
  File "synapse/http/matrixfederationclient.py", line 540, in _send_request
    destination_bytes, method_bytes, url_to_sign_bytes
  File "synapse/http/matrixfederationclient.py", line 748, in build_auth_headers
    request.get("destination") or request["destination_is"],

def build_auth_headers(
self,
destination: Optional[bytes],
method: bytes,
url_bytes: bytes,
content: Optional[JsonDict] = None,
destination_is: Optional[bytes] = None,
) -> List[bytes]:
"""
Builds the Authorization headers for a federation request
Args:
destination: The destination homeserver of the request.
May be None if the destination is an identity server, in which case
destination_is must be non-None.
method: The HTTP method of the request
url_bytes: The URI path of the request
content: The body of the request
destination_is: As 'destination', but if the destination is an
identity server
Returns:
A list of headers to be added as "Authorization:" headers
"""
if destination is None and destination_is is None:
raise ValueError("destination and destination_is cannot both be None!")
request: JsonDict = {
"method": method.decode("ascii"),
"uri": url_bytes.decode("ascii"),
"origin": self.server_name,
}
if destination is not None:
request["destination"] = destination.decode("ascii")
if destination_is is not None:
request["destination_is"] = destination_is.decode("ascii")
if content is not None:
request["content"] = content
request = sign_json(request, self.server_name, self.signing_key)
auth_headers = []
for key, sig in request["signatures"][self.server_name].items():
auth_headers.append(
(
'X-Matrix origin=%s,key="%s",sig="%s",destination="%s"'
% (
self.server_name,
key,
sig,
request.get("destination") or request["destination_is"],
)
).encode("ascii")
)
return auth_headers

There's logic which is trying to assert we've provided sensible input, but it's failing. I'd guess that destination is an empty bytes object?

@DMRobertson DMRobertson added S-Minor Blocks non-critical functionality, workarounds exist. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues. P4 (OBSOLETE: use S- labels.) Okay backlog: will not schedule, will accept patches labels May 10, 2022
@b3s1r
Copy link

b3s1r commented Jun 10, 2022

Yes that seems to be the problem.
I got that error when I tried to GET /_matrix/client/r0/profile/{userId} on my server.
I used it wrong and didn't put the domain in the {userId}. (so just /%40user%3A and not /%40user%3Aexample.com
That caused destination not to be None, but an empty object.

Not sure if this is helpful in any way, but it was my evening. So there you go.

clokep referenced this issue Jun 29, 2022
Co-authored-by: Jan Christian Grünhage <jan.christian@gruenhage.xyz>
Co-authored-by: Marcus Hoffmann <bubu@bubu1.eu>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P4 (OBSOLETE: use S- labels.) Okay backlog: will not schedule, will accept patches S-Minor Blocks non-critical functionality, workarounds exist. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants