Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/transport/http-transport-security.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ describe('HttpTransport security behavior (no listen)', () => {
await handler(req, res);

expect(res.statusCode).toBe(500);
expect(String(res.body)).toContain('OAuth authorization failed');
expect(String(res.body)).toMatch(/^Internal error \(correlation ID: [a-f0-9-]+\)$/);

await transport.stop();
});
Expand Down Expand Up @@ -1387,7 +1387,7 @@ describe('HttpTransport security behavior (no listen)', () => {
await handler(req, res);

expect(res.statusCode).toBe(500);
expect(String(res.body)).toContain('OAuth callback failed');
expect(String(res.body)).toMatch(/^Internal error \(correlation ID: [a-f0-9-]+\)$/);

await transport.stop();
});
Expand Down Expand Up @@ -1601,7 +1601,8 @@ describe('HttpTransport security behavior (no listen)', () => {
await handler(req, res);

expect(res.statusCode).toBe(500);
expect(res.body).toMatchObject({ error: 'server_error', error_description: 'Registration failed' });
expect((res.body as any).error).toBe('server_error');
expect((res.body as any).error_description).toMatch(/^Internal error \(correlation ID: [a-f0-9-]+\)$/);

await transport.stop();
});
Expand Down Expand Up @@ -1734,7 +1735,8 @@ describe('HttpTransport security behavior (no listen)', () => {
await handler(req, res);

expect(res.statusCode).toBe(500);
expect(res.body).toMatchObject({ error: 'server_error', error_description: 'Registration failed' });
expect((res.body as any).error).toBe('server_error');
expect((res.body as any).error_description).toMatch(/^Internal error \(correlation ID: [a-f0-9-]+\)$/);

await transport.stop();
});
Expand Down
2 changes: 1 addition & 1 deletion src/transport/http-transport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2385,7 +2385,7 @@ describeIfListen('HttpTransport', () => {
.query({ code: 'test-code' });

expect(response.status).toBe(500);
expect(response.text).toBe('OAuth callback failed');
expect(response.text).toMatch(/^Internal error \(correlation ID: [a-f0-9-]+\)$/);
});
});

Expand Down
30 changes: 19 additions & 11 deletions src/transport/http-transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1723,10 +1723,12 @@ export class HttpTransport {
try {
profiles = await this.profileIndexProvider();
} catch (error) {
this.logger.error('Failed to load profile index', error instanceof Error ? error : new Error(String(error)));
const correlationId = generateCorrelationId();
this.logger.error('Failed to load profile index', error instanceof Error ? error : new Error(String(error)), { correlationId });
res.status(HTTP_STATUS.INTERNAL_SERVER_ERROR).json({
error: 'Internal Server Error',
message: 'Failed to load profile index',
message: `Internal error (correlation ID: ${correlationId})`,
correlationId
});
return;
}
Expand Down Expand Up @@ -1921,8 +1923,9 @@ export class HttpTransport {

await profileState.oauthProvider.authorize(client, params, res);
} catch (error) {
this.logger.error('OAuth authorize error', error instanceof Error ? error : new Error(String(error)));
res.status(HTTP_STATUS.INTERNAL_SERVER_ERROR).send('OAuth authorization failed');
const correlationId = generateCorrelationId();
this.logger.error('OAuth authorize error', error instanceof Error ? error : new Error(String(error)), { correlationId });
res.status(HTTP_STATUS.INTERNAL_SERVER_ERROR).send(`Internal error (correlation ID: ${correlationId})`);
}
}

Expand Down Expand Up @@ -2195,9 +2198,10 @@ export class HttpTransport {

await profileState.oauthProvider.handleCallback(req, res);
} catch (error) {
this.logger.error('OAuth callback error', error instanceof Error ? error : new Error(String(error)));
const correlationId = generateCorrelationId();
this.logger.error('OAuth callback error', error instanceof Error ? error : new Error(String(error)), { correlationId });
if (!res.headersSent) {
res.status(HTTP_STATUS.INTERNAL_SERVER_ERROR).send('OAuth callback failed');
res.status(HTTP_STATUS.INTERNAL_SERVER_ERROR).send(`Internal error (correlation ID: ${correlationId})`);
}
}
}
Expand Down Expand Up @@ -2231,8 +2235,9 @@ export class HttpTransport {
};
res.json(buildAuthorizationServerMetadata(metadata, profileState.context.enterpriseAuthorization));
} catch (error) {
this.logger.error('OAuth authorization server metadata error', error instanceof Error ? error : new Error(String(error)));
res.status(HTTP_STATUS.INTERNAL_SERVER_ERROR).send('OAuth metadata failed');
const correlationId = generateCorrelationId();
this.logger.error('OAuth authorization server metadata error', error instanceof Error ? error : new Error(String(error)), { correlationId });
res.status(HTTP_STATUS.INTERNAL_SERVER_ERROR).send(`Internal error (correlation ID: ${correlationId})`);
}
}

Expand Down Expand Up @@ -2298,8 +2303,9 @@ export class HttpTransport {
return;
}

this.logger.error('Client registration failed', error instanceof Error ? error : new Error(String(error)));
res.status(HTTP_STATUS.INTERNAL_SERVER_ERROR).json({ error: 'server_error', error_description: 'Registration failed' });
const correlationId = generateCorrelationId();
this.logger.error('Client registration failed', error instanceof Error ? error : new Error(String(error)), { correlationId });
res.status(HTTP_STATUS.INTERNAL_SERVER_ERROR).json({ error: 'server_error', error_description: `Internal error (correlation ID: ${correlationId})`, correlationId });
}
}

Expand Down Expand Up @@ -2808,7 +2814,9 @@ export class HttpTransport {
// If contains requests, process and return response
if (messageType === 'request') {
if (!this.messageHandler) {
res.status(HTTP_STATUS.INTERNAL_SERVER_ERROR).json({ error: 'Internal Server Error', message: 'Message handler not configured' });
const correlationId = generateCorrelationId();
this.logger.error('Message handler not configured', new Error('Message handler not configured'), { correlationId });
res.status(HTTP_STATUS.INTERNAL_SERVER_ERROR).json({ error: 'Internal Server Error', message: `Internal error (correlation ID: ${correlationId})`, correlationId });
return;
}

Expand Down
Loading