Repository navigation
fix(oauth): prioritize existing OAuth identity bindings over username/email matching - #1653
Open
NicolasRoelofs wants to merge 3 commits into
Open
NicolasRoelofs wants to merge 3 commits into
NicolasRoelofs wants to merge 3 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes an issue in Generic OAuth/OIDC authentication where an already linked identity may result in the creation of a duplicate CWA user during a subsequent login.
The existing OAuth association should take precedence over username/email matching when resolving the local CWA account.
Problem
When an existing CWA account is explicitly linked to an OIDC identity, the initial linking operation can succeed.
However, on a subsequent OAuth login, the application may search for a local user using the configured username or email claims before considering the existing OAuth association.
If the identity provider returns an opaque
subvalue as the username and no matching email is available, CWA may create a new user instead of reusing the previously linked account.This can lead to:
Proposed fix
During a normal OAuth login:
provider_user_id.No database schema changes are required.
Reproduction
Environment: Calibre-Web Automated v4.0.8, Generic OIDC provider.
Example configuration:
readerreader@example.comsub):opaque-sub-123subemailSteps:
Actual behavior before the fix: A new user may be created from the opaque subject despite the existing OAuth association.
Expected behavior: The previously linked CWA account is reused, with its original permissions and preferences.
Validation
The fix was manually validated in a CWA v4.0.8 Docker deployment:
Automated regression tests and review against the current development branch are still needed.
Scope
This PR focuses exclusively on OAuth identity resolution and account linking.
It does not introduce automatic SSO redirects, change OAuth provider configuration, or modify the database schema.