Skip to content

Use old id_token if new id_token not in refresh response #629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion lib/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ async function refresh({ tokenEndpointParams } = {}) {
// Update the session
const session = req[config.session.name];
Object.assign(session, {
id_token: newTokenSet.id_token,
access_token: newTokenSet.access_token,
// If no new ID token assume the current ID token is valid.
id_token: newTokenSet.id_token || oldTokenSet.id_token,
Copy link
Preview

Copilot AI Jul 18, 2025

Choose a reason for hiding this comment

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

Using the old ID token without validating its expiration could lead to security issues. Consider checking if the old ID token is still valid (not expired) before using it as a fallback.

Suggested change
id_token: newTokenSet.id_token || oldTokenSet.id_token,
id_token: newTokenSet.id_token || (isTokenValid(oldTokenSet.id_token) ? oldTokenSet.id_token : undefined),

Copilot uses AI. Check for mistakes.

// If no new refresh token assume the current refresh token is valid.
refresh_token: newTokenSet.refresh_token || oldTokenSet.refresh_token,
token_type: newTokenSet.token_type,
Expand Down