element-hq / element-hq/synapse
URL preview not working with raw IPv6 addresses
- Dominant language
- Python
- Stars
- 4.6k
- Forks
- 600
- Avg merge
- 5d 22h
- Merged PRs (30d)
- 51
Description
### Description
Synapse fails to generate URL previews for valid IPv6 URLs. When a URL contains a correctly formatted IPv6 literal inside square brackets (for example: `http://[201:fdd3:b236:edda:67f5:ff3c:af8d:4132]/`), Synapse removes the brackets and attempts to apply IDNA encoding to the raw IPv6 address. Since IPv6 literals contain characters that are not valid in domain names (such as `:`), the idna library raises an `InvalidCodepoint` exception.
According to RFC 3986, IPv6 literals enclosed in `[` and `]` are not subject to IDNA processing and should be treated as numeric IP addresses. Synapse should detect this case and skip IDNA encoding.
### Steps to reproduce
- Try to preview raw IPv6 address:
```
curl 'https://homeserver/_matrix/media/r0/preview_url?url=http://%5B201:fdd3:b236:edda:67f5:ff3c:af8d:4132%5D&ts=1774786740000' -H 'Authorization: Bearer '
```
### Homeserver
Private homeserver
### Synapse Version
1.148.0
### Installation Method
Debian packages from packages.matrix.org
### Database
17.7 (Debian 17.7-0+deb13u1)
### Workers
Multiple workers
### Platform
Debian 13, VPS
### Configuration
```
url_preview_enabled: true
url_preview_ip_range_whitelist:
- '200::/7'
url_preview_ip_range_blacklist:
- "0.0.0.0/0"
```
### Relevant log output
```shell
2026-03-31 16:11:23,750 - synapse.http.client - 402 - DEBUG - Sending request GET http://[201:fdd3:b236:edda:67f5:ff3c:af8d:4132]
2026-03-31 16:11:23,751 - synapse.http.client - 471 - INFO - Error sending request to GET http://[201:fdd3:b236:edda:67f5:ff3c:af8d:4132]: InvalidCodepoint Codepoint U+003A at position 4 of '201:fdd3:b236:edda:67f5:ff3c:af8d:4132' not allowed
2026-03-31 16:11:23,751 - synapse.http.server - 131 - INFO - SynapseError: 500 - Failed to download content: ["idna.core.InvalidCodepoint: Codepoint U+003A at position 4 of '201:fdd3:b236:edda:67f5:ff3c:af8d:4132' not allowed\n"]
```
### Anything else that would be useful to know?
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.