element-hq / element-hq/synapse

Federation .well-known requests don't follow 308 redirects

Open
#8,098 0 comments 0 reactions 0 assignees View on GitHub
A-Federation z-bug Z-Upstream-Bug
Dominant language
Python
Stars
4.6k
Forks
600
Avg merge
5d 22h
Merged PRs (30d)
51

Description

This issue has been migrated from [#8098](https://github.com/matrix-org/synapse/issues/8098).

---

### Description

Synapse does not follow HTTP 308 (Permanent Redirect) redirects on .well-known files when resolving hosts for federation.

The problem seems to be that Synapse [uses Twisted's RedirectAgent for handling .well-known redirects](https://github.com/matrix-org/synapse/blob/v1.18.0/synapse/http/federation/well_known_resolver.py#L100), which for whatever reason [doesn't follow 308 redirects](https://github.com/twisted/twisted/blob/twisted-20.3.0/src/twisted/web/client.py#L2116-L2117)

### Steps to reproduce

- Set up a server with .well-known delegation behind a 308 redirect
- Try to federate with that server

Expected result: federation works fine
Actual result: other servers will fail to fetch the .well-known and fall back to 8448, leading to federation not working

```
2020-08-07 21:50:39,593 - synapse.http.matrixfederationclient - 414 - INFO - GET-1685382- {GET-O-838751} [onscale.co.nz] Sending request: GET matrix://onscale.co.nz/_matrix/key/v2/server/ed25519%3Aa_YoJp; timeout 10.000000s
2020-08-07 21:50:39,594 - synapse.http.federation.well_known_resolver - 245 - INFO - GET-1685382- Fetching https://onscale.co.nz/.well-known/matrix/server
2020-08-07 21:50:40,851 - synapse.http.federation.well_known_resolver - 192 - INFO - GET-1685382- Error parsing well-known for b'onscale.co.nz': Non-200 response 308
2020-08-07 21:50:40,913 - synapse.http.federation.matrix_federation_agent - 250 - INFO - GET-1685382- Connecting to onscale.co.nz:8448
2020-08-07 21:50:49,598 - synapse.http.federation.matrix_federation_agent - 261 - INFO - GET-1685382- Failed to connect to onscale.co.nz:8448: HostnameAddress(hostname=b'onscale.co.nz', port=8448)
```

### Version information

- **Version**: 1.18

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.