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
2 changes: 1 addition & 1 deletion src/auth/oauth-provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1985,7 +1985,7 @@ describe('ExternalOAuthProvider', () => {
await provider.handleCallback(mockReq, mockRes);

expect(mockRes.status).toHaveBeenCalledWith(500);
expect(mockRes.send).toHaveBeenCalledWith('Internal Server Error during token exchange');
expect(mockRes.send).toHaveBeenCalledWith(expect.stringMatching(/^Internal error \(correlation ID: [a-f0-9-]+\)$/));
});
});

Expand Down
6 changes: 4 additions & 2 deletions src/auth/oauth-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { SSRFValidator } from '../security/ssrf-validator.js';
import { parseOAuthMetadataEndpoints } from './oauth-metadata.js';
import { InMemoryClientsStore } from './client-store/in-memory-clients-store.js';
import { isApprovedUnregisteredClientRedirectUri } from './unregistered-client-redirect-policy.js';
import { generateCorrelationId } from '../core/errors.js';
export { InMemoryClientsStore };
export type { InMemoryClientsStoreOptions } from './client-store/types.js';

Expand Down Expand Up @@ -867,8 +868,9 @@ export class ExternalOAuthProvider implements OAuthServerProvider {
res.redirect(clientUrl.toString());

} catch (err) {
this.logger.error('Callback handling failed', err as Error);
res.status(500).send('Internal Server Error during token exchange');
const correlationId = generateCorrelationId();
this.logger.error('Callback handling failed', err as Error, { correlationId });
res.status(500).send(`Internal error (correlation ID: ${correlationId})`);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/transport/http-transport-security.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,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 @@ -1378,7 +1378,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 @@ -1592,7 +1592,7 @@ 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).toMatchObject({ error: 'server_error', error_description: expect.stringMatching(/^Internal error \(correlation ID: [a-f0-9-]+\)$/) });

await transport.stop();
});
Expand Down Expand Up @@ -1724,7 +1724,7 @@ 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).toMatchObject({ error: 'server_error', error_description: expect.stringMatching(/^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 @@ -2340,7 +2340,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
29 changes: 18 additions & 11 deletions src/transport/http-transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1625,10 +1625,11 @@ 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})`,
});
return;
}
Expand Down Expand Up @@ -1814,8 +1815,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 @@ -2077,9 +2079,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 @@ -2113,8 +2116,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 @@ -2180,8 +2184,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})` });
}
}

Expand Down Expand Up @@ -2690,7 +2695,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', undefined, { correlationId });
res.status(HTTP_STATUS.INTERNAL_SERVER_ERROR).json({ error: 'Internal Server Error', message: `Internal error (correlation ID: ${correlationId})` });
return;
}

Expand Down
Loading