Skip to content

Stop concurrent OAuth2 callbacks from using each other's provider. #10860 - #10914

Merged
dpage merged 1 commit into
pgadmin-org:masterfrom
dpage:fix/issue-10860-oauth2-provider-race
Dec 1, 2026
Merged

dpage merged 1 commit into
pgadmin-org:masterfrom
dpage:fix/issue-10860-oauth2-provider-race

Conversation

@dpage

@dpage dpage commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • /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.
  • browser.tests.test_oauth2_with_mocking, browser.tests.test_oauth2_auto_login, authenticate.tests.test_oauth2_userinfo_endpoint, authenticate.tests.test_auth_source_user_binding
  • pycodestyle

Closes #10860

Summary by CodeRabbit

  • Bug Fixes
    • 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.

Closes pgadmin-org#10860
@dpage dpage self-assigned this Dec 1, 2026
@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Explain Change →

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.

Changes

OAuth2 provider isolation

Layer / File(s) Summary
Keep provider selection callback-local
web/pgadmin/authenticate/oauth2.py, web/pgadmin/browser/tests/test_oauth2_with_mocking.py
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.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

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: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 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 Passed [#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 Passed 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.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 4129152 and dcd112a.

Files selected for processing: 2

  • web/pgadmin/authenticate/oauth2.py
  • web/pgadmin/browser/tests/test_oauth2_with_mocking.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

@dpage
dpage merged commit ea6c29d into pgadmin-org:master Dec 1, 2026
44 of 47 checks passed
@dpage
dpage deleted the fix/issue-10860-oauth2-provider-race branch December 1, 2026 12:01
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.

Concurrent OAuth2 callbacks can use each other's provider

1 participant