diff --git a/apps/server/src/provider/AntigravityAuth.test.ts b/apps/server/src/provider/AntigravityAuth.test.ts index 02e8b691a1334..ac98682e68d0e 100644 --- a/apps/server/src/provider/AntigravityAuth.test.ts +++ b/apps/server/src/provider/AntigravityAuth.test.ts @@ -251,6 +251,73 @@ it.layer(NodeServices.layer)("AntigravityAuth", (it) => { }), ); + it.effect("shows Antigravity's onboarding rejection instead of the generic failure", () => + Effect.gen(function* () { + const harness = yield* makeHarness(); + yield* harness.auth.controller.start(owner); + yield* phase(harness.auth, "waiting"); + const reason = + "Onboarding failed: User is ineligible for free-tier. Reason: Your current account is not eligible for Antigravity. Try signing in with another personal Google account."; + yield* Deferred.fail( + harness.authenticated, + new AcpErrors.AcpRequestError({ + code: -32603, + errorMessage: reason, + method: "authenticate", + }), + ); + const failed = yield* phase(harness.auth, "failed"); + assert.equal(failed.message, reason); + const other = yield* phase(harness.auth, "failed", otherOwner); + assert.equal(other.message, "Sign-in failed in another client."); + yield* Deferred.await(harness.closed); + }), + ); + + it.effect("keeps the generic failure when an authenticate error could leak a URL", () => + Effect.gen(function* () { + const harness = yield* makeHarness(); + yield* harness.auth.controller.start(owner); + yield* phase(harness.auth, "waiting"); + yield* Deferred.fail( + harness.authenticated, + new AcpErrors.AcpRequestError({ + code: -32603, + errorMessage: `Onboarding failed ${callbackUrl}`, + method: "authenticate", + }), + ); + const failed = yield* phase(harness.auth, "failed"); + assert.equal(failed.message, "Google sign-in failed. Start sign-in again."); + yield* Deferred.await(harness.closed); + }), + ); + + it.effect.each([ + ["a percent-encoded callback", "callback=http%3A%2F%2F127.0.0.1%3A51234%2F%3Fcode%3Dtest-code"], + ["an email address", "Account alice@example.com is not eligible"], + ["a key=value fragment", "reason=invalid"], + ["only digits and punctuation", "555-123-4567"], + ["a scheme without slashes", "Onboarding failed: See https:example.com for help."], + ["a bare hostname", "Onboarding failed. Visit support.google.com for help."], + ["a hyphenated credential", "Invalid token sk-123456789012345678901234567890"], + ] as const)( + "keeps the generic failure when an authenticate error contains %s", + ([, errorMessage]) => + Effect.gen(function* () { + const harness = yield* makeHarness(); + yield* harness.auth.controller.start(owner); + yield* phase(harness.auth, "waiting"); + yield* Deferred.fail( + harness.authenticated, + new AcpErrors.AcpRequestError({ code: -32603, errorMessage, method: "authenticate" }), + ); + const failed = yield* phase(harness.auth, "failed"); + assert.equal(failed.message, "Google sign-in failed. Start sign-in again."); + yield* Deferred.await(harness.closed); + }), + ); + it.effect("does not call callback HTTP success a successful Google sign-in", () => Effect.gen(function* () { const harness = yield* makeHarness(); @@ -297,9 +364,16 @@ it.layer(NodeServices.layer)("AntigravityAuth", (it) => { .complete(owner, { flowId: state.flowId!, callbackUrl: invalidUrl }) .pipe(Effect.exit); assert.isTrue(Exit.isFailure(result)); + assert.equal( + (yield* phase(harness.auth, "waiting")).inputError, + "This redirect URL does not belong to the current sign-in.", + ); + assert.isNull((yield* phase(harness.auth, "waiting", otherOwner)).inputError); } assert.equal(harness.forwarded(), 0); assert.equal((yield* phase(harness.auth, "waiting")).authorizationUrl, authorizationUrl); + yield* harness.auth.controller.complete(owner, { flowId: state.flowId!, callbackUrl }); + assert.isNull((yield* phase(harness.auth, "verifying")).inputError); yield* harness.auth.controller.cancel(owner, state.flowId!); }), ); diff --git a/apps/server/src/provider/AntigravityAuth.ts b/apps/server/src/provider/AntigravityAuth.ts index ea1c8f7448cc2..86dcd279f450a 100644 --- a/apps/server/src/provider/AntigravityAuth.ts +++ b/apps/server/src/provider/AntigravityAuth.ts @@ -96,10 +96,42 @@ function visibleSnapshot(snapshot: AuthSnapshot, ownerSessionId: string): Provid authorizationUrl: null, interaction: null, expiresAt: null, - ...(busy ? { message: "Sign-in is in progress in another client." } : {}), + inputError: null, + ...(busy + ? { message: "Sign-in is in progress in another client." } + : snapshot.state.phase === "failed" + ? { message: "Sign-in failed in another client." } + : {}), }; } +const MAX_PROVIDER_REASON_LENGTH = 300; + +/** + * Antigravity rejections such as "account not eligible" carry an actionable, + * human-readable reason. Show it, but only when it is short and cannot leak a + * URL, email, token, or path into the UI. + */ +function providerReason(message: string): string | undefined { + const text = message + .replace(/\p{Cc}+/gu, " ") + .replace(/\s+/g, " ") + .trim(); + if (text.length === 0 || text.length > MAX_PROVIDER_REASON_LENGTH) return undefined; + if (!/\p{L}/u.test(text)) return undefined; + // Allowlist plain prose. This excludes URLs (encoded or not), paths, emails, + // and key=value fragments without enumerating each leak shape. + if (!/^[\p{L}\p{N} .,:;'"()!?-]+$/u.test(text)) return undefined; + // Scheme-like ("https:example.com") and hostname-like ("support.google.com") + // runs pass the character allowlist but still name a location. Prose puts + // a space after "." and ":". + if (/[\p{L}\p{N}][.:][\p{L}\p{N}]/u.test(text)) return undefined; + // Credential-shaped runs: a long unbroken token, or a long digit run, even + // when hyphens split it ("sk-1234..."). + if (/\S{20,}/u.test(text) || /\p{N}{8,}/u.test(text)) return undefined; + return text; +} + function safeAuthFailure(cause: Cause.Cause, usesBrowser: boolean): string { const error = Cause.findErrorOption(cause); if (Option.isSome(error)) { @@ -119,6 +151,10 @@ function safeAuthFailure(cause: Cause.Cause, usesBrowser: boolean): str if (!usesBrowser && error.value.code === -32602) { return "Antigravity rejected the configured credentials. Check the provider settings."; } + if (error.value.method === "authenticate") { + const reason = providerReason(error.value.errorMessage); + if (reason) return reason; + } } } return usesBrowser @@ -226,6 +262,7 @@ export const makeAntigravityAuth = Effect.fn("makeAntigravityAuth")(function* < phase: Exit.isSuccess(result) ? "succeeded" : "failed", authorizationUrl: null, expiresAt: null, + inputError: null, message: Exit.isSuccess(result) ? usesBrowser ? "Signed in with Google." @@ -276,6 +313,7 @@ export const makeAntigravityAuth = Effect.fn("makeAntigravityAuth")(function* < ...flow.state, phase: "verifying", authorizationUrl: null, + inputError: null, message: "Checking Antigravity access and models.", }); }), @@ -306,6 +344,7 @@ export const makeAntigravityAuth = Effect.fn("makeAntigravityAuth")(function* < phase, authorizationUrl: null, expiresAt: null, + inputError: null, message, }); return true; @@ -398,12 +437,19 @@ export const makeAntigravityAuth = Effect.fn("makeAntigravityAuth")(function* < options.instanceId, flow.pending, input.callbackUrl, + ).pipe( + // The flow keeps waiting for a correct paste, so show why this one + // was refused without ending it. The detail is a fixed message. + Effect.tapError((error) => + publishFlow(flow, { ...flow.state, inputError: error.detail }), + ), ); flow.callbackSent = true; yield* publishFlow(flow, { ...flow.state, phase: "verifying", authorizationUrl: null, + inputError: null, message: "Waiting for Google to finish sign-in.", }); const forwarding = yield* ( @@ -452,6 +498,7 @@ export const makeAntigravityAuth = Effect.fn("makeAntigravityAuth")(function* < phase: "cancelled", authorizationUrl: null, expiresAt: null, + inputError: null, message: "Google sign-in was cancelled by sign-out.", }); } diff --git a/apps/web/src/components/settings/ProviderAuthenticationSection.tsx b/apps/web/src/components/settings/ProviderAuthenticationSection.tsx index 9e3037c79a48c..078cce689382b 100644 --- a/apps/web/src/components/settings/ProviderAuthenticationSection.tsx +++ b/apps/web/src/components/settings/ProviderAuthenticationSection.tsx @@ -90,7 +90,8 @@ export function ProviderAuthenticationSection({ : needsExternalSetup ? "No in-app sign-in advertised. Follow the provider's docs to finish setup." : `Sign in on ${environmentLabel}.`; - const statusMessage = auth?.phase === "failed" ? auth.message : null; + const statusMessage = + auth?.phase === "failed" ? auth.message : auth?.phase === "waiting" ? auth.inputError : null; const disabled = readOnly || pending || query.error !== null || isDiscovering; const draftId = `${auth?.flowId ?? ""}:${interaction?.id ?? ""}`; const values = draft.id === draftId ? draft.values : {}; diff --git a/apps/web/src/components/settings/ProviderSetupSection.browser.test.tsx b/apps/web/src/components/settings/ProviderSetupSection.browser.test.tsx index d65046fd2b9c8..be266d60ebdc1 100644 --- a/apps/web/src/components/settings/ProviderSetupSection.browser.test.tsx +++ b/apps/web/src/components/settings/ProviderSetupSection.browser.test.tsx @@ -227,6 +227,18 @@ describe("Antigravity setup", () => { expect(occurrences("Signed in.")).toBe(1); }); + it("shows why a pasted redirect URL was refused while the flow keeps waiting", async () => { + const refused = "This redirect URL does not belong to the current sign-in."; + setup.auth = authState({ message: "Open the Google sign-in link.", inputError: refused }); + await renderSetup(); + expect(occurrences(refused)).toBe(1); + expect(occurrences("Open the Google sign-in link.")).toBe(0); + + setup.auth = authState({ message: "Open the Google sign-in link.", inputError: null }); + await publish(); + expect(occurrences(refused)).toBe(0); + }); + it("offers sign-in again when credentials expire after a completed auth flow", async () => { setup.auth = authState({ phase: "succeeded", diff --git a/packages/contracts/src/providerSetup.ts b/packages/contracts/src/providerSetup.ts index 69394bed3c146..d97d24460b36f 100644 --- a/packages/contracts/src/providerSetup.ts +++ b/packages/contracts/src/providerSetup.ts @@ -130,6 +130,9 @@ export const ProviderAuthState = Schema.Struct({ authorizationUrl: Schema.NullOr(Schema.String), expiresAt: Schema.NullOr(IsoDateTime), message: Schema.NullOr(Schema.String), + // Why the last pasted redirect URL was rejected. The flow is still waiting, + // so this is not a failure and clears once a paste is accepted. + inputError: Schema.optionalKey(Schema.NullOr(Schema.String)), // Newer servers may add method types, interactions, or owners; older // clients drop what they cannot decode instead of rejecting the state. methods: Schema.optionalKey(