Skip to content

Allow ChatGPT connector OAuth redirect URIs - #5

Merged
aterga merged 3 commits into
mainfrom
claude/zealous-archimedes-qi8b42
Jun 17, 2026
Merged

aterga merged 3 commits into
mainfrom
claude/zealous-archimedes-qi8b42

Conversation

@aterga

@aterga aterga commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Problem

Adding the connector to ChatGPT Web failed with:

{ "error": "invalid_request", "error_description": "unknown client_id / redirect_uri" }

ChatGPT Web uses a redirect URI of the form https://chatgpt.com/connector/oauth/<id>, but validate_client in src/auth.rs only accepted loopback callbacks, so the authorize request was rejected.

Change

In src/auth.rs:

  • Renamed is_loopback_redirect → is_allowed_redirect and added https://chatgpt.com/connector/oauth/ to the accepted prefixes (loopback callbacks still accepted).
  • Updated the call site in validate_client.
  • Updated the doc comments to reflect that redirect URIs are restricted to loopback plus ChatGPT connector OAuth callbacks.

Verification

cargo build succeeds (only a pre-existing, unrelated dead-code warning).

🤖 Generated with Claude Code


Generated by Claude Code

ChatGPT Web uses https://chatgpt.com/connector/oauth/<id> as its OAuth
redirect URI, which the server rejected because validate_client only
accepted loopback callbacks. Rename is_loopback_redirect to
is_allowed_redirect and additionally permit ChatGPT connector OAuth
callbacks.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011whdm4khV3aoLP3F3DbdZP
@aterga
aterga marked this pull request as ready for review June 17, 2026 21:01
@aterga
aterga requested a review from Copilot June 17, 2026 21:01
Connecting the MCP server as a custom connector via Claude Web failed
with the same unknown client_id / redirect_uri error as ChatGPT, because
Claude.ai's hosted surfaces (web, Desktop, mobile, Cowork) use the fixed
callback https://claude.ai/api/mcp/auth_callback, which is_allowed_redirect
did not accept. Add it to the allow list.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011whdm4khV3aoLP3F3DbdZP

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the OAuth client redirect URI validation to allow ChatGPT Web’s connector OAuth callback URLs (in addition to loopback redirects), so ChatGPT Web can complete the authorize request without being rejected by validate_client.

Changes:

  • Expand redirect URI allowlist logic (rename is_loopback_redirect → is_allowed_redirect) to include https://chatgpt.com/connector/oauth/….
  • Update validate_client to use the renamed allowlist helper.
  • Update doc comments to describe the expanded redirect restrictions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/auth.rs Resolved
Comment thread src/auth.rs Resolved
A bare starts_with("http://localhost") also matched hosts like
http://localhost.evil.com and http://localhost@evil.com, which approve()
would then use to build the redirect — an open redirector. Match the
loopback host exactly by requiring it to end at a ':' (port), '/' (path),
or end of string, and add unit tests for accepted and rejected
redirect_uri cases.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011whdm4khV3aoLP3F3DbdZP
@aterga
aterga merged commit c5adc3a into main Jun 17, 2026
aterga added a commit that referenced this pull request Jul 17, 2026
…origin for OQL reads (Tiers 0–1) (#61)

* Make per-app reads self-correcting: surface auth as the missing ingredient (Tiers 0-1)

Anonymous per-app reads come back empty because the data is gated by the
caller's principal, and nothing in the old tool surface signalled that
authentication — not "no data" — was the missing ingredient. An agent asked a
"my data in this app" question would read empty, guess bespoke method/entity
names, and thrash before stumbling onto passing the app_url. This reworks the
return payloads, error messages, capability flags, and the server-instructions
playbook so the authenticated path is the obvious one and an empty read is
self-explaining.

Tier 0
 #1 Empty reads now carry an auth signal. get_canister_oql_schema,
    run_canister_oql_query, and call_canister query results always echo
    is_anonymous (alongside acted_as_principal / derived_for_origin). When a read
    is anonymous AND empty, they append a note: empty here most likely means "not
    authenticated as your account", so re-run adding the origin. Computed only
    from local facts (anonymous && empty) — never by probing whether
    authenticated data exists — and the origin stays a placeholder the agent
    fills, never one guessed via app_url_default.

Tier 1
 #2 Rewrote the server-instructions playbook: open_app FIRST for a named app; a
    "my/our…" question is an authenticated read (pass the origin); anonymous
    per-app reads usually return empty and that's an auth artifact; call
    get_canister_api_doc only when candid says it's available; oql:true => reads
    via the OQL tools, call_canister is updates-only. Dropped the old
    "discover_app_canisters first" / "get_canister_api_doc FIRST" advice.
 #3 open_app / discover_app_canisters now probe each app-owned canister's Candid
    once (enrich_capabilities) and attach oql / api_doc_available flags plus a
    caller-gated data-access note bound to the resolved derivation_origin. Scoped
    by is_app_data_candidate to the app's own data canisters — never
    II/NNS/ledger/frontend — per the origin-resolution trust boundary.
 #4 get_canister_candid reports api_doc_available, computed with the same
    predicate get_canister_api_doc uses, so the api-doc call is gated on it.
 #5 The call_canister OQL-rejection message names the replacement path
    (icp_oql_guide -> get_canister_oql_schema -> run_canister_oql_query) and the
    auth hint (pass the origin for the user's own data).
 #6 get_canister_api_doc returns a structured result in every case
    (available/expected/retry/next), distinguishing an expected absence from an
    unreachable canister instead of one opaque error.
 #7 run_canister_oql_query validates the query's start entity on an empty result
    (validate-on-empty, not preflight) by re-reading the schema for the SAME
    principal, returning valid_entities + a did_you_mean repair (booking ->
    bookings). Hard-validates start only.
 #8 get_canister_oql_schema emits a ready-to-run run_canister_oql_query example
    per entity, each preserving the identity the schema was read under so copying
    one doesn't silently drop to anonymous.
 #9 Rewrote the OQL tool descriptions (guide->schema->query; entity names are
    often plural and differ from Candid; my-data => pass origin) and the OQL primer.

Tests cover the new pure helpers (empty detection, entity extraction,
did_you_mean, examples, conservative empty-reply detection, app-data-candidate
scoping) and the enriched OQL-rejection message. Tier 2 (auto-authenticated
reads / open_app_as_me) is left to a follow-up.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HRpq9CvXFNhkr2roH7j22d

* Address adversarial review: fix empty-diagnosis on error paths, app_url mis-hints, unparsed-reply note

Folds in the confirmed findings from an adversarial review of the Tier 0-1 diff
(4 dimensions x per-finding verification). No high-severity findings; the
security-guardrail dimension found nothing.

 - diagnose_empty_oql now takes an EmptyContext. On a FAILED result (trap / OQL
   error arm) it emits ONLY the #7 unknown-`start` repair, never the "came back
   empty => likely not authenticated" / "no entities here" notes — those describe
   an EMPTY result and would contradict a genuine error message. (Previously an
   anonymous query with a valid start that ERRORED got a misleading re-authenticate
   hint.)
 - diagnose_empty_oql distinguishes a FAILED schema re-read (entities: None) from a
   schema that genuinely lists no entities (Some([])), so a transient schema-read
   failure on an authenticated empty-table result no longer mislabels it "this
   account sees no entities" — it falls back to the benign "0 rows" note.
 - Dropped the "(or app_url)" hint for the OQL read tools in three places (the
   open_app data-access handle, the open_app description, and the server-instructions
   MY/OUR block): get_canister_oql_schema / run_canister_oql_query take only
   `derivation_origin`; `app_url` is call_canister's. Offering it sent the agent to
   a param those tools silently ignore -> an anonymous empty read.
 - The OQL Unrecognized-result arm now carries a structured `note` ("not an empty
   result; raw reply is in the text block"), so a structured-only consumer doesn't
   misread a non-tabular reply as "no data".
 - Fixed the candid_reply_is_empty doc to match the implementation: it recognizes
   `variant { none }` only; an explicit `variant { err = … }` is a real error, not
   "empty" (with a test assertion locking that contract in).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HRpq9CvXFNhkr2roH7j22d

* Build OQL example query with serde_json so untrusted entity names are escaped

Addresses a Copilot review comment on PR #61: oql_query_examples built the
example `query` JSON string with format!, so a schema entity name containing a
quote or backslash — the schema is canister-supplied, hence untrusted — would
produce invalid JSON in the (advisory) example. Build the query object via
serde_json::json!(...).to_string() instead, which escapes it. Added a test with
a quoted entity name asserting both the args and the inner query string parse as
valid JSON and the name round-trips.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HRpq9CvXFNhkr2roH7j22d

* Require an origin for OQL reads: disable anonymous per-app reads for now

Per maintainer direction, replace the soft "anonymous empty read" auth note on
the OQL read tools with a hard precondition: get_canister_oql_schema and
run_canister_oql_query now REJECT a call with no derivation_origin, since they
read per-app data gated by the caller's principal (an anonymous read is signed as
2vxsx-fae and returns nothing useful). The rejection names what to pass and points
at open_app / resolve_app so the agent recovers in one step. A hard reject can't
be misread as "no data" the way an empty result can.

Rationale for no anonymous escape hatch: authenticating never hurts a public read
— the canister serves the request regardless of principal, so a caller with no
account there simply isn't blocked. So there's no case that needs anonymous.

Scope:
 - Applies to the two OQL read tools only (the definitively caller-gated per-app
   data surface). The guards are a two-line origin.is_none() check, so re-enabling
   anonymous later is a trivial revert — the is_anonymous field and the empty-read
   diagnostics are left intact and simply aren't reached while the guards stand.
 - call_canister stays permissive (keeps its soft empty-read note): it's the
   general-purpose tool used for genuinely public canisters like ledgers, where
   there's often no app origin to pass and hard-blocking would break common public
   reads for no gain.
 - Public-metadata tools (get_canister_candid, get_canister_api_doc,
   discover_app_canisters, resolve_app) are unaffected — they read public data and
   take no origin.

Updated the OQL tool descriptions, the server-instructions playbook, the
get_canister_candid OQL note, open_app's description + data-access note, and the
OQL primer to say the OQL reads REQUIRE the origin (not "anonymous comes back
empty"). Added a test that the rejection message is actionable.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HRpq9CvXFNhkr2roH7j22d

* Sync README with the tool changes (capability flags, structured api-doc, require-origin OQL reads)

The README tool table + flow drifted from the code. Brought them current:
 - get_canister_candid now advertises both `oql` and `api_doc_available` flags.
 - get_canister_api_doc is call-only-when-available and returns a structured
   available/expected/retry/next result (not "call first for an unfamiliar app").
 - get_canister_oql_schema / run_canister_oql_query now REQUIRE derivation_origin
   (anonymous per-app reads are rejected for now); noted the per-entity examples
   and the empty-result start validation / did_you_mean.
 - open_app / discover_app_canisters now report per-canister oql/api_doc_available
   capability flags + the caller-gated data-access note.
 - Typical flow + OQL section updated to say the OQL read tools require the origin
   while public metadata and call_canister public reads stay anonymous.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HRpq9CvXFNhkr2roH7j22d

---------

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants