BUG: [Security] Critical: Login CSRF vulnerability in OAuth flow (Missing 'state' parameter)

未关闭
#268 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

@Shevilll 已经在做这个了。

开始于 2026年6月20日。

  • #269 来自 @KumarADITHYA123 —— 已关闭,未合并
  • #301 来自 @Shevilll —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
github, python, redis, supabase

调研方向

阅读 backend/integrations/discord/cogs.py 中 /verify_github 命令附近的代码,然后跟踪 backend/app/services/auth/supabase.py 中的 login_with_github 以及 backend/app/api/v1/auth.py 中的 callback。确认 OAuth state 是如何生成、存储、传递给 GitHub 并在关联前进行检查的;当 callback 拒绝缺失或不匹配的 state 时即表示完成。

由索引模型根据 Issue 内容生成。

描述

Is there an existing issue for this?

  • I have searched the existing issues

What happened?

📌 Issue Overview
The current GitHub OAuth implementation in
backend/integrations/discord/cogs.py
and
backend/app/api/v1/auth.py
is vulnerable to Login CSRF / Session Fixation attacks. The flow relies solely on a session_id embedded in the redirect_uri to bind the Discord verification request to the GitHub callback, without validating the standard OAuth state parameter (RFC 6749).

This allows an attacker to force a victim's Discord account to be linked to the attacker's GitHub account by tricking them into clicking a valid callback link.

🔍 Steps to Reproduce
Initiate Verification: Run /verify_github in Discord to generate a verification link.
Inspect URL: Analyze the generated OAuth URL.
Code Verification: Inspect
backend/integrations/discord/cogs.py
at line 150.
auth_url_data = await login_with_github(redirect_to=callback_url)
The Error: the
login_with_github
function supports a state parameter, but it is not passed.
🎯 Expected Behavior
The OAuth initialization should generate a cryptographically secure random state token, store it (e.g., in Redis) with a short expiration, and pass it to GitHub. The callback endpoint should verify that the returned state matches the stored token before processing the linkage.

🚨 Actual Behavior
The state parameter is defined as Optional in
backend/app/services/auth/supabase.py
and is never passed by the
verify_github
command. The backend accepts any valid code + session_id pair without verifying the origin of the request.

🔗 Verification Evidence
I verified this using a script that imports the actual project code.

Source Code Check (
cogs.py
): Line 150 calls
login_with_github
with ONLY redirect_to. The state argument is absent.

Execution Check (
supabase.py
): When running the actual backend logic, the generated URL sent to the provider is:

Provider: github
Options: {'redirect_to': '.../callback'}
State Parameter: MISSING

This confirms the vulnerability exists in the live codebase.

💡 Suggested Improvements
Generate State: In
cogs.py
, generate state = secrets.token_urlsafe(32).
Store It: Save redis.setex(f"oauth_state:{state}", 300, session_id).
Pass It: Update correct call: await login_with_github(..., state=state).
Validate It: Update auth_callback in auth.py to Depends(verify_state_token).

Record

  • I agree to follow this project's Code of Conduct
  • I want to work on this issue
主要语言
Python
星标
103
派生
143
PR 合并指标
30 天内没有已合并 PR

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

AOSSIE-Org/Devr.AI 的其他 Issue

查看 AOSSIE-Org/Devr.AI 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。