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

server_name is not correctly validated for join requests #7108

Open
grinapo opened this issue Mar 19, 2020 · 7 comments
Open

server_name is not correctly validated for join requests #7108

grinapo opened this issue Mar 19, 2020 · 7 comments
Labels
A-Validation 500 (mostly) errors due to lack of event/parameter validation z-bug (Deprecated Label) z-p2 (Deprecated Label)

Comments

@grinapo
Copy link

grinapo commented Mar 19, 2020

Description

Caused #4891 but is a problem by itself, too.

2020-03-19 16:02:39,463 - synapse.http.matrixfederationclient - 491 - WARNING - POST-591111- {GET-O-12659} [!NEdKsYgzazXzpqqeBT:grin.hu] Request failed: GET matrix://!NEdKsYgzazXzpqqeBT:grin.hu/_matrix/federation/v1/make_join/%21NEdKsYgzazXzpqqeBT%3Agrin.hu/%40grin%3Agrin.hu?ver=1&ver=2&ver=3&ver=4&ver=5&ver=org.matrix.msc2260: ValueError("invalid literal for int() with base 10: b'grin.hu'")

2020-03-19 16:02:39,463 - synapse.util.retryutils - 218 - INFO - POST-591111- Connection to !NEdKsYgzazXzpqqeBT:grin.hu was unsuccessful (<class 'synapse.api.errors.RequestSendFailed'>(Failed to send request: ValueError: invalid literal for int() with base 10: b'grin.hu')); backoff now 600000

2020-03-19 16:02:39,464 - synapse.federation.federation_client - 421 - WARNING - POST-591111- Failed to make_join via !NEdKsYgzazXzpqqeBT:grin.hu

2020-03-19 16:02:39,465 - synapse.http.server - 81 - INFO - POST-591111- <XForwardedForRequest at 0x7f49810bc128 method='POST' uri='/_matrix/client/r0/join/!NEdKsYgzazXzpqqeBT%3Agrin.hu?server_name=%21NEdKsYgzazXzpqqeBT%3Agrin.hu' clientproto='HTTP/1.1' site=8008> SynapseError: 502 - Failed to make_join via any server

Steps to reproduce

I don't know, I only became aware of this when it completely broke communities.

Version information

  • Homeserver:
    matrix.grin.hu

  • Version:
    v1.11.1-1 (debian)

  • Install method:
    debian experimental repo.

  • Platform:
    Debian/Sid/x64

@richvdh
Copy link
Member

richvdh commented Mar 19, 2020

looks like you're trying to send a join request to a server called !NEdKsYgzazXzpqqeBT:grin.hu (which is of course not a valid server name: the error comes because it is trying to interpret the bit after the : as a port number).

Can you share all the logs for POST-591111

@grinapo
Copy link
Author

grinapo commented Mar 19, 2020

2020-03-19 16:02:39,462 - synapse.http.matrixfederationclient - 408 - INFO - POST-591111- {GET-O-12659} [!NEdKsYgzazXzpqqeBT:grin.hu] Sending request: GET matrix://!NEdKsYgzazXzpqqeBT:grin.hu/_matrix/federation/v1/make_join/%21NEdKsYgzazXzpqqeBT%3Agrin.hu/%40grin%3Agrin.hu?ver=1&ver=2&ver=3&ver=4&ver=5&ver=org.matrix.msc2260; timeout 20.000000s
2020-03-19 16:02:39,462 - synapse.http.matrixfederationclient - 434 - INFO - POST-591111- Failed to send request: invalid literal for int() with base 10: b'grin.hu'
2020-03-19 16:02:39,463 - synapse.http.matrixfederationclient - 491 - WARNING - POST-591111- {GET-O-12659} [!NEdKsYgzazXzpqqeBT:grin.hu] Request failed: GET matrix://!NEdKsYgzazXzpqqeBT:grin.hu/_matrix/federation/v1/make_join/%21NEdKsYgzazXzpqqeBT%3Agrin.hu/%40grin%3Agrin.hu?ver=1&ver=2&ver=3&ver=4&ver=5&ver=org.matrix.msc2260: ValueError("invalid literal for int() with base 10: b'grin.hu'")
2020-03-19 16:02:39,463 - synapse.util.retryutils - 218 - INFO - POST-591111- Connection to !NEdKsYgzazXzpqqeBT:grin.hu was unsuccessful (<class 'synapse.api.errors.RequestSendFailed'>(Failed to send request: ValueError: invalid literal for int() with base 10: b'grin.hu')); backoff now 600000
2020-03-19 16:02:39,464 - synapse.federation.federation_client - 421 - WARNING - POST-591111- Failed to make_join via !NEdKsYgzazXzpqqeBT:grin.hu
2020-03-19 16:02:39,465 - synapse.http.server - 81 - INFO - POST-591111- <XForwardedForRequest at 0x7f49810bc128 method='POST' uri='/_matrix/client/r0/join/!NEdKsYgzazXzpqqeBT%3Agrin.hu?server_name=%21NEdKsYgzazXzpqqeBT%3Agrin.hu' clientproto='HTTP/1.1' site=8008> SynapseError: 502 - Failed to make_join via any server
2020-03-19 16:02:39,466 - synapse.access.http.8008 - 302 - INFO - POST-591111- 2a01:5d0:2:100::1001 - 8008 - {@grin:grin.hu} Processed request: 0.490sec/0.001sec (0.011sec, 0.002sec) (0.014sec/0.433sec/7) 84B 502 "POST /_matrix/client/r0/join/!NEdKsYgzazXzpqqeBT%3Agrin.hu?server_name=%21NEdKsYgzazXzpqqeBT%3Agrin.hu HTTP/1.1" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.116 Safari/537.36" [3 dbevts]

