Skip to content

Commit f8bb764

Browse files
committed
fix(auth): prevent authentication bypass and fix Authorization header
- Fix critical security vulnerability where non-GET requests to protected SSR routes bypassed authentication - Add proper 401 error handling for non-GET requests to protected SSR routes - Fix Authorization header being set to 'Bearer undefined' when bearerToken is not provided - Make Authorization header conditional in ApiClientService based on bearerToken presence LFXV2-417 Signed-off-by: Asitha de Silva <asithade@gmail.com>
1 parent 93d05f0 commit f8bb764

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

apps/lfx-pcc/src/server/middleware/auth.middleware.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,23 @@ function makeAuthDecision(result: AuthMiddlewareResult, req: Request): AuthDecis
187187
};
188188
}
189189

190+
// Non-GET SSR routes - return 401 error
191+
if (route.type === 'ssr' && req.method !== 'GET') {
192+
req.log.warn(
193+
{
194+
path: req.path,
195+
routeType: route.type,
196+
method: req.method,
197+
},
198+
'SSR route requires authentication for non-GET request - returning 401'
199+
);
200+
return {
201+
action: 'error',
202+
errorType: 'authentication',
203+
statusCode: 401,
204+
};
205+
}
206+
190207
// API routes - return 401 error
191208
if (route.type === 'api') {
192209
req.log.warn(

apps/lfx-pcc/src/server/services/api-client.service.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,21 @@ export class ApiClientService {
3535
}
3636

3737
private async makeRequest<T>(method: string, url: string, bearerToken?: string, data?: any, customHeaders?: Record<string, string>): Promise<ApiResponse<T>> {
38+
const headers: Record<string, string> = {
39+
...customHeaders,
40+
Accept: 'application/json',
41+
['Content-Type']: 'application/json',
42+
['User-Agent']: 'LFX-PCC-Server/1.0',
43+
};
44+
45+
// Only add Authorization header if bearerToken is provided
46+
if (bearerToken) {
47+
headers['Authorization'] = `Bearer ${bearerToken}`;
48+
}
49+
3850
const requestInit: RequestInit = {
3951
method,
40-
headers: {
41-
...customHeaders,
42-
Authorization: `Bearer ${bearerToken}`,
43-
Accept: 'application/json',
44-
['Content-Type']: 'application/json',
45-
['User-Agent']: 'LFX-PCC-Server/1.0',
46-
},
52+
headers,
4753
signal: AbortSignal.timeout(this.config.timeout),
4854
};
4955

0 commit comments

Comments
 (0)