Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions templates/cli/lib/auth/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ const loginWithOAuthDevice = async ({
}

globalConfig.setEmail(account.email);
globalConfig.removeCookie();

const { removed: removedLegacySessions, failed: failedLegacySessions } =
await removeLegacySessionsExcept(id);
Comment on lines +419 to 422

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Cookie cleanup can regress

removeCookie() runs before removeLegacySessionsExcept(id), but legacy session revocation uses ClientLegacy.call(), which persists any a_session_console= Set-Cookie response back to the active global config. Since the new OAuth session is current during that cleanup, a logout response that expires or updates the legacy cookie can write a cookie field onto the new token session after it was removed. In that case login --new can still finish with stale cookie data in the newly created session.

Suggested change
globalConfig.removeCookie();
const { removed: removedLegacySessions, failed: failedLegacySessions } =
await removeLegacySessionsExcept(id);
const { removed: removedLegacySessions, failed: failedLegacySessions } =
await removeLegacySessionsExcept(id);
globalConfig.removeCookie();

Expand Down
17 changes: 17 additions & 0 deletions templates/cli/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,10 @@ class Global extends Config<GlobalConfigData> {
this.setTo(Global.PREFERENCE_COOKIE, cookie);
}

removeCookie(): void {
this.deleteFrom(Global.PREFERENCE_COOKIE);
}

getProject(): string {
if (!this.hasFrom(Global.PREFERENCE_PROJECT)) {
return "";
Expand Down Expand Up @@ -1442,6 +1446,19 @@ class Global extends Config<GlobalConfigData> {
this.write();
}
}

deleteFrom(key: string): void {
const current = this.getCurrentSession();

if (current) {
const config = this.get(current as any);

if (config && (config as any)[key] !== undefined) {
delete (config as any)[key];
this.write();
}
}
}
}

export const localConfig = new Local();
Expand Down
Loading