diff --git a/src/plugins/console/server/lib/proxy_request.ts b/src/plugins/console/server/lib/proxy_request.ts index 4c6c7c21f32a4..fb07b7c49a003 100644 --- a/src/plugins/console/server/lib/proxy_request.ts +++ b/src/plugins/console/server/lib/proxy_request.ts @@ -34,6 +34,13 @@ interface Args { rejectUnauthorized?: boolean; } +/** + * Node http request library does not expect there to be trailing "[" or "]" + * characters in ipv6 host names. + */ +const sanitizeHostname = (hostName: string): string => + hostName.trim().replace(/^\[/, '').replace(/\]$/, ''); + // We use a modified version of Hapi's Wreck because Hapi, Axios, and Superagent don't support GET requests // with bodies, but ES APIs do. Similarly with DELETE requests with bodies. Another library, `request` // diverged too much from current behaviour. @@ -67,7 +74,7 @@ export const proxyRequest = ({ method: method.toUpperCase(), // We support overriding this on a per request basis to support legacy proxy config. See ./proxy_config. rejectUnauthorized: typeof rejectUnauthorized === 'boolean' ? rejectUnauthorized : undefined, - host: hostname, + host: sanitizeHostname(hostname), port: port === '' ? undefined : parseInt(port, 10), protocol, path: `${pathname}${search || ''}`,