You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Stop concurrent OAuth2 callbacks from using each other's provider. #10860 - #10914
/oauth2/authorize set the provider from its session onto the process-wide OAuth2 auth source, and login() and its helpers read it back from there, so overlapping callbacks for different providers could finish with each other's provider.
Each callback now works on its own shallow copy of the source (OAuth2Authentication.for_provider()), bound to the provider in its own session; clients and config are still the shared class-level dicts. This keeps login(form) and get_friendly_name() on the common auth source interface rather than threading a provider argument through every helper, and covers the extra read Add OAuth and Microsoft Entra ID authentication for database servers. #9261 #10830 adds.
authenticate() keeps the selected provider in a local variable instead of writing it to the shared instance, which had the same race between choosing the client and building the redirect.
Test plan
New Concurrent OAuth2 Callbacks Keep Their Own Provider scenario in test_oauth2_with_mocking.py: two callbacks in threads meet at a barrier inside get_user_profile(); fails on master ({'github': 'oidc-basic', ...}), passes with the fix.
Improved reliability when multiple OAuth2 sign-ins using different providers are processed at the same time. Each sign-in now retains its selected provider, reducing the risk of authentication errors or provider mix-ups.
…admin-org#10860
The OAuth2 callback set the provider from its session onto the auth
source instance, which is shared by every request in the process, and
login() and its helpers then read it back from there. Two callbacks for
different providers in flight at the same time could therefore finish
with the other's provider, its client, claims, userinfo endpoint and
logout URL. Each callback now works on its own copy of the source, bound
to the provider in its own session, and authenticate() keeps the
selected provider in a local variable rather than on the shared instance.
Closespgadmin-org#10860
No actionable comments were generated in the recent review.
Walkthrough
OAuth2 callbacks now use provider-bound copies of the shared authentication source. Interactive authentication reads the selected provider into a local variable. A new concurrent-callback test checks that callbacks for two providers retain their session-selected providers.
The callback uses a shallow copy of the shared source bound to its provider. authenticate reads the selected provider locally. The new concurrent test checks that each callback uses the provider selected in its session.
pgadmin-org/pgadmin4#10830: Adds the “Sign in again” flow and a provider read that this change keeps callback-specific.
Suggested reviewers: asheshv, pyodin
Merge Risk: Minimal · up to dcd11
This change keeps concurrent OAuth2 sign-ins on their own provider instead of mixing providers. No actionable merge-blocking risk remains after review.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title states the main change: concurrent OAuth2 callbacks no longer use each other's provider. The raw summary shows a provider-bound shallow copy via for_provider() and a local provider variable …
Linked Issues check
[#10860] The issue requires that each OAuth2 callback use only the provider stored in its own session, and that the provider stay callback-specific through login() and its helpers, including the extra…
Out of Scope Changes check
The whole-PR diff (merge base 36487e7 to head dcd112a) changes web/pgadmin/authenticate/oauth2.py and adds a test scenario in web/pgadmin/browser/tests/test_oauth2_with_mocking.py. The oauth2.py cha…
Full details: Title check
Explanation
The title states the main change: concurrent OAuth2 callbacks no longer use each other's provider. The raw summary shows a provider-bound shallow copy via for_provider() and a local provider variable in interactive authentication, which addresses this. The objectives and linked issue #10860 describe the same race. The title is specific and matches the changeset. It includes an issue reference, which is acceptable.
Full details: Linked Issues check
Explanation
[#10860] The issue requires that each OAuth2 callback use only the provider stored in its own session, and that the provider stay callback-specific through login() and its helpers, including the extra session read added by #10830. At the reviewed head, oauth_authorize() no longer writes the provider onto the shared registered source. It calls get_auth_sources(OAUTH2).for_provider(oauth2_client), which returns a copy.copy() of the source with oauth2_current_client set to the session provider. login() and its helpers read self.oauth2_current_client, so they read the per-callback value. Clients and config remain shared class-level dicts, which is the intended behavior. authenticate() stores the selected provider in the local variable provider_name and no longer writes it to self. The shared instance keeps oauth2_current_client as None (set in init). The reported test scenario (two concurrent callbacks meeting at a barrier in get_user_profile()) is listed in the PR test plan. I did not inspect the test file contents, so its behavior rests on the PR description. I did not read the full login() helper bodies, so I did not confirm that no helper writes other shared instance state. The diff touches no such writes.
Full details: Out of Scope Changes check
Explanation
The whole-PR diff (merge base 36487e7 to head dcd112a) changes web/pgadmin/authenticate/oauth2.py and adds a test scenario in web/pgadmin/browser/tests/test_oauth2_with_mocking.py. The oauth2.py changes are: importing copy, adding for_provider(), passing the session provider through it in oauth_authorize(), and using a local provider_name in authenticate(). All of these serve the objective in #10860 of preventing cross-provider use between concurrent callbacks. The test addition supports that objective. No unrelated refactoring or feature change appears in the reviewed hunks.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
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
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
/oauth2/authorizeset the provider from its session onto the process-wide OAuth2 auth source, andlogin()and its helpers read it back from there, so overlapping callbacks for different providers could finish with each other's provider.OAuth2Authentication.for_provider()), bound to the provider in its own session; clients and config are still the shared class-level dicts. This keepslogin(form)andget_friendly_name()on the common auth source interface rather than threading a provider argument through every helper, and covers the extra read Add OAuth and Microsoft Entra ID authentication for database servers. #9261 #10830 adds.authenticate()keeps the selected provider in a local variable instead of writing it to the shared instance, which had the same race between choosing the client and building the redirect.Test plan
Concurrent OAuth2 Callbacks Keep Their Own Providerscenario intest_oauth2_with_mocking.py: two callbacks in threads meet at a barrier insideget_user_profile(); fails on master ({'github': 'oidc-basic', ...}), passes with the fix.browser.tests.test_oauth2_with_mocking,browser.tests.test_oauth2_auto_login,authenticate.tests.test_oauth2_userinfo_endpoint,authenticate.tests.test_auth_source_user_bindingCloses #10860
Summary by CodeRabbit