Skip to content

fix(security): OAuth のメール自動リンク廃止・登録制限の統一・非 http URI の無害化 - #293

Merged
sasagar merged 2 commits into
devfrom
fix/oauth-registration-uri
Oct 14, 2026
Merged

sasagar merged 2 commits into
devfrom
fix/oauth-registration-uri

Conversation

@sasagar

@sasagar sasagar commented Oct 14, 2026

Copy link
Copy Markdown
Member

変更

  • OAuthService
    • 既存アカウントへのメール一致による自動リンクを廃止(リンク行がある場合のみログイン)。メールが既存アカウントと一致する場合は email_exists で拒否
    • プロバイダーのメールは検証済みのみ使用(GitHub /user/emails の verified、Google verified_email/email_verified、Discord verified)。未検証時はプレースホルダー
    • 新規作成時に登録無効・招待制を適用、ブロック済みユーザー名を回避。user:beforeRegister / afterRegister フックを実行
    • OAuth のみのユーザーが最後のプロバイダーを解除できないよう hasUsablePassword() を追加
  • lib/registrationPolicy.ts(新規): 登録可否・招待制の判定を auth.ts から共通化
  • routes/oauth.ts: requireAuth → requireAuth()(link / unlink / accounts が動作していなかった)。ログイン中セッションに紐付いた link フロー(POST /:provider/link/authorize、state + セッショントークンの httpOnly cookie)を追加
  • routes/users.ts: 招待制等を迂回していた旧 POST /api/users を削除(フロントエンド未使用)
  • フロントエンド: toSafeHttpUrl() を追加し、NoteCardMenu(新しいタブで開く / リンクコピー / 共有)と MfmRenderer のリンクで http(s) 以外を拒否

挙動の変化

  • 未リンクの OAuth ログインで既存アカウントとメールが一致すると拒否(設定画面からのリンク UI は未実装)
  • 招待制 / 登録停止中は OAuth による新規登録不可(リンク済みユーザーはログイン可)
  • POST /api/users は 404。POST /api/auth/register を使用

確認

  • typecheck / lint / format:check / backend ユニット 1065 件・frontend 42 件 pass

https://claude.ai/code/session_01Y29fBeRP344FME6de48wUv

…egacy register, guard remote URLs

- OAuthService: never auto-link a provider login to an existing local account
  by email; refuse with "An account with this email already exists. Log in and
  link the provider from settings." Only verified provider emails are used
  (GitHub /user/emails verified, Google verified_email/email_verified, Discord
  verified); otherwise a placeholder email is stored.
- OAuth sign-up now honours registration.enabled, invite-only /
  REQUIRE_INVITATION, blocked usernames and the user:beforeRegister plugin hook.
  Already-linked users can still log in.
- routes/oauth: call requireAuth() (it was passed uncalled, so link/unlink/
  accounts never worked). Add POST /:provider/link/authorize; the link state
  cookie is bound to the initiating session token and the callback links to
  that session's user. POST /:provider/link requires matching state.
- unlinkAccount treats OAuth placeholder password hashes as no password.
- Extract registration policy helpers to lib/registrationPolicy.ts (shared by
  /api/auth/register and OAuth).
- Remove legacy POST /api/users, which bypassed all registration gating (unused
  by the frontend).
- Frontend: add toSafeHttpUrl and use it for remote note.uri in NoteCardMenu
  (open in new tab / copy / share) and MFM url/link nodes.

Claude-Session: https://claude.ai/code/session_01Y29fBeRP344FME6de48wUv
@coderabbitai

coderabbitai Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 20 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: Love-Rox/rox/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f102ef30-7fba-4746-b902-cd34cd9506d2
📥 Commits

Reviewing files that changed from the base of the PR and between 768c035 and 641e9db.

📒 Files selected for processing: 12
  • packages/backend/src/lib/registrationPolicy.ts
  • packages/backend/src/lib/validation.ts
  • packages/backend/src/routes/auth.ts
  • packages/backend/src/routes/oauth.ts
  • packages/backend/src/routes/users.ts
  • packages/backend/src/services/OAuthService.ts
  • packages/backend/src/tests/unit/OAuthRoutesSecurity.test.ts
  • packages/backend/src/tests/unit/OAuthService.test.ts
  • packages/frontend/src/components/mfm/MfmRenderer.tsx
  • packages/frontend/src/components/note/NoteCardMenu.tsx
  • packages/frontend/src/lib/utils/safeUrl.ts
  • packages/frontend/src/tests/safeUrl.test.ts
  • 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

Comment @coderabbitai help to get the list of available commands.

@sasagar
sasagar merged commit 79697e5 into dev Oct 14, 2026
11 checks passed
This was referenced Oct 14, 2026
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.

1 participant