Server mode OAuth2: 'NoneType' object is not subscriptable on every request after re-submitting the OAuth2 login while already logged in
メンテナーはふだん 3 日以内に返信
評価
- 難易度
- 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',
}]
- Log in with the internal user.
GET /browser/returns 200. - While still logged in, open
/login. The login page is rendered for an authenticated user. Submit the OAuth2 button (POST /authenticate/loginwithoauth2_button=fake). It returns a 302 to the provider. - Do not complete the provider login, or come back from it.
GET /browser/,/favicon.ico,/logoutand/loginall 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
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
pgadmin-org/pgadmin4 のほかの issue
-
Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
pgadmin-org/pgadmin4#10702 ·
メンテナーはふだん 3 日以内に返信
-
AI Assistant 'Insert at Cursor' does not insert the SQL into the query editor対応中かも @GBra-4-669 が 8 日前に担当しました。 オープンBug
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
pgadmin-org/pgadmin4#10690 ·
メンテナーはふだん 3 日以内に返信
-
Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
pgadmin-org/pgadmin4#10673 ·
メンテナーはふだん 3 日以内に返信
-
Import/Export Data fails for a file name containing a backslash, and creates a stray file named EオープンBug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
pgadmin-org/pgadmin4#10672 ·
メンテナーはふだん 3 日以内に返信
-
Helm chart: allow setting ingressClassName on the Ingress対応中かも @commarla が 13 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
pgadmin-org/pgadmin4#10658 ·
メンテナーはふだん 3 日以内に返信
pgadmin-org/pgadmin4 の issue をすべて見る
似ている issue
-
flow-measurement measurement
難易度 1/5 1時間未満 初心者へのやさしさ 76/100
MichaelYcJo/SpecSeal#1366 ·
-
bug c/evals c/ui size:L
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
Arize-ai/phoenix#17633 · コメント 2 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
TransformerLensOrg/TransformerLens#1980 ·
メンテナーはふだん 1 日以内に返信
-
Module: Solr Needs: Lead Needs: Triage Theme: Search Type: Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
internetarchive/openlibrary#14284 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 69/100
SpaceCowMedia/commander-spellbook-backend#1292 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信