Add referer to remote media requests. (#8135)
authorsofar <sofar+github@foo-projects.org>
Tue, 5 Mar 2019 07:12:02 +0000 (23:12 -0800)
committerLoïc Blot <nerzhul@users.noreply.github.com>
Tue, 5 Mar 2019 07:12:02 +0000 (08:12 +0100)
This sends the following header to a remote media server:

    Referer: minetest://<server_name>:port

This was verified with CTF and the Minetest Public Remove Media
server. If the servername was a plain IPv6 address it will
contain `:` characters and will be encapsulated in `[]` to
be a valid URI.

src/client/clientmedia.cpp

index e3ad92dbcddc646e5d6cf8fe3eb0a3848b416cb0..e52ebcab3c03b167dac046d3510328bf663c44b2 100644 (file)
@@ -254,6 +254,16 @@ void ClientMediaDownloader::initialStep(Client *client)
                        fetch_request.post_data = required_hash_set;
                        fetch_request.extra_headers.emplace_back(
                                "Content-Type: application/octet-stream");
+
+                       // Encapsulate possible IPv6 plain address in []
+                       std::string addr = client->getAddressName();
+                       if (addr.find(":", 0) != std::string::npos)
+                               addr = '[' + addr + ']';
+                       fetch_request.extra_headers.emplace_back(
+                               std::string("Referer: minetest://") +
+                               addr + ":" +
+                               std::to_string(client->getServerAddress().getPort()));
+
                        httpfetch_async(fetch_request);
 
                        m_httpfetch_active++;