Skip to content

Commit

Permalink
[Console] Scrub the lead and trailing brackets from ipv6 host names (#…
Browse files Browse the repository at this point in the history
…68991) (#69150)

* scrub the lead and trailing brackets from ipv6 host names

* Update comment

* refactor: scrub -> sanitize

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
jloleysens and elasticmachine committed Jun 15, 2020
1 parent e931192 commit 9601b3e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/plugins/console/server/lib/proxy_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 || ''}`,
Expand Down

0 comments on commit 9601b3e

Please sign in to comment.