@richvdh
Copy link
Member

richvdh commented Mar 19, 2020

ok so the problem there is the faulty server_name in the request. Sounds a bit like a client issue to me. What are you doing in the client to cause it to send that request?

@richvdh richvdh changed the title ValueError("invalid literal for int() with base 10: b'grin.hu'") server_name is not correctly validated for join requests Mar 19, 2020
@grinapo
Copy link
Author

grinapo commented Mar 19, 2020

Someone haev created a room with alias, and requested the room to be added to a community. It was added, somehow, probably by using the alias, and my guess is that it was not in the expected form. But it seems to have been added despite all the problems (if there was any), but killed off the community immediately.

The error above was me trying to join the room I got from the group_rooms table.

So maybe the root of the problem was that synapse allowed rubbish to be added into a community.

It's probably not a real bug if riotweb allows the user to try to join any crap address (shall try and fail) but synapse probably shouldn't choke on the validity check.

@thegcat
Copy link
Contributor

thegcat commented Apr 25, 2020

I'm seeing a similar issue. I tried to /j !syHhCrpMpRzCdwgFZa:matrix.org from Riot/Firefox/macOS which resulted in the above issue. I was trying to rejoin that room because of #4891, for which I can now provide an explanation, but that is out of scope here :-)

Rejoining the room via an alias for example using /j #freenode_#kif:matrix.org from the same Riot/Firefox/macOS worked fine, this seems to be an issue with joining rooms by their ID, not a fundamental problem with joining rooms.

As the URI for the POST is /_matrix/client/r0/join/!syHhCrpMpRzCdwgFZa%3Amatrix.org?server_name=%21syHhCrpMpRzCdwgFZa%3Amatrix.org this looks to be an issue in Riot not extracting the server name from the room ID correctly?

Log excerpt:

