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

fix: Fix Issue #63 to properly set the x-forwarded-host header #64

Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.15.4 (tbd)

- Fixed the `x-forwarded-host` header value

## 0.15.3

- Added possibility to specify multiple headers or query parameters
Expand Down
12 changes: 11 additions & 1 deletion docs/proxy-injector.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@ interface ProxyInjectorConfiguration {
active?: boolean;
agentOptions?: any;
proxy?: any;
xfwd?: boolean;
defaultHeaders?: Array<string>;
discardHeaders?: Array<string>;
permitHeaders?: Array<string>;
injectHeaders?: Record<string, string>;
followRedirect?: boolean;
}
```

The mapping is already a general configuration, as the targets need to be known as well as their usual counterparts (e.g., to identify the correct URLs in an HAR file). The `agentOptions` can be used to specify more sophisticated options for the proxyed request (e.g., which ciphers to use). The `proxy` option allows us to set a (corporate?) proxy to be used on the local machine (oh the irony - a proxy server that allows setting another proxy ...).

While the `defaultHeaders` provide a way to override the used default set of headers, `permitHeaders` are for explicitly allowing non-default headers and `discardHeaders` may be used to define which headers should never be considered.
While the `defaultHeaders` provide a way to override the used default set of headers, `permitHeaders` are for explicitly allowing non-default headers and `discardHeaders` may be used to define which headers should never be considered, and `injectHeaders` may be used to create or override headers with custom values.

If not explicitly specified the default headers are defined to be:

Expand All @@ -50,3 +52,11 @@ const defaultProxyHeaders = [
'range',
];
```

The `xfwd` option will create the following headers:
- x-forwarded-for
- x-forwarded-host
- x-forwarded-port
- x-forwarded-proto

and set the header values as derived from the original request. The `x-forwarded-host` header will contain the request's `host` header value, which may include a port number.
2 changes: 1 addition & 1 deletion src/server/injectors/proxy-injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export default class ProxyInjector implements KrasInjector {

if (this.config.xfwd) {
integrateXfwd(headers, protocol, req);
headers['x-forwarded-host'] = headers['x-forwarded-host'] || headers.host || '';
headers['x-forwarded-host'] = headers['x-forwarded-host'] || req.headers.host || '';
}

return headers;
Expand Down
Loading