Skip to content

Commit 696316c

Browse files
author
Lasim
committed
feat(backend): add response type validation in OAuth2 authorization
1 parent c4e376b commit 696316c

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

services/backend/src/routes/oauth2/authorization.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,24 @@ export default async function authorizationRoute(fastify: FastifyInstance) {
4646
code_challenge_method
4747
} = request.query as z.infer<typeof authorizationQuerySchema>;
4848

49+
// Validate response_type (additional validation beyond schema)
50+
if (response_type !== 'code') {
51+
request.log.warn({
52+
operation: 'oauth2_authorization',
53+
responseType: response_type,
54+
error: 'unsupported_response_type',
55+
}, 'Unsupported OAuth2 response type');
56+
57+
const errorUrl = `${redirect_uri}?error=unsupported_response_type&error_description=${encodeURIComponent('Only "code" response type is supported')}&state=${state}`;
58+
return reply.redirect(errorUrl);
59+
}
60+
4961
request.log.debug({
5062
operation: 'oauth2_authorization',
5163
clientId: client_id,
5264
redirectUri: redirect_uri,
5365
scope,
66+
responseType: response_type,
5467
codeChallengeMethod: code_challenge_method,
5568
}, 'OAuth2 authorization request received');
5669

services/backend/src/routes/teams/index.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,6 @@ export default async function teamsRoute(fastify: FastifyInstance) {
4040
requireOAuthScope('teams:read')
4141
]
4242
}, async (request: FastifyRequest, reply: FastifyReply) => {
43-
const authType = request.tokenPayload ? 'oauth2' : 'cookie';
44-
const userId = request.user!.id;
45-
46-
request.log.debug({
47-
operation: 'get_user_default_team',
48-
userId,
49-
authType,
50-
clientId: request.tokenPayload?.clientId,
51-
scope: request.tokenPayload?.scope,
52-
endpoint: request.url
53-
}, 'Authentication method determined for default team retrieval');
5443
try {
5544
if (!request.user) {
5645
return reply.status(401).send({
@@ -59,6 +48,18 @@ export default async function teamsRoute(fastify: FastifyInstance) {
5948
});
6049
}
6150

51+
const authType = request.tokenPayload ? 'oauth2' : 'cookie';
52+
const userId = request.user.id;
53+
54+
request.log.debug({
55+
operation: 'get_user_default_team',
56+
userId,
57+
authType,
58+
clientId: request.tokenPayload?.clientId,
59+
scope: request.tokenPayload?.scope,
60+
endpoint: request.url
61+
}, 'Authentication method determined for default team retrieval');
62+
6263
const defaultTeam = await TeamService.getUserDefaultTeam(request.user.id);
6364

6465
if (!defaultTeam) {

services/backend/tests/unit/routes/teams.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ describe('Teams Route', () => {
100100
user: {
101101
id: 'user-123',
102102
} as any, // Use any to avoid complex Lucia User type issues in tests
103+
log: {
104+
debug: vi.fn(),
105+
info: vi.fn(),
106+
warn: vi.fn(),
107+
error: vi.fn(),
108+
},
103109
} as any;
104110

105111
mockReply = {

0 commit comments

Comments
 (0)