Server mode OAuth2: 'NoneType' object is not subscriptable on every request after re-submitting the OAuth2 login while already logged in

オープン 初心者向け
#10,733 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 3 日以内に返信

@Rarasinhoo がすでに取り組んでいます。

2026年11月4日 から。

  • #10734 @Rarasinhoo による — オープン

評価

難易度
1/5
見積もり時間
1時間未満
初心者へのやさしさ
88/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python

調査の方向性

pgadmin/__init__.py の 1010 行付近にある before_request と、issue に記載された authenticate.login() のフローから始めます。OAuth2 リダイレクトによって auth_source_manager が None に設定された後、どのようにチェックされるかを追跡します。issue では条件を 1 つ変更する修正が報告されています。影響を受けるリクエストで TypeError が発生しなくなったことを確認します。

索引モデルが issue の本文から書いたものです。

説明

Describe the bug

In server mode with OAuth2, a browser that is already logged in and submits the OAuth2 login button again ends up with session['auth_source_manager'] = None while current_user.is_authenticated is still true. From then on before_request raises TypeError: 'NoneType' object is not subscriptable on every request, including /logout and /login, so the user cannot recover from the UI. Only clearing the cookies, waiting for the session to expire, or restarting the server unblocks them.

This looks like the same error as #9476, which was closed because it could not be reproduced. The steps below reproduce it every time.

To Reproduce

Official image dpage/pgadmin4:9.19.0. The code is the same on master. Use this config_local.py; the OAuth2 provider does not need to exist:

AUTHENTICATION_SOURCES = ['internal', 'oauth2']
OAUTH2_CONFIG = [{
    'OAUTH2_NAME': 'fake', 'OAUTH2_DISPLAY_NAME': 'Fake',
    'OAUTH2_CLIENT_ID': 'x', 'OAUTH2_CLIENT_SECRET': 'y',
    'OAUTH2_TOKEN_URL': 'https://idp.invalid/token',
    'OAUTH2_AUTHORIZATION_URL': 'https://idp.invalid/authorize',
    'OAUTH2_API_BASE_URL': 'https://idp.invalid/', 'OAUTH2_USERINFO_ENDPOINT': 'me',
    'OAUTH2_SCOPE': 'openid email',
}]
  1. Log in with the internal user. GET /browser/ returns 200.
  2. While still logged in, open /login. The login page is rendered for an authenticated user. Submit the OAuth2 button (POST /authenticate/login with oauth2_button=fake). It returns a 302 to the provider.
  3. Do not complete the provider login, or come back from it. GET /browser/, /favicon.ico, /logout and /login all return 500.

In production with Microsoft Entra, the same thing happens on the /oauth2/authorize callback. It typically hits a user who still has a valid session and clicks "Login with Microsoft" from an old tab or a bookmarked /login?next=/.

Expected behavior

An authenticated session that has auth_source_manager set to None (set in authenticate.login() before the OAuth2 redirect) should not crash before_request.

Error message

ERROR pgadmin: 'NoneType' object is not subscriptable
  File "/pgadmin4/pgadmin/__init__.py", line 1010, in before_request
    session['auth_source_manager']['current_source'] not in \
TypeError: 'NoneType' object is not subscriptable

Cause and fix

authenticate.login() runs session['auth_source_manager'] = None, but before_request only checks that the key is present ('auth_source_manager' in session) before subscripting it. If that check becomes session.get('auth_source_manager'), steps 1–3 return 200/302 and the traceback no longer appears. I verified this by mounting the patched file in the 9.19.0 image. A PR follows.

Desktop

  • Server mode (Docker, dpage/pgadmin4:9.19.0), OAuth2 with Microsoft Entra ID
  • Browser: Chrome 157 / curl
主要言語
Python
スター
3.9k
フォーク
914
平均マージ
2日 10時間
マージ済み PR(30日)
25

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

pgadmin-org/pgadmin4 のほかの issue

pgadmin-org/pgadmin4 の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。