Skip to content

Commit 1b66bad

Browse files
refactor (#369)
* fix: remove duplicate OAuth callback route registrations in auth.ts - Removed duplicate nested app.get('/github/callback') that was registered inside an outer callback handler (caused by a bad merge) - Removed duplicate nested app.get('/google/callback') same issue - Removed dead code blocks (stray authUrl + redirect calls outside handlers) that were left over after the duplicate outer wrappers were stripped - All routes (/github, /github/callback, /google, /google/callback, /me, /logout) are now correctly registered at the top level within authRoutes plugin scope * fix: resolve OAuth CSRF vulnerabilities and add cookie types --------- Signed-off-by: Roshan Kumar Singh <162692544+roshankumar0036singh@users.noreply.github.com>
1 parent 02320c0 commit 1b66bad

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

apps/backend/src/routes/auth.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ export async function authRoutes(app: FastifyInstance) {
5757
// GitHub OAuth callback
5858
app.get('/github/callback', async (request: FastifyRequest<{ Querystring: OAuthCallbackQuery }>, reply: FastifyReply) => {
5959
const { code, state } = request.query;
60-
const storedState = (request.cookies as any)?.oauth_state;
61-
60+
const storedState = request.cookies?.oauth_state;
6261
if (!state || !storedState || state !== storedState) {
6362
return reply.status(400).send({ error: 'Invalid or missing OAuth state — possible CSRF attack' });
6463
}
@@ -183,7 +182,8 @@ export async function authRoutes(app: FastifyInstance) {
183182
// Google callback
184183
app.get('/google/callback', async (request: FastifyRequest<{ Querystring: OAuthCallbackQuery }>, reply: FastifyReply) => {
185184
const { code, state } = request.query;
186-
const storedState = (request.cookies as any)?.oauth_state;
185+
186+
const storedState = request.cookies?.oauth_state;
187187
if (!state || !storedState || state !== storedState) {
188188
return reply.status(400).send({ error: 'Invalid or missing OAuth state — possible CSRF attack' });
189189
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import '@fastify/cookie';
2+
import { FastifyRequest } from 'fastify';
3+
4+
declare module 'fastify' {
5+
interface FastifyRequest {
6+
cookies: Record<string, string | undefined>;
7+
}
8+
}

0 commit comments

Comments
 (0)