From bfad87aae8438a536800ff720acb280ffb303200 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Tue, 16 Nov 2021 10:44:08 -0800 Subject: [PATCH] http: Don't set X-Forwarded-Proto when using a reverse proxy Discussion on Ia16d8f86b1cb20 indicates that we want to go in the other direction - MediaWiki shouldn't set X-Forwarded-Proto, rather the reverse proxy (envoy in Wikimedia's case) should set it. This follows-up cc241c2add4ebdd. Bug: T288848 Change-Id: Ifc5e9da9a02b45d9d1ad51c3e1389f9ac7325c86 --- includes/http/MWHttpRequest.php | 3 --- tests/phpunit/includes/http/MWHttpRequestTest.php | 1 - 2 files changed, 4 deletions(-) diff --git a/includes/http/MWHttpRequest.php b/includes/http/MWHttpRequest.php index ef1025accf8..531b5b051f7 100644 --- a/includes/http/MWHttpRequest.php +++ b/includes/http/MWHttpRequest.php @@ -264,9 +264,6 @@ abstract class MWHttpRequest implements LoggerAwareInterface { } // Set the current host in the Host header $this->setHeader( 'Host', $this->parsedUrl['host'] ); - // Set current protocol in X-Forwarded-Proto - // TODO: consider supporting the standardized "Forwarded" header too - $this->setHeader( 'X-Forwarded-Proto', $this->parsedUrl['scheme'] ); // Replace scheme, host and port in the request $this->parsedUrl['scheme'] = $parsedProxy['scheme']; $this->parsedUrl['host'] = $parsedProxy['host']; diff --git a/tests/phpunit/includes/http/MWHttpRequestTest.php b/tests/phpunit/includes/http/MWHttpRequestTest.php index fffb1f58cff..622b5680795 100644 --- a/tests/phpunit/includes/http/MWHttpRequestTest.php +++ b/tests/phpunit/includes/http/MWHttpRequestTest.php @@ -94,7 +94,6 @@ class MWHttpRequestTest extends PHPUnit\Framework\TestCase { $req->setReverseProxy( 'http://localhost:1234' ); $this->assertSame( 'http://localhost:1234/path?query=string', $req->url ); $this->assertSame( 'example.org', $req->reqHeaders['Host'] ); - $this->assertSame( 'https', $req->reqHeaders['X-Forwarded-Proto'] ); } }