Skip to content

Commit b800720

Browse files
Change cookieJarSizeTest depending on type of cookie
1 parent 4d1ffc6 commit b800720

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/server/session/stateless-session-store.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,32 +118,42 @@ export class StatelessSessionStore extends AbstractSessionStore {
118118
reqCookies: cookies.RequestCookies,
119119
resCookies: cookies.ResponseCookies,
120120
session: JWTPayload,
121-
sessionCookieName: string,
121+
cookieName: string,
122122
maxAge: number
123123
) {
124124
const jwe = await cookies.encrypt(session, this.secret);
125125

126126
const cookieValue = jwe.toString();
127127

128-
resCookies.set(sessionCookieName, jwe.toString(), {
128+
resCookies.set(cookieName, jwe.toString(), {
129129
...this.cookieConfig,
130130
maxAge
131131
});
132132
// to enable read-after-write in the same request for middleware
133-
reqCookies.set(sessionCookieName, cookieValue);
133+
reqCookies.set(cookieName, cookieValue);
134134

135135
// check if the session cookie size exceeds 4096 bytes, and if so, log a warning
136136
const cookieJarSizeTest = new cookies.ResponseCookies(new Headers());
137-
cookieJarSizeTest.set(sessionCookieName, cookieValue, {
137+
cookieJarSizeTest.set(cookieName, cookieValue, {
138138
...this.cookieConfig,
139139
maxAge
140140
});
141+
141142
if (new TextEncoder().encode(cookieJarSizeTest.toString()).length >= 4096) {
142-
console.warn(
143-
"The session cookie size exceeds 4096 bytes, which may cause issues in some browsers. " +
144-
"Consider removing any unnecessary custom claims from the access token or the user profile. " +
145-
"Alternatively, you can use a stateful session implementation to store the session data in a data store."
146-
);
143+
// if the cookie is the session cookie, log a warning with additional information about the claims and user profile.
144+
if (cookieName === this.sessionCookieName) {
145+
console.warn(
146+
`The ${cookieName} cookie size exceeds 4096 bytes, which may cause issues in some browsers. ` +
147+
"Consider removing any unnecessary custom claims from the access token or the user profile. " +
148+
"Alternatively, you can use a stateful session implementation to store the session data in a data store."
149+
);
150+
} else {
151+
console.warn(
152+
`The ${cookieName} cookie size exceeds 4096 bytes, which may cause issues in some browsers. ` +
153+
"You can use a stateful session implementation to store the session data in a data store."
154+
);
155+
}
156+
147157
}
148158
}
149159

0 commit comments

Comments
 (0)