From 49cfa96cc51f9618be34d80d16ba7ed534cf339f Mon Sep 17 00:00:00 2001 From: Pierre Gayvallet Date: Fri, 12 Jul 2024 12:03:28 +0200 Subject: [PATCH] `ssl.redirectHttpFromPort`: use host from request instead of config (#188088) ## Summary Fix https://github.com/elastic/kibana/issues/24870 --- .../src/https_redirect_server.test.ts | 11 +++++++++++ .../src/https_redirect_server.ts | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/core/http/core-http-server-internal/src/https_redirect_server.test.ts b/packages/core/http/core-http-server-internal/src/https_redirect_server.test.ts index 6050d86ded357..3123fe8bba06c 100644 --- a/packages/core/http/core-http-server-internal/src/https_redirect_server.test.ts +++ b/packages/core/http/core-http-server-internal/src/https_redirect_server.test.ts @@ -96,3 +96,14 @@ test('forwards http requests to https', async () => { expect(res.header.location).toEqual(`https://${config.host}:${config.port}/`); }); }); + +test('keeps the request host when redirecting', async () => { + await server.start(config); + + await supertest(`http://localhost:${config.ssl.redirectHttpFromPort}`) + .get('/') + .expect(302) + .then((res) => { + expect(res.header.location).toEqual(`https://localhost:${config.port}/`); + }); +}); diff --git a/packages/core/http/core-http-server-internal/src/https_redirect_server.ts b/packages/core/http/core-http-server-internal/src/https_redirect_server.ts index 2999c4aaf734e..e621b864fa075 100644 --- a/packages/core/http/core-http-server-internal/src/https_redirect_server.ts +++ b/packages/core/http/core-http-server-internal/src/https_redirect_server.ts @@ -40,7 +40,7 @@ export class HttpsRedirectServer { return responseToolkit .redirect( formatUrl({ - hostname: config.host, + hostname: request.url.hostname, pathname: request.url.pathname, port: config.port, protocol: 'https',