Server mode OAuth2: 'NoneType' object is not subscriptable on every request after re-submitting the OAuth2 login while already logged in
维护者通常 4 天内回复
还没有人认领这个 Issue。
- #10734 来自 @Rarasinhoo —— 已关闭,未合并
评估
- 难度
- 1/5
- 预计耗时
- 1 小时以内
- 新手友好度
- 88/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- python
调研方向
从 pgadmin/__init__.py 中约第 1010 行的 before_request,以及 issue 中描述的 authenticate.login() 流程开始。追踪 OAuth2 重定向将 auth_source_manager 设为 None 后,它是如何被检查的。issue 报告了一项只涉及一个条件的修复;确认受影响的请求不再引发 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 小时
- 30 天内合并 PR
- 25
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
pgadmin-org/pgadmin4 的其他 Issue
-
Bug
难度 2/5 1-3 小时 新手友好度 68/100
pgadmin-org/pgadmin4#10702 · 1 条评论 ·
维护者通常 4 天内回复
-
Bug
难度 2/5 1-3 小时 新手友好度 78/100
pgadmin-org/pgadmin4#10673 ·
维护者通常 4 天内回复
-
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 ·
维护者通常 4 天内回复
-
Feature
难度 2/5 1-3 小时 新手友好度 78/100
pgadmin-org/pgadmin4#10426 · 3 条评论 · 1 个 reaction ·
维护者通常 4 天内回复
-
Feature
难度 2/5 1-3 小时 新手友好度 68/100
pgadmin-org/pgadmin4#10272 · 5 条评论 ·
维护者通常 4 天内回复
查看 pgadmin-org/pgadmin4 的全部 Issue
相似的 Issue
-
documentation
难度 2/5 1-3 小时 新手友好度 76/100
awslabs/social-messaging-agent-runtime-toolkit#140 ·
维护者通常 1 天内回复
-
subtask
难度 2/5 1-3 小时 新手友好度 72/100
fga-eps-mds/2026.2-MeasureSoftGram-DOC#187 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 83/100
txn2/mcp-data-platform#2493 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
YO-WHATS-UP2/minigit#78 ·
维护者通常 3 天内回复
-
documentation
难度 2/5 1-3 小时 新手友好度 78/100
liberation-data/drivine-python#432 ·
维护者通常 1 天内回复