Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ab87523

Browse files
Fix cookie domain when host has a port
1 parent 35830af commit ab87523

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

‎src/node/app/proxy.ts‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ export class ProxyHttpProvider extends HttpProvider implements HttpProxyProvider
6161
current = domain
6262
}
6363
})
64-
return current || host
64+
// Setting the domain to localhost doesn't seem to work for subdomains (for
65+
// example dev.localhost).
66+
return current && current !== "localhost" ? current : host
6567
}
6668

6769
public maybeProxyRequest(
@@ -90,12 +92,11 @@ export class ProxyHttpProvider extends HttpProvider implements HttpProxyProvider
9092
return undefined
9193
}
9294

93-
// At minimum there needs to be sub.domain.tld.
94-
const host = request.headers.host
95-
const parts = host && host.split(".")
96-
if (!parts || parts.length < 3) {
97-
return undefined
98-
}
95+
// Split into parts.
96+
const host = request.headers.host || ""
97+
const idx = host.indexOf(":")
98+
const domain = idx !== -1 ? host.substring(0, idx) : host
99+
const parts = domain.split(".")
99100

100101
// There must be an exact match.
101102
const port = parts.shift()

‎src/node/http.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,9 @@ export class HttpServer {
581581
this.heart.beat()
582582
const route = this.parseUrl(request)
583583
const write = (payload: HttpResponse): void => {
584+
const host = request.headers.host || ""
585+
const idx = host.indexOf(":")
586+
const domain = idx !== -1 ? host.substring(0, idx) : host
584587
response.writeHead(payload.redirect ? HttpCode.Redirect : payload.code || HttpCode.Ok, {
585588
"Content-Type": payload.mime || getMediaMime(payload.filePath),
586589
...(payload.redirect ? { Location: this.constructRedirect(request, route, payload as RedirectResponse) } : {}),
@@ -591,9 +594,7 @@ export class HttpServer {
591594
"Set-Cookie": [
592595
`${payload.cookie.key}=${payload.cookie.value}`,
593596
`Path=${normalize(payload.cookie.path || "/", true)}`,
594-
request.headers.host
595-
? `Domain=${(this.proxy && this.proxy.getCookieDomain(request.headers.host)) || request.headers.host}`
596-
: undefined,
597+
domain ? `Domain=${(this.proxy && this.proxy.getCookieDomain(domain)) || domain}` : undefined,
597598
// "HttpOnly",
598599
"SameSite=strict",
599600
]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /