Skip to content

Commit e339e00

Browse files
authored
Merge pull request #4642 from easyops-cn/steve/v3-secure-cookie
fix(): handle secure related cookie flags
2 parents 8812cea + 66940ed commit e339e00

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

packages/brick-container/serve/getProxy.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export default function getProxy(env, getRawIndexHtml) {
103103
return responseBuffer;
104104
}
105105

106+
// Add or clear secure related cookie flags
106107
const secureCookieFlags = [
107108
"SameSite=None",
108109
"Secure",
@@ -115,12 +116,19 @@ export default function getProxy(env, getRawIndexHtml) {
115116
req.path === "/next/api/auth/login/v2" &&
116117
Array.isArray(setCookies)
117118
) {
119+
// - If the server is https, but the local is http, clear the secure cookie flags;
120+
// - Otherwise, if the local is localhost and cookieSameSiteNone is enabled (default),
121+
// add the secure cookie flags;
122+
// - Otherwise, if the local is https, do nothing;
123+
// - Otherwise, clear the secure cookie flags;
118124
const strategy =
119-
env.cookieSameSiteNone && env.host === "localhost"
120-
? "add"
121-
: env.https
122-
? null
123-
: "clear";
125+
env.server.startsWith("https:") && !env.https
126+
? "clear"
127+
: env.cookieSameSiteNone && env.host === "localhost"
128+
? "add"
129+
: env.https
130+
? null
131+
: "clear";
124132
if (strategy) {
125133
// Note: it seems that now Chrome (v107) requires `SameSite=None` even for localhost.
126134
// However, `Secure` can use used with non-http for localhost.

0 commit comments

Comments
 (0)