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
5 changes: 5 additions & 0 deletions .changeset/local-cimd-loopback-only.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"executor": patch
---

Use the hosted loopback OAuth client metadata document only when Executor is opened on a loopback origin. A local Executor reached through a public reverse proxy now publishes its own client metadata document, so providers that support Client ID Metadata Documents no longer reject its callback as an invalid redirect URI.
20 changes: 20 additions & 0 deletions packages/react/src/plugins/oauth-sign-in.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,26 @@ describe("oauthClientIdMetadataDocumentUrl", () => {
}),
).toBe("https://executor.sh/api/oauth/client-id-metadata/local.json");
});

it("uses the hosted local document on an IPv6 loopback origin", () => {
setLocation("http://[::1]:4788/integrations/posthog");

expect(
oauthClientIdMetadataDocumentUrl({
hostedBaseUrl: "https://executor.sh",
}),
).toBe("https://executor.sh/api/oauth/client-id-metadata/local.json");
});

it("uses the current origin behind a public reverse proxy", () => {
setLocation("https://executor-mcp.example.com/integrations/posthog");

expect(
oauthClientIdMetadataDocumentUrl({
hostedBaseUrl: "https://executor.sh",
}),
).toBe("https://executor-mcp.example.com/api/oauth/client-id-metadata/default.json");
});
});

describe("oauthCallbackUrl", () => {
Expand Down
11 changes: 10 additions & 1 deletion packages/react/src/plugins/oauth-sign-in.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,21 @@ const configuredClientIdMetadataBaseUrl = (): string | undefined => {
return value ? value : undefined;
};

// The hosted local document only lists loopback callbacks, so a local
// Executor reached through a public origin (a reverse proxy) must publish its
// own document instead.
const isLoopbackHostname = (hostname: string): boolean =>
hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]";

export function oauthClientIdMetadataDocumentUrl(options?: {
readonly hostedBaseUrl?: string | null;
readonly path?: string;
}): string {
const hostedBaseUrl = options?.hostedBaseUrl ?? configuredClientIdMetadataBaseUrl();
if (hostedBaseUrl) {
if (
hostedBaseUrl &&
(typeof window === "undefined" || isLoopbackHostname(window.location.hostname))
) {
return new URL(OAUTH_CLIENT_ID_METADATA_DOCUMENT_LOCAL_PATH, hostedBaseUrl).toString();
}

Expand Down
Loading