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

Check x-forwarded-host before host for support reverse proxy defaults #4928

Merged
merged 8 commits into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 5 additions & 0 deletions .changeset/fast-meals-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/auth': minor
---

Check x-forwarded-host before host for support reverse proxy defaults
3 changes: 2 additions & 1 deletion packages-next/auth/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,11 @@ export function createAuth<GeneratedListTypes extends BaseGeneratedListTypes>({
// Allow access to the adminMeta data from the /init path to correctly render that page
// even if the user isn't logged in (which should always be the case if they're seeing /init)
const headers = context.req?.headers;
const host = headers ? headers['x-forwarded-host'] || headers.host : null;
const url = headers?.referer ? new URL(headers.referer) : undefined;
const accessingInitPage =
url?.pathname === '/init' &&
url?.host === headers?.host &&
url?.host === host &&
(await context.sudo().lists[listKey].count({})) === 0;
return (
accessingInitPage ||
Expand Down