Apr 25 21:40:27 kif-matrix matrix-synapse[16017]: 2020-04-25 21:40:27,631 - synapse.federation.federation_client - 499 - WARNING - POST-232771 - Failed to make_join via !syHhCrpMpRzCdwgFZa:matrix.org
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]: Traceback (most recent call last):
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:   File "/opt/venvs/matrix-synapse/lib/python3.7/site-packages/twisted/internet/defer.py", line 1418, in _inlineCallbacks
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:     result = g.send(result)
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]: StopIteration: {'destination': '!syHhCrpMpRzCdwgFZa:matrix.org', 'failure_ts': 1587843483700, 'retry_last_ts': 1587843483700, 'retry_interval': 600000}
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]: During handling of the above exception, another exception occurred:
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]: Traceback (most recent call last):
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:   File "/opt/venvs/matrix-synapse/lib/python3.7/site-packages/twisted/internet/defer.py", line 1418, in _inlineCallbacks
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:     result = g.send(result)
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]: StopIteration: {'destination': '!syHhCrpMpRzCdwgFZa:matrix.org', 'failure_ts': 1587843483700, 'retry_last_ts': 1587843483700, 'retry_interval': 600000}
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]: During handling of the above exception, another exception occurred:
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]: Traceback (most recent call last):
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:   File "/opt/venvs/matrix-synapse/lib/python3.7/site-packages/twisted/internet/defer.py", line 1418, in _inlineCallbacks
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:     result = g.send(result)
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]: StopIteration: {'destination': '!syHhCrpMpRzCdwgFZa:matrix.org', 'failure_ts': 1587843483700, 'retry_last_ts': 1587843483700, 'retry_interval': 600000}
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]: During handling of the above exception, another exception occurred:
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]: Traceback (most recent call last):
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:   File "/opt/venvs/matrix-synapse/lib/python3.7/site-packages/synapse/federation/federation_client.py", line 480, in _try_destination_list
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:     res = await callback(destination)
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:   File "/opt/venvs/matrix-synapse/lib/python3.7/site-packages/synapse/federation/federation_client.py", line 556, in send_request
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:     destination, room_id, user_id, membership, params
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:   File "/opt/venvs/matrix-synapse/lib/python3.7/site-packages/twisted/internet/defer.py", line 1416, in _inlineCallbacks
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:     result = result.throwExceptionIntoGenerator(g)
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:   File "/opt/venvs/matrix-synapse/lib/python3.7/site-packages/twisted/python/failure.py", line 512, in throwExceptionIntoGenerator
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:     return g.throw(self.type, self.value, self.tb)
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:   File "/opt/venvs/matrix-synapse/lib/python3.7/site-packages/synapse/federation/transport/client.py", line 240, in make_membership_event
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:     ignore_backoff=ignore_backoff,
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:   File "/opt/venvs/matrix-synapse/lib/python3.7/site-packages/twisted/internet/defer.py", line 1416, in _inlineCallbacks
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:     result = result.throwExceptionIntoGenerator(g)
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:   File "/opt/venvs/matrix-synapse/lib/python3.7/site-packages/twisted/python/failure.py", line 512, in throwExceptionIntoGenerator
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:     return g.throw(self.type, self.value, self.tb)
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:   File "/opt/venvs/matrix-synapse/lib/python3.7/site-packages/synapse/http/matrixfederationclient.py", line 780, in get_json
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:     timeout=timeout,
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:   File "/opt/venvs/matrix-synapse/lib/python3.7/site-packages/twisted/internet/defer.py", line 1416, in _inlineCallbacks
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:     result = result.throwExceptionIntoGenerator(g)
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:   File "/opt/venvs/matrix-synapse/lib/python3.7/site-packages/twisted/python/failure.py", line 512, in throwExceptionIntoGenerator
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:     return g.throw(self.type, self.value, self.tb)
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:   File "/opt/venvs/matrix-synapse/lib/python3.7/site-packages/synapse/http/matrixfederationclient.py", line 246, in _send_request_with_optional_trailing_slash
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:     response = yield self._send_request(request, **send_request_args)
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:   File "/opt/venvs/matrix-synapse/lib/python3.7/site-packages/twisted/internet/defer.py", line 1416, in _inlineCallbacks
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:     result = result.throwExceptionIntoGenerator(g)
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:   File "/opt/venvs/matrix-synapse/lib/python3.7/site-packages/twisted/python/failure.py", line 512, in throwExceptionIntoGenerator
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:     return g.throw(self.type, self.value, self.tb)
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:   File "/opt/venvs/matrix-synapse/lib/python3.7/site-packages/synapse/http/matrixfederationclient.py", line 337, in _send_request
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:     ignore_backoff=ignore_backoff,
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:   File "/opt/venvs/matrix-synapse/lib/python3.7/site-packages/twisted/internet/defer.py", line 1418, in _inlineCallbacks
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:     result = g.send(result)
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:   File "/opt/venvs/matrix-synapse/lib/python3.7/site-packages/synapse/util/retryutils.py", line 101, in get_retry_limiter
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]:     destination=destination,
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]: synapse.util.retryutils.NotRetryingDestination: Not retrying server !syHhCrpMpRzCdwgFZa:matrix.org.
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]: 2020-04-25 21:40:27,633 - synapse.http.server - 81 - INFO - POST-232771 - <XForwardedForRequest at 0x7ff7deda4fd0 method='POST' uri='/_matrix/client/r0/join/!syHhCrpMpRzCdwgFZa%3Amatrix.org?server_name=%21syHhCrpMpRzCdwgFZa%3Amatrix.org' clientproto='HTTP/1.1' site=8008> SynapseError: 502 - Failed to make_join via any server
Apr 25 21:40:27 kif-matrix matrix-synapse[16017]: 2020-04-25 21:40:27,634 - synapse.access.http.8008 - 302 - INFO - POST-232771 - 129.217.6.212 - 8008 - {@thegcat:kif.rocks} Processed request: 0.012sec/0.000sec (0.001sec, 0.003sec) (0.002sec/0.004sec/4) 68B 502 "POST /_matrix/client/r0/join/!syHhCrpMpRzCdwgFZa%3Amatrix.org?server_name=%21syHhCrpMpRzCdwgFZa%3Amatrix.org HTTP/1.1" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:75.0) Gecko/20100101 Firefox/75.0" [0 dbevts]

@richvdh richvdh added z-bug (Deprecated Label) z-p2 (Deprecated Label) A-Validation 500 (mostly) errors due to lack of event/parameter validation labels Apr 28, 2020
@aaronraimist
Copy link
Contributor

Looks like #9161 may have fixed this

@aaronraimist
Copy link
Contributor

Oh I guess that was for a different API

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Validation 500 (mostly) errors due to lack of event/parameter validation z-bug (Deprecated Label) z-p2 (Deprecated Label)
Projects
None yet
Development

No branches or pull requests

4 participants