-
Notifications
You must be signed in to change notification settings - Fork 925
Harden MCP portal authentication changes #199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dcartertwo
wants to merge
1
commit into
feature/mcp-portal-large-catalogs
Choose a base branch
from
feature/mcp-portal-auth-hardening
base: feature/mcp-portal-large-catalogs
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+196
−9
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
packages/gatekeeper-mcp-portal/__tests__/account-revision.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import { afterEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
| import { | ||
| McpAccountBase, | ||
| type ConnectedServer, | ||
| type ConnectOutcome, | ||
| } from "@gadgets/mcp-shared/account"; | ||
| import { McpAccount } from "../src/portal.js"; | ||
|
|
||
| afterEach(() => vi.restoreAllMocks()); | ||
|
|
||
| describe("McpAccount configuration revision", () => { | ||
| it("records the current revision before handing an OAuth attempt to its callback", async () => { | ||
| const values = new Map<string, unknown>([["portalConfigRevision", "old"]]); | ||
| const ctx = { | ||
| id: { toString: () => "account" }, | ||
| storage: { | ||
| kv: { | ||
| get: (key: string) => values.get(key), | ||
| put: (key: string, value: unknown) => values.set(key, value), | ||
| delete: (key: string) => values.delete(key), | ||
| }, | ||
| }, | ||
| exports: {}, | ||
| }; | ||
| const env = { | ||
| MCP_PORTAL_URL: "https://portal.example.com/mcp", | ||
| MCP_PORTAL_AUTH: "oauth", | ||
| }; | ||
| const server: ConnectedServer = { | ||
| endpoint: env.MCP_PORTAL_URL, | ||
| serverId: "portal", | ||
| serverName: "Portal", | ||
| provenance: "deployment", | ||
| auth: "oauth", | ||
| }; | ||
| const base = McpAccountBase.prototype as unknown as { | ||
| beginConnect(nonce: string, target: ConnectedServer | null): Promise<ConnectOutcome>; | ||
| }; | ||
| vi.spyOn(base, "beginConnect") | ||
| .mockResolvedValue({ kind: "redirect", url: "https://login.example.com" }); | ||
| const account = new McpAccount(ctx as never, env as never); | ||
| const internals = account as unknown as { | ||
| awaitingSelection(nonce: string): boolean; | ||
| server(): ConnectedServer | undefined; | ||
| }; | ||
| vi.spyOn(internals, "awaitingSelection").mockReturnValue(true); | ||
| vi.spyOn(internals, "server").mockReturnValue(server); | ||
|
|
||
| await expect(account.beginConnect("nonce", server)).resolves.toMatchObject({ kind: "redirect" }); | ||
|
|
||
| expect(values.get("portalConfigRevision")).not.toBe("old"); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { fileURLToPath } from "node:url"; | ||
| import capnwebValidate from "capnweb-validate/vite"; | ||
| import { defineConfig } from "vitest/config"; | ||
|
|
||
| export default defineConfig({ | ||
| plugins: [capnwebValidate()], | ||
| test: { | ||
| alias: { | ||
| "cloudflare:workers": fileURLToPath( | ||
| new URL("../mcp-shared/__tests__/stubs/cloudflare-workers.ts", import.meta.url)), | ||
| }, | ||
| }, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The doc-comment above (lines 165-168) is now stale relative to this new logic. It says probing may legitimately move between
noneand OAuth (bidirectionally), butconfigured === "oauth" ? connected === "token" : connected !== configuredonly tolerates that drift when the portal is configured asoauth. When configured asnone, a connectedoauthstate now requires a reconnect (connected !== configured) — the intended new hardening, but it contradicts the comment. Please update the doc to describe the asymmetric rule (an oauth-configured portal may prove public during probing, while an explicitlynone-configured portal stays strict).