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 Server Error during token exchange \(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 @@ -36,6 +36,7 @@ import {
PROXY_CREDENTIALS,
} from '../core/constants.js';
import { escapeHtmlSafe } from '../validation/validation-utils.js';
import { generateCorrelationId } from '../core/errors.js';
import { SSRFValidator } from '../security/ssrf-validator.js';
import { parseOAuthMetadataEndpoints } from './oauth-metadata.js';
import { InMemoryClientsStore } from './client-store/in-memory-clients-store.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 Server Error during token exchange (correlation ID: ${correlationId})`);
}
}

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(/^OAuth callback failed \(correlation ID: [a-f0-9-]+\)$/);
});
});

Expand Down
15 changes: 9 additions & 6 deletions src/transport/http-transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1814,8 +1814,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(`OAuth authorization failed (correlation ID: ${correlationId})`);
}
}

Expand Down Expand Up @@ -2077,9 +2078,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(`OAuth callback failed (correlation ID: ${correlationId})`);
}
}
}
Expand Down Expand Up @@ -2113,8 +2115,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(`OAuth metadata failed (correlation ID: ${correlationId})`);
}
}

Expand Down
Loading