ffansbach / de-map

GNU General Public License v2.0
8 stars 8 forks source link

bug: Not detecting redirects in HTTP versions >HTTP/1.1 #41

Open xnumad opened 1 year ago

xnumad commented 1 year ago

Consequence by example

https://www.freifunk-karte.de/debug.php:

https://mesh.freifunknord.de/data/nodes.json returns no result

(which is false, as you can see when opening the URL yourself) As an eventual result, none of the nodes defined therein are in the map.

Core issue

Failing to parse lower case headers in HTTP versions >HTTP/1.1 A request to the URL from the example, https://mesh.freifunknord.de/data/nodes.json, has the response header location: https://map.freifunknord.de/data/nodes.json ("Freifunk Nord" is only an example Freifunk community affected by this, using HTTP/2, there are probably many other that are as well using HTTP versions newer than HTTP/1.1 on their web servers.)

This expression however is case-sensitive and expects capitalization: https://github.com/ffansbach/de-map/blob/dd683f197f12e85fe9d05db2070ed1e004587926/lib/CurlHelper.php#L53

Workaround

Force use of HTTP/1.1 use curl --http1.1 (actually, its equivalent option value for libcurl: CURLOPT_HTTP_VERSION=CURL_HTTP_VERSION_1_1) (Assuming the new web servers still support it, which is highly probable though.) (Although this might actually in turn break support for (Freifunk community) web servers not supporting HTTP/1.1, e.g. some only supporting HTTP/1.0. If there even are any such old servers used (by Freifunk communities).)

Quickest fix

Make the redirect parser work on the lowercase headers, simply by making it case-insensitive. For this, add an i after the closing / of the regular expression.

-                preg_match("/(Location:|URI:)[^(\n)]*/", $header, $matches);
+                preg_match("/(Location:|URI:)[^(\n)]*/i", $header, $matches);