Skip to content

Commit ebe64b5

Browse files
authored
[server] Drop old cookie migration path (#19997)
1 parent d08a955 commit ebe64b5

File tree

2 files changed

+13
-32
lines changed

2 files changed

+13
-32
lines changed

components/server/src/session-handler.spec.db.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,27 +207,32 @@ describe("SessionHandler", () => {
207207
expect(res.cookie).to.be.undefined;
208208
});
209209
it("JWT cookie is present but invalid", async () => {
210-
const res = await handle(existingUser, "_gitpod_dev_jwt_=invalid");
210+
const res = await handle(undefined, "__Host-_gitpod_dev_jwt_=invalid");
211211
expect(res.status).to.equal(401);
212-
expect(res.value).to.equal("JWT Session is invalid");
212+
expect(res.value).to.equal("User has no valid session.");
213213
expect(res.cookie).to.be.undefined;
214214
});
215215

216-
it("old JWT cookie is present, is accepted (!), and we get a new one", async () => {
216+
it("old JWT cookie is ignored, new one is outdated and refreshed", async () => {
217217
const oldExpiredCookie = await sessionHandler.createJWTSessionCookie(existingUser.id, {
218218
issuedAtMs: Date.now() - SessionHandler.JWT_REFRESH_THRESHOLD - 1,
219219
});
220220
oldExpiredCookie.name = "_gitpod_dev_jwt_";
221-
const newCookie = await sessionHandler.createJWTSessionCookie(existingUser.id);
221+
const newCookie = await sessionHandler.createJWTSessionCookie(existingUser.id, {
222+
issuedAtMs: Date.now() - SessionHandler.JWT_REFRESH_THRESHOLD - 1,
223+
});
222224

223-
const res = await handle(existingUser, `${oldExpiredCookie.name}=${oldExpiredCookie.value}`);
225+
const res = await handle(
226+
existingUser,
227+
`${oldExpiredCookie.name}=${oldExpiredCookie.value}; ${newCookie.name}=${newCookie.value}`,
228+
);
224229
expect(res.status).to.equal(200);
225230
expect(res.value).to.equal("Refreshed JWT cookie issued.");
226231
expect(res.cookie).to.not.be.undefined;
227232
expect(res.cookie?.split("=")[0]).to.equal(newCookie.name);
228233
});
229234

230-
it("old expired AND new one JWT cookies are present, new one is accepted", async () => {
235+
it("ld JWT cookie is ignored, new one is accepted", async () => {
231236
const oldExpiredCookie = await sessionHandler.createJWTSessionCookie(existingUser.id, {
232237
issuedAtMs: Date.now() - SessionHandler.JWT_REFRESH_THRESHOLD - 1,
233238
});

components/server/src/session-handler.ts

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -154,19 +154,10 @@ export class SessionHandler {
154154

155155
/**
156156
* @param cookies
157-
* @returns Primary (the cookie name we set) AND secondary cookie (old accepted cookie name) values (in that order).
157+
* @returns Primary (the cookie name we set in config)
158158
*/
159159
private filterCookieValues(cookies: { [key: string]: string[] }): string[] {
160-
const cookieValues = cookies[getPrimaryJWTCookieName(this.config)] ?? [];
161-
162-
const secondaryCookieName = getSecondaryJWTCookieName(this.config);
163-
if (secondaryCookieName) {
164-
const secondaryCookieValues = cookies[secondaryCookieName];
165-
if (secondaryCookieValues) {
166-
cookieValues.push(...secondaryCookieValues);
167-
}
168-
}
169-
return cookieValues;
160+
return cookies[getPrimaryJWTCookieName(this.config)] ?? [];
170161
}
171162

172163
/**
@@ -239,28 +230,13 @@ export class SessionHandler {
239230
sameSite,
240231
secure,
241232
});
242-
243-
const secondaryCookieName = getSecondaryJWTCookieName(this.config);
244-
if (secondaryCookieName) {
245-
res.clearCookie(secondaryCookieName, {
246-
domain: this.config.hostUrl.url.hostname,
247-
});
248-
}
249233
}
250234
}
251235

252236
function getPrimaryJWTCookieName(config: Config) {
253237
return config.auth.session.cookie.name;
254238
}
255239

256-
function getSecondaryJWTCookieName(config: Config) {
257-
const PREFIX = "__Host-";
258-
if (!config.auth.session.cookie.name.startsWith(PREFIX)) {
259-
return undefined;
260-
}
261-
return config.auth.session.cookie.name.slice(PREFIX.length);
262-
}
263-
264240
function parseCookieHeader(c: string): { [key: string]: string[] } {
265241
return c
266242
.split("; ")

0 commit comments

Comments
 (0)