mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-01 09:39:53 +01:00
fix(tool-access): keep OAuth redirect-policy refusals out of Sentry
An authorization server that answers dynamic client registration with 400 invalid_redirect_uri is applying its own redirect policy. Paperclip only sends callbacks built from trusted origins and already returns a 502 with remediation, so stop reporting this one case as a crash. Other registration 400s, unknown codes and non-400 rejections stay reported. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
66a8aa7f7e
commit
97a4b46447
3 files changed
+51
-1
No files matched your search
@@ -75,6 +75,31 @@ describe("OAuth dynamic client registration failure reporting", () => {
|
||||
expect(JSON.stringify(oauthProviderFailureDiagnosticsFor(reported))).not.toContain(PROVIDER_CANARY);
|
||||
});
|
||||
|
||||
it("answers a provider's 400 invalid_redirect_uri with its remediation and no crash report", async () => {
|
||||
const res = await request(createApp(400, { error: "invalid_redirect_uri", error_description: PROVIDER_CANARY }))
|
||||
.post("/register");
|
||||
|
||||
expect(res.status).toBe(502);
|
||||
expect(res.body).toMatchObject({
|
||||
error: "The authorization server rejected Paperclip's callback URL.",
|
||||
code: "oauth_dynamic_client_registration_failed",
|
||||
details: { providerError: "invalid_redirect_uri", status: 400 },
|
||||
});
|
||||
expect(JSON.stringify(res.body)).not.toContain(PROVIDER_CANARY);
|
||||
expect(captureExceptionMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it.each([
|
||||
["a 422 invalid_redirect_uri", 422, { error: "invalid_redirect_uri" }],
|
||||
["a 400 with an unrecognized error code", 400, { error: "redirect_rejected_by_policy" }],
|
||||
["a 400 with no error code", 400, {}],
|
||||
])("still reports %s", async (_label, status, body) => {
|
||||
const res = await request(createApp(status, body)).post("/register");
|
||||
|
||||
expect(res.status).toBe(502);
|
||||
expect(captureExceptionMock).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("still reports a successful response with unusable client metadata", async () => {
|
||||
const res = await request(createApp(201, { redirect_uris: [] })).post("/register");
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
import { recordResponsibleUserDenialOnActiveRun } from "../services/responsible-user-denial-run-outcomes.js";
|
||||
import { isObjectJournalBusyError } from "../services/object-byte-journal.js";
|
||||
import { isExpectedMcpConnectionFailure } from "../services/mcp-connection-failure.js";
|
||||
import { isExpectedOAuthProviderFailure } from "../services/tool-access/oauth/provider-failure-diagnostics.js";
|
||||
import { isOpenRouterCatalogUnavailable } from "../services/openrouter-models.js";
|
||||
import { ENVIRONMENT_PROVIDER_UNAVAILABLE_CODE, readTransientSandboxCreationRefusal } from "../services/environment-provider-unavailable-error.js";
|
||||
import { isEndedDbPoolError } from "../database-retry.js";
|
||||
@@ -219,7 +220,15 @@ export function errorHandler(
|
||||
);
|
||||
// An unreachable public provider catalog still answers 503 with its
|
||||
// retry guidance, but it is the provider's outage, not a server fault.
|
||||
reportCrash(reportableError, req, !isExpectedMcpConnectionFailure(err) && !isOpenRouterCatalogUnavailable(err));
|
||||
// An OAuth provider refusing Paperclip's callback URL is its redirect
|
||||
// policy; the person still gets the 502 and its remediation.
|
||||
reportCrash(
|
||||
reportableError,
|
||||
req,
|
||||
!isExpectedMcpConnectionFailure(err)
|
||||
&& !isOpenRouterCatalogUnavailable(err)
|
||||
&& !isExpectedOAuthProviderFailure(err),
|
||||
);
|
||||
}
|
||||
const secretSensitiveServerError =
|
||||
err.status >= 500 &&
|
||||
|
||||
@@ -16,3 +16,19 @@ export function recordOAuthProviderFailure<T extends Error>(error: T, diagnostic
|
||||
export function oauthProviderFailureDiagnosticsFor(error: unknown): Readonly<OAuthProviderFailureDiagnostics> | null {
|
||||
return error instanceof Error ? recorded.get(error) ?? null : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* A registration endpoint that refuses Paperclip's callback URL with 400
|
||||
* `invalid_redirect_uri` is applying its own redirect policy, such as an
|
||||
* allowlist of approved clients or an HTTPS rule. Paperclip only sends a
|
||||
* callback it built from a trusted origin, so it cannot change that answer;
|
||||
* the person already gets remediation copy. Other registration 400s, such as
|
||||
* `invalid_client_metadata` or an unrecognized code, can mean Paperclip sent
|
||||
* bad metadata and stay reportable.
|
||||
*/
|
||||
export function isExpectedOAuthProviderFailure(error: unknown): boolean {
|
||||
const diagnostics = oauthProviderFailureDiagnosticsFor(error);
|
||||
return diagnostics?.operation === "dynamic_client_registration"
|
||||
&& diagnostics.httpStatus === 400
|
||||
&& diagnostics.providerError === "invalid_redirect_uri";
|
||||
}
|
||||
Reference in new issue
Block a user