Skip to content

Commit 246a838

Browse files
fix(core): createActionURL set detectedProtocol correctly (#10421)
* fix: possible invalid url in createActionURL * fix: x-forwarded-proto goes without colon
1 parent 11cfb0a commit 246a838

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

packages/core/src/lib/utils/env.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ export function createActionURL(
7676
const detectedHost = headers.get("x-forwarded-host") ?? headers.get("host")
7777
const detectedProtocol =
7878
headers.get("x-forwarded-proto") ?? protocol ?? "https"
79-
80-
url = new URL(`${detectedProtocol}://${detectedHost}`)
79+
const _protocol = detectedProtocol.endsWith(":") ? detectedProtocol : detectedProtocol + ':'
80+
81+
url = new URL(`${_protocol}//${detectedHost}`)
8182
}
8283

8384
// remove trailing slash

packages/core/test/env.test.ts

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ describe("config is inferred from environment variables", () => {
108108
})
109109

110110
describe("createActionURL", () => {
111-
const consoleWarnSpy = vi.spyOn(console, "warn").mockImplementation(() => { })
111+
const consoleWarnSpy = vi.spyOn(console, "warn").mockImplementation(() => {})
112112

113113
afterEach(() => {
114114
consoleWarnSpy.mockClear()
@@ -161,6 +161,56 @@ describe("createActionURL", () => {
161161
},
162162
expected: "https://example.com/auth/signin",
163163
},
164+
{
165+
args: {
166+
action: "signin",
167+
protocol: "http:",
168+
headers: new Headers({
169+
"x-forwarded-host": "example.com",
170+
}),
171+
env: {},
172+
basePath: "/auth",
173+
},
174+
expected: "http://example.com/auth/signin",
175+
},
176+
{
177+
args: {
178+
action: "signin",
179+
protocol: "https:",
180+
headers: new Headers({
181+
"x-forwarded-host": "example.com",
182+
}),
183+
env: {},
184+
basePath: "/auth",
185+
},
186+
expected: "https://example.com/auth/signin",
187+
},
188+
{
189+
args: {
190+
action: "signin",
191+
protocol: undefined,
192+
headers: new Headers({
193+
"x-forwarded-host": "example.com",
194+
"x-forwarded-proto": "https",
195+
}),
196+
env: {},
197+
basePath: "/auth",
198+
},
199+
expected: "https://example.com/auth/signin",
200+
},
201+
{
202+
args: {
203+
action: "signin",
204+
protocol: undefined,
205+
headers: new Headers({
206+
"x-forwarded-host": "example.com",
207+
"x-forwarded-proto": "http",
208+
}),
209+
env: {},
210+
basePath: "/auth",
211+
},
212+
expected: "http://example.com/auth/signin",
213+
},
164214
{
165215
args: {
166216
action: "signout",

0 commit comments

Comments
 (0)