Skip to content

fix: keep apiKey encrypted in refresh operation (#13063) #13177

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 1 commit into
base: main
Choose a base branch
from

Conversation

contip
Copy link

@contip contip commented Jul 15, 2025

What?

Prevents decrypted apiKey from being saved back to database on the auth refresh operation.

Why?

References issue #13063: refreshing a token for a logged-in user decrypted apiKey and wrote it back in plaintext, corrupting the user record.

How?

The user is now fetched with db.findOne instead of findByID, preserving the encryption of the key when saved back to the database using db.updateOne. The user record is then re-fetched using findByID, allowing for the decrypted key to be provided in the response.

Tests

  • ✅ keeps apiKey encrypted in DB after refresh
  • ✅ returns user with decrypted apiKey after refresh

Fixes #13063

@contip contip force-pushed the fix/refresh-keeps-apiKey-encrypted branch from 91b6997 to c76b5c2 Compare July 15, 2025 17:23
@contip contip changed the title fix(auth): keep apiKey encrypted in refresh operation (#13063) fix: keep apiKey encrypted in refresh operation (#13063) Jul 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid initialization vector when set Api Key on user
1 participant