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: createActionURL set detectedProtocol correctly #10421

Merged
merged 2 commits into from
Mar 31, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/core/src/lib/utils/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ export function createActionURL(
const detectedHost = headers.get("x-forwarded-host") ?? headers.get("host")
const detectedProtocol =
headers.get("x-forwarded-proto") ?? protocol ?? "https"

url = new URL(`${detectedProtocol}://${detectedHost}`)
const _protocol = detectedProtocol.endsWith(":") ? detectedProtocol : detectedProtocol + ':'

url = new URL(`${_protocol}//${detectedHost}`)
}

// remove trailing slash
Expand Down
52 changes: 51 additions & 1 deletion packages/core/test/env.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describe("config is inferred from environment variables", () => {
})

describe("createActionURL", () => {
const consoleWarnSpy = vi.spyOn(console, "warn").mockImplementation(() => { })
const consoleWarnSpy = vi.spyOn(console, "warn").mockImplementation(() => {})

afterEach(() => {
consoleWarnSpy.mockClear()
Expand Down Expand Up @@ -161,6 +161,56 @@ describe("createActionURL", () => {
},
expected: "https://example.com/auth/signin",
},
{
args: {
action: "signin",
protocol: "http:",
headers: new Headers({
"x-forwarded-host": "example.com",
}),
env: {},
basePath: "/auth",
},
expected: "http://example.com/auth/signin",
},
{
args: {
action: "signin",
protocol: "https:",
headers: new Headers({
"x-forwarded-host": "example.com",
}),
env: {},
basePath: "/auth",
},
expected: "https://example.com/auth/signin",
},
{
args: {
action: "signin",
protocol: undefined,
headers: new Headers({
"x-forwarded-host": "example.com",
"x-forwarded-proto": "https",
}),
env: {},
basePath: "/auth",
},
expected: "https://example.com/auth/signin",
},
{
args: {
action: "signin",
protocol: undefined,
headers: new Headers({
"x-forwarded-host": "example.com",
"x-forwarded-proto": "http",
}),
env: {},
basePath: "/auth",
},
expected: "http://example.com/auth/signin",
},
{
args: {
action: "signout",
Expand Down