Skip to content

Commit d21da16

Browse files
cliffhallclaude
andcommitted
refactor(auth): address review — accurate toast copy, document state asymmetry, tighten test
- Soften the OAuth-callback-rejected toast: the shape guard is defense-in-depth, not full CSRF prevention (PKCE remains primary), so the message no longer overstates ("rejecting to prevent a cross-site request" -> "did not originate from this session"). - Document the intentional asymmetry between a present-but-malformed `state` (rejected) and a wholly absent `state` (accepted, matched via OAUTH_PENDING_SERVER_KEY) — rejecting the null case would mask real provider error redirects that omit `state`. - Make the "valid state is not rejected" test assert the specific downstream "could not be matched" toast (seeding OAUTH_PENDING_SERVER_KEY) instead of an indirect "some toast fired" check. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01S3fTN8H3R8YV4yUGvZjYnX
1 parent 2b84281 commit d21da16

2 files changed

Lines changed: 33 additions & 9 deletions

File tree

‎clients/web/src/App.test.tsx‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ vi.mock("./components/views/InspectorView/InspectorView", () => ({
404404
}));
405405

406406
import App from "./App";
407+
import { OAUTH_PENDING_SERVER_KEY } from "./utils/oauthFlow";
407408
import * as McpIndex from "@inspector/core/mcp/index.js";
408409
import * as FetchLogModule from "@inspector/core/mcp/state/fetchRequestLogState.js";
409410
import { useManagedRequestorTasks } from "@inspector/core/react/useManagedRequestorTasks.js";
@@ -1625,9 +1626,16 @@ describe("App OAuth callback state validation", () => {
16251626
});
16261627

16271628
it("does not reject when the state param parses to a valid authId", async () => {
1628-
// A well-formed 64-char-hex state is accepted; the handler proceeds past
1629-
// the rejection guard (it fails later for other reasons in this harness,
1630-
// but never shows the 'OAuth callback rejected' toast).
1629+
// A well-formed 64-char-hex state passes the shape guard, so the handler
1630+
// proceeds to the server-matching step. With no server registered under the
1631+
// seeded pending id, that step surfaces the "could not be matched" toast —
1632+
// asserting on that specific downstream toast proves the state was accepted
1633+
// (never the "OAuth callback rejected" toast) rather than relying on an
1634+
// indirect "some toast fired" check.
1635+
window.sessionStorage.setItem(
1636+
OAUTH_PENDING_SERVER_KEY,
1637+
"server-that-does-not-exist",
1638+
);
16311639
window.history.replaceState(
16321640
{},
16331641
"",
@@ -1636,7 +1644,13 @@ describe("App OAuth callback state validation", () => {
16361644

16371645
renderWithMantine(<App />);
16381646

1639-
await waitFor(() => expect(notificationsMock.show).toHaveBeenCalled());
1647+
await waitFor(() =>
1648+
expect(notificationsMock.show).toHaveBeenCalledWith(
1649+
expect.objectContaining({
1650+
title: "OAuth callback could not be matched",
1651+
}),
1652+
),
1653+
);
16401654
expect(notificationsMock.show).not.toHaveBeenCalledWith(
16411655
expect.objectContaining({ title: "OAuth callback rejected" }),
16421656
);

‎clients/web/src/App.tsx‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,10 +1473,20 @@ function App() {
14731473
// rebuilt client can restore those `auth` entries. Read it before the
14741474
// URL is cleared below.
14751475
//
1476-
// CSRF hardening: a `state` that is present but does not parse to our
1477-
// expected 64-char-hex authId shape is a forgery indicator — the value
1478-
// did not originate from `generateOAuthState`. Reject the callback with a
1479-
// clear error instead of silently proceeding with an undefined sessionId.
1476+
// Defense-in-depth: a `state` that is present but does not parse to our
1477+
// expected 64-char-hex authId shape did not originate from
1478+
// `generateOAuthState`, so reject the callback instead of silently
1479+
// proceeding with an undefined sessionId. This is a shape check, not full
1480+
// state-matching — the primary CSRF protection remains PKCE
1481+
// (`code_verifier`); this layer catches malformed/forged `state` early.
1482+
//
1483+
// Intentional asymmetry: a present-but-malformed `state` (including the
1484+
// empty string `?state=`) is rejected, but a wholly absent `state`
1485+
// (`stateParam === null`) is *not* — it falls through with
1486+
// `sessionId = undefined` and is matched via `OAUTH_PENDING_SERVER_KEY`
1487+
// instead. Rejecting the null case would turn any provider error redirect
1488+
// that omits `state` into a misleading "rejected" toast, hiding the real
1489+
// OAuth error surfaced by the `!params.successful` branch below.
14801490
const stateParam = new URLSearchParams(window.location.search).get("state");
14811491
const parsedState = stateParam ? parseOAuthState(stateParam) : null;
14821492
const stateRejected = stateParam !== null && parsedState === null;
@@ -1493,7 +1503,7 @@ function App() {
14931503
notifications.show({
14941504
title: "OAuth callback rejected",
14951505
message:
1496-
"OAuth callback carried an unrecognized state parameter; rejecting to prevent a cross-site request. Please try connecting again.",
1506+
"OAuth callback carried an unrecognized state parameter that did not originate from this session. Please try connecting again.",
14971507
color: "red",
14981508
});
14991509
return;

0 commit comments

Comments
 (0)