Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Console] Scrub the lead and trailing brackets from ipv6 host names #68991

Merged
merged 4 commits into from
Jun 15, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 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,16 @@ interface Args {
rejectUnauthorized?: boolean;
}

/**
* Node http request library does not expect there to be trailing "[" or "]"
jloleysens marked this conversation as resolved.
Show resolved Hide resolved
* characters in ipv6 host names but the Node URL class with helpers (from the "url" module)
* does not scrub these from the "hostname" value.
*
* We do this just before sending the request.
*/
const scrubURLHostname = (hostName: string): string =>
jloleysens marked this conversation as resolved.
Show resolved Hide resolved
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 +77,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: scrubURLHostname(hostname),
port: port === '' ? undefined : parseInt(port, 10),
protocol,
path: `${pathname}${search || ''}`,
Expand Down