fix(instagram): sign and validate OAuth state with nonce and TTL to prevent CSRF account linking
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 54/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- redis, typescript
調査の方向性
Start with apps/api/src/instagram/services/instagram-auth.service.ts and the initiateAuth and callback paths in apps/api/src/instagram/instagram.controller.ts. Trace how OAuth state is created and how the callback exchanges the code; check the existing Redis setup and available secret configuration. Done means the callback rejects invalid, expired, and replayed state before token exchange or account linking, with tests covering those cases.
索引モデルが issue の本文から書いたものです。
説明
Problem Description
In apps/api/src/instagram/services/instagram-auth.service.ts, getOAuthUrl sets the OAuth state parameter to raw ${userId}:new or ${userId} with no HMAC signature, random nonce, expiration, or session/cookie binding.
Meanwhile, @Public() @Get('callback') in apps/api/src/instagram/instagram.controller.ts calls handleOAuthCallback, which splits state.split(':') and trusts the userId directly to link the Instagram account to user.company.id and overwrite Company.instagramHandle.
An attacker who knows or guesses a userId can complete OAuth with their own Instagram account and replay /api/instagram/callback?code=<attacker_code>&state=<victim_userId> (or CSRF a logged-in victim) to link their Instagram account to the victim's workspace, hijacking instagramHandle, automations, and leads.
Expected Behavior
- The OAuth
stateparameter must be cryptographically signed (HMAC-SHA256) and bound to a short-lived, single-use randomnonce(e.g., 10-minute TTL on the OAuth handshake only — connected Instagram accounts and long-lived tokens are unaffected). handleOAuthCallbackmust verify the signature, expiration, and single-usenonce(atomically deleting it) before exchangingcodeor linking anyInstagramAccount.- Invalid, expired, tampered, or replayed
statevalues must be rejected with400/401.
Where to Look
apps/api/src/instagram/instagram.controller.ts(initiateAuth,callback)apps/api/src/instagram/services/instagram-auth.service.ts(getOAuthUrl,handleOAuthCallback)
Solution / Implementation Guide
-
Sign & store
stateingetOAuthUrl:- Generate a random
nonce(crypto.randomBytes(16).toString('hex')) and payload{ userId, setupMode, nonce, exp: Date.now() + 10 * 60 * 1000 }. - Store
oauth:state:${nonce}in Redis with a 10-minute TTL (or bindnonceto anHttpOnly; SameSite=Laxcookie). - Encode
base64url(JSON.stringify(payload))and append an HMAC-SHA256 signature usingAUTH_SECRET/NEXTAUTH_SECRET(<encoded>.<sig>).
- Generate a random
-
Verify & consume
stateinhandleOAuthCallback:- Split
<encoded>.<sig>, verify the HMAC withcrypto.timingSafeEqual, parse the payload, and checkDate.now() <= payload.exp. - Atomically verify and delete
oauth:state:${payload.nonce}in Redis (or verify theHttpOnlycookie nonce) so the callback URL cannot be replayed. - Only after verification passes, proceed with token exchange and
InstagramAccountlinking.
- Split
- 主要言語
- TypeScript
- スター
- 2
- フォーク
- 1
- 平均マージ
- 6分
- マージ済み PR(30日)
- 27
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
sumamakhan761/tryinstance のほかの issue
-
backend good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
sumamakhan761/tryinstance#65 ·
メンテナーはふだん 1 日以内に返信
-
backend good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
sumamakhan761/tryinstance#64 ·
メンテナーはふだん 1 日以内に返信
-
backend good first issue
難易度 1/5 1〜3時間 初心者へのやさしさ 88/100
sumamakhan761/tryinstance#63 ·
メンテナーはふだん 1 日以内に返信
-
backend good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
sumamakhan761/tryinstance#62 ·
メンテナーはふだん 1 日以内に返信
-
backend good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
sumamakhan761/tryinstance#60 ·
メンテナーはふだん 1 日以内に返信
sumamakhan761/tryinstance の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
makecindy/cindy#15342 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
kwitsch/claude-code-plugin-tooling#219 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 1 日以内に返信
-
no-repo-link tool-submission
難易度 1/5 1時間未満 初心者へのやさしさ 74/100
BraveOPotato/NoSignups#2618 ·
-
enhancement good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100