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

url preview fails on IP addresses on py3 #4208

Closed
richvdh opened this issue Nov 20, 2018 · 2 comments
Closed

url preview fails on IP addresses on py3 #4208

richvdh opened this issue Nov 20, 2018 · 2 comments
Assignees

Comments

@richvdh
Copy link
Member

richvdh commented Nov 20, 2018

2018-11-20 11:58:46,190 - synapse.access.http.8085 - 233 - INFO - GET-10890 - 81.2.100.169 - 8085 - Received request: GET /_matrix/media/r0/preview_url?url=http://8.8.8.8
2018-11-20 11:58:46,269 - synapse.http.client - 96 - INFO - GET-10890 - Sending request GET http://8.8.8.8
2018-11-20 11:58:46,270 - synapse.http.client - 473 - INFO - GET-10890 - Getting endpoint for b'http://8.8.8.8'
2018-11-20 11:58:46,270 - synapse.http.client - 118 - INFO - GET-10890 - Error sending request to  GET http://8.8.8.8: TypeError a bytes-like object is required, not 'str'
2018-11-20 11:58:46,270 - synapse.rest.media.v1.preview_url_resource - 323 - WARNING - GET-10890 - Error downloading http://8.8.8.8: TypeError("a bytes-like object is required, not 'str'",)
2018-11-20 11:58:46,270 - synapse.http.server - 85 - INFO - GET-10890 - <XForwardedForRequest at 0x7ff7e8948a58 method='GET' uri='/_matrix/media/r0/preview_url?url=http://8.8.8.8' clientproto='HTTP/1.1' site=8085> SynapseError: 500 - Failed to download content: ["TypeError: a bytes-like object is required, not 'str'\n"]
2018-11-20 11:58:46,271 - synapse.access.http.8085 - 302 - INFO - GET-10890 - 81.2.100.169 - 8085 - {@richvdh:matrix.org} Processed request: 0.081sec/0.000sec (0.000sec, 0.000sec) (0.000sec/0.078sec/1) 138B 500 "GET /_matrix/media/r0/preview_url?url=http://8.8.8.8 HTTP/1.1" "curl/7.58.0" [0 dbevts]
@richvdh richvdh added the py3 label Nov 20, 2018
@richvdh richvdh changed the title url_preview fails on IP addresses on py3 url preview fails on IP addresses on py3 Nov 20, 2018
@richvdh
Copy link
Member Author

richvdh commented Dec 4, 2018

The problem here is:

  • twisted's URI object is defined such that its host is a bytes
  • twisted.web.client.Agent feeds the uri into the endpointForURI method of an EndpointFactory
  • SpiderEndpointFactory feeds uri.host into SpiderEndpoint's constructor
  • SpinderEndpoint.connect feeds it it into reactor.resolve, and thence to netaddr.ip.IPAddress.
  • reactor.resolve returns its input if the input is an IP address
  • netaddr.ip.IPAddress's constructor explodes horribly if given a bytes instead of a str.

It's a bit of a catalogue of fail, but the upshot seems to be that only previews of IP literal hostnames are affected, so this is probably not a hard blocker for 0.34.

@hawkowl
Copy link
Contributor

hawkowl commented Dec 21, 2018

Fixed by #4215

@hawkowl hawkowl closed this as completed Dec 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants