fix(instagram): sign and validate OAuth state with nonce and TTL to prevent CSRF account linking
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 54/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- redis, typescript
- Ambito
- authentication, backend, security
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- TypeScript
- Stelle
- 2
- Fork
- 1
- Merge medio
- 6m
- PR unite (30g)
- 27
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di sumamakhan761/tryinstance
-
backend good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
sumamakhan761/tryinstance#65 ·
I maintainer di solito rispondono entro 1 giorno
-
backend good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
sumamakhan761/tryinstance#64 ·
I maintainer di solito rispondono entro 1 giorno
-
backend good first issue
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
sumamakhan761/tryinstance#63 ·
I maintainer di solito rispondono entro 1 giorno
-
backend good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
sumamakhan761/tryinstance#62 ·
I maintainer di solito rispondono entro 1 giorno
-
backend good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
sumamakhan761/tryinstance#60 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di sumamakhan761/tryinstance
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
makecindy/cindy#15342 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
kwitsch/claude-code-plugin-tooling#219 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
I maintainer di solito rispondono entro 1 giorno
-
no-repo-link tool-submission
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 74/100
BraveOPotato/NoSignups#2618 ·
-
enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100