Repository navigation
feat(connect): browser-login choice in Connect (Spec 132 PR-3) - #2025
Conversation
…ec 132 PR-1a) Related #1971
…132 PR-1a) Related #1971
… 132 PR-1b) Related #1971
…mic (Spec 132 PR-1b) Related #1971
…132 PR-1c) Related #1971
…132 PR-1a) Related #1971
…(Spec 132 PR-1c) Related #1971
…ts (Spec 132 PR-1c) Related #1971
…into feat/client-oauth-login-storage
…Spec 132 PR-1d) Related #1971
… 132 PR-1d) Related #1971
…on (Spec 132 PR-1d) Related #1971
…back (Spec 132 PR-1d) Related #1971
…PR-1e) Public OAuth endpoints behind the three-state gate (metadata, register, authorize, token), the /mcp/oauth[/<client>] resource chain that authenticates mcp_oat_ tokens on every request, the mcp_oat_ refusal on the classic MCP routes, admin REST for sign-in requests, per-login and API-key revoke, credentials[] on client payloads, and the oauth credential kind on activity rows. Related #1971
…Spec 132 PR-1e) Register takes exactly one JSON object as application/json; mcp_oat_ is refused on classic MCP routes whatever the bearer whitespace and on the REST API with the client-credential 403; once used every client row carries credentials and browser_login_disabled (install-wide); open requests and SSE streams end with their login (revoke, forget, switch-off, rotation, expiry); cross-origin and cross-site posts to register and token are refused; an unreadable ever-used marker reads as used; OAuth routes answer 404 behind a proxy header. Related #1971
… (Spec 132 PR-1e) Cancelling a tracked request also sets immediate read and write deadlines so a handler blocked in a write or a body read ends; the watcher is stopped and joined at shutdown (also in StopServer). A monotonic switch-off epoch makes a quick off then on still end requests authenticated before it. Tests cover blocked write, stalled upload, shutdown, quick off/on, and client revoke, client forget and refresh-token replay ending only the affected stream. Related #1971
…2 PR-1e) The switch-off epoch is counted when the disabled configuration is published, so a request that authenticated under the enabled one is always older than it. Stream tracking has a stopping flag checked under the mutex that creates the registry, and a fresh lifecycle per server run; a refused request is answered 503 without invoking the MCP handler. Related #1971
… server run (Spec 132 PR-1e) A switch-off whose publish fails no longer ends live streams: the epoch is counted only after a successful publish while the lifecycle lock is always released. A request captures a server-run generation before authenticating and is refused (503, handler not invoked) if it registers in another run. Related #1971
…er login (Spec 132 PR-1f) scripts/test-client-oauth-e2e.sh drives a real ./mcpproxy on a scratch data dir through default off, discovery, registration, authorize, admin approve, PKCE exchange, MCP over the login, wrong doors, refresh and replay, revoke/forget, guard refusal, rate limits, off after use and on again. Also adds docs/features/client-oauth-login.md, the CLAUDE.md entry, and specs/132-client-oauth-login/verification/real-clients.md (SDK client verified; Claude Code, Cursor, VS Code and Inspector not verified). Related #1971
…132 PR-1f) Related #1971
…c 132 PR-1f) Related #1971
Web UI consent page at /ui/authorize for browser sign-in requests, with
the generic-address name suggestion.
- suggested_client on GET /api/v1/oauth/authorizations/{id} (generic
address only): the sanitised reported name, trimmed and case-insensitive,
compared with each existing client's id, display name and known client
names (whole name, and the part before a trailing parenthesised suffix);
exactly one distinct client -> {id, matched}, none or several -> absent.
Computed on read, never stored, never applied by the server: preview
without a client answers complete:false, approve answers client_required.
- Content-Security-Policy frame-ancestors 'none' and X-Frame-Options DENY
on /ui/authorize.
- AuthorizeRequest.vue, /authorize route, API methods and types: fixed or
chosen client, unverified-name label, access sentence, profile shown or
asked, replace-login checkbox, guard verdict through preview with fixes,
no-API-key mode, already_decided / binding_changed / 404 handling.
- Docs: REST reference and docs/features/client-oauth-login.md.
Related #1971
- /ui/authorize frame headers: case-insensitive on the cleaned path (Vue Router matches case-insensitively and the SPA answers unknown paths). - suggested_client: compare with strings.EqualFold (Unicode folding), strip one balanced trailing parenthesised group (nested parentheses allowed); tests for display-name-only, display name over known name, sigma forms, nested suffix and whole-name vs stripped-name ambiguity. Related #1971
…Spec 132 PR-2a) - Page: a new ?request= id clears the page and reloads (generation check); decisions go to the loaded request. Approve needs a complete preview with access for the current choice and sends exactly the body it answered. The replace-login option is tied to the client that owns the previous login. The new-client draft is always filled from suggested_new_client. One decision per page: both buttons guarded, terminal after success. - Backend: previous_login carries client_id; a replace_grant that is a live login of this registration owned by another client is refused (422, field replace_grant). Related #1971
- Decision answers are ignored once the request was left (new id) or the page unmounted: no navigation, no state change, no release of a newer request's pending decision. - A preview refused with binding_changed reloads the request (keeping the user's choice when it still exists) and shows the review-again notice. - With no profiles configured an unbound client starts on "All servers", so the select shows what is submitted. Related #1971
…pec 132 PR-1e) After StopServer and a new StartServer in one process, the context watcher of the stopped run called StopServer once more and its exit path cleared the running state; either could land on the new run and leave it stopped. The watcher's stop and the exit cleanup are now bound to their own run. Found through TestOAuthStreams_StopThenStartTracksAgain failing in CI. Related #1971
…c 132 PR-1e) StopServer captured the HTTP server at entry but cancelled and unmarked whatever run was current at its end. It now cancels the context of the run it began stopping and clears state only while that run is current. Related #1971
…to feat/client-oauth-login-e2e
…o feat/client-oauth-login-consent
CLAUDE.md reached 40,631 characters with the Spec 132 entry, over the 40,000 limit of the check-size job. Remove the seven oldest entries (specs 108, 109, 115, 116 and 117 PR-1/PR-2); their docs pages are unchanged. Related #1971
…o feat/client-oauth-login-consent
…in-consent # Conflicts: # docs/features/client-oauth-login.md
… into feat/client-oauth-login-hub
TestWebUISweepSpecListIsComplete requires every spec under e2e/web-ui-sweep to be run by a launcher and named in the two docs. The sweep core now starts with MCPPROXY_MCP_OAUTH_ENABLED=true and run-web-smoke.sh runs client-oauth-consent.spec.ts (9 tests) with the other specs: 136 passed, 3 skipped locally. Related #1971
… into feat/client-oauth-login-hub
…in-hub # Conflicts: # docs/features/client-oauth-login.md # frontend/src/services/api.ts
…o feat/client-oauth-login-tray
…in-tray # Conflicts: # docs/features/client-oauth-login.md
…to feat/client-oauth-login-connect
…Spec 132 PR-3) A created-file undo record now authorises an Undo only while the per-config state file (<config>.undo.state: current generation id, pending flag) is readable, not pending and names the generation the record carries. A browser-login connect marks the state pending before the config write and commits a new random generation after it; any failure before the write restores the previous state exactly, a crash or failed commit leaves it pending and Undo refuses. An API-key connect, a disconnect or an undo moves the state along only if the file already exists, so older records are superseded even when their retirement fails; an install that never used browser login gets no new file. The state file goes with the last record. The wall-clock ordering is removed. A post-write verification failure now names the backup (browser-login) and any undo-record note in its error text. Related #1971
… (Spec 132 PR-3) Within a process every write of one config (connect of either auth mode, disconnect, undo) runs under a per-config-path mutex. Across processes the pending undo state carries a random owner token: commit and rollback re-read it and write only while it is still pending under that token; a refused rollback changes nothing, a refused commit after the config was written leaves the state pending, and a writer that finds another owner's pending state takes it over. A writer that saw no state file before its write advances one that appeared during it. The state and record files are fsynced before their rename and the directory after it; a sync failure on the pending step stops the connect before the config is written. The state is parsed strictly: all fields present with the right types, the right version, hex generation ids, an owner only while pending. Related #1971
…te (Spec 132 PR-3) Every writer of one config (connect, disconnect, undo; each OpenCode candidate file under its own lock) now holds, for its whole undo-state transaction, the in-process mutex (keyed by the symlink-resolved path) and then, on Unix, an exclusive flock on the config's directory (its nearest existing ancestor while it does not exist), which creates no file and is waited for at most about 10 seconds before the writer fails with nothing written. A pending state found under the lock is a crashed writer's, and a rollback restores the snapshot taken under the lock, so no live writer's state is taken over or restored over. The owner token stays as defence in depth, and Windows keeps the mutex and token. The OpenCode alternate-config disconnect now runs the same lock, transaction and cleanup as the first candidate. The state parser requires exactly one JSON value (a trailing ] or } is refused). Related #1971
… 132 PR-3) Related #1971
Deploying mcpproxy-docs with
|
| Latest commit: |
af0d13b
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://39ff7ae5.mcpproxy-docs.pages.dev |
| Branch Preview URL: | https://feat-client-oauth-login-conn.mcpproxy-docs.pages.dev |
…PR-3) CodeQL flags a single-pass comment removal as incomplete sanitization. Related #1971
| } | ||
|
|
||
| func checkUndoRecordFile(path, backupPath, clientID, serverName string, current []byte, gate stateGate) (undoVerdict, string) { | ||
| raw, err := os.ReadFile(path) |
There was a problem hiding this comment.
False positive, no change: the path is the server-resolved client config path plus a backup name that Undo accepts only as a bare filename belonging to that config (internal/connect/undo.go, the filepath.Base and prefix checks).
🤖 Addressed by Claude Code
| // removeUndoRecord deletes one record, best effort ("" is a no-op). | ||
| func removeUndoRecord(path string) { | ||
| if path != "" { | ||
| _ = os.Remove(path) |
There was a problem hiding this comment.
False positive, no change: same path as above — a record file beside the server-resolved client config, found by listing that directory, never taken from the request.
🤖 Addressed by Claude Code
The golden holds macOS client config paths, so it failed on the Linux runner. Related #1971
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
📦 Build ArtifactsWorkflow Run: View Run Available Artifacts
How to DownloadOption 1: GitHub Web UI (easiest)
Option 2: GitHub CLI gh run download 45340399200 --repo smart-mcp-proxy/mcpproxy-go
|
## Summary Follow-up to #2025 for the CodeQL alerts it left open. - **`go/path-injection` (alerts 902, 903; `internal/connect/undo_record.go`)**: Undo built the backup path, and from it the undo record path, out of the backup name in the request. The name was already validated (bare filename, `<config>.bak.` prefix), which CodeQL cannot see. Undo now looks the name up in the config directory and builds the path from the name the directory lists. A name that is not listed gets the same `not_found` answer as before. - CodeQL on this PR no longer reports those two, nor the older alert 164 (`internal/connect/connect.go`), which had the same source. Not changed: alert 904 (`go/weak-sensitive-data-hashing`). `fileDigest` is a change detector for the config file a connect wrote, not a credential hash; going through `hash.Hash` made no difference to CodeQL, so the body is the original direct call with a comment. A test pins the value to plain SHA-256. The alert needs a dismissal. Also not changed: alert 900 (`go/unvalidated-url-redirection`, `internal/server/oauth_login_http.go`). That redirect goes to the client's registered `redirect_uri`, which is what OAuth requires; it was dismissed as a false positive. ## Testing - `go test -race ./internal/connect/ ./internal/httpapi/` - `golangci-lint run --config .github/.golangci.yml ./internal/connect/...`: 0 issues - `GOOS=windows go vet ./internal/connect/` Related #1971
Summary
Last slice of Spec 132 (browser login for MCP clients, off by default). Connect can now write a client's browser sign-in address instead of an API key.
mcpproxy connect <client> --auth key|oauth(defaultkey).oauthwrites<base>/mcp/oauth/<client-id>with no header and no credential, and never mints or revokes a key.mcp_oauth_enabledis on, the build is the personal edition and the client is markedSupportsBrowserLogin. Today that isclaude-codeonly, the one client with a recorded real-client check. Otherwise the request is refused with HTTP 400 / CLI exit 1.ClientConnectList.vue) and the macOS Connect sheet show the choice only whenbrowser_login_availableis true. Payload gainssupports_browser_login,browser_login_availableandauth.Undo for browser-login connects
A browser-login entry has no key to replay, so Undo is authorised by a record written beside the config:
<config>.undo.statenames the current generation. A created-file record counts only while the state is well formed, not pending, and names that record's generation. Anything else isconflict.cleanup_errorand never fails the connect.flockon the config's directory. No lock file is created.What does not change
feature_off_payloads.golden.jsonand a no-extra-file test).mcp_oauth_enabledoff, payloads are unchanged apart from the two new boolean fields.Known limits
conflictuntil the next successful write.Testing
go test -race ./internal/connect/... ./internal/httpapi/... ./cmd/mcpproxy/..., the same under-tags serverfor connect and httpapi: pass.golangci-lintwith the CI config, bare and--build-tags server: 0 issues.GOOS=windows go build ./...andgo vet: clean.scripts/test-client-oauth-e2e.sh: 183 passed.scripts/test-api-e2e.sh: 77 passed.gpt-6.1-sol): 15 rounds, last one clean.Related #1971