Skip to content

Accept ChatGPT's issuer-identification OAuth redirect - #189

Merged
aterga merged 2 commits into
mainfrom
claude/icp-mcp-openai-submission-envi5o
Sep 3, 2026
Merged

aterga merged 2 commits into
mainfrom
claude/icp-mcp-openai-submission-envi5o

Conversation

@aterga

@aterga aterga commented Sep 3, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The OpenAI directory submission fails at the MCP-details step:

MCP details save failed: Dynamic client registration failed: registration endpoint
returned 400 (invalid_redirect_uri: redirect_uri
https://chatgpt.com/connector_platform_oauth_redirect is not permitted: …)

That 400 is ours. DEFAULT_ALLOWED_REDIRECTS pinned only ("chatgpt.com", "/connector/oauth/"), and path_within_prefix matches at segment boundaries, so that prefix can never admit /connector_platform_oauth_redirect.

The submission doc recorded /connector_platform_oauth_redirect as a legacy URI deliberately left out of the allow-list, to be added via OAUTH_ALLOWED_REDIRECT_PREFIXES only "if a reviewer reports a failure." That premise was wrong. Per OpenAI's Apps SDK auth docs the two forms are not old and new but conditional on the authorization server:

ChatGPT sends to an AS that…
https://chatgpt.com/connector/oauth/{callback_id} does not support issuer identification
https://chatgpt.com/connector_platform_oauth_redirect advertises authorization_response_iss_parameter_supported

Our AS metadata advertises authorization_response_iss_parameter_supported: true, so the stable path is the form a ChatGPT connection actually registers with us — which is exactly what DCR was rejecting. Our own correct hardening and our own correct metadata combined into the rejection.

Both paths are now pinned, so neither needs a deploy-time env entry.

Security

The CWE-601 path pin the DEFAULT_ALLOWED_REDIRECTS doc block describes is tightened here, not loosened.

Review (#discussion_r3924369843) caught that the first version of this change was not exact as its comment claimed: path_within_prefix accepts any segment-boundary descendant, so DCR would also have admitted /connector_platform_oauth_redirect/anything. Matching mode is now a per-entry property — PathPin::Exact vs PathPin::Prefix — instead of an implicit property of the matcher, and ChatGPT's stable callback is pinned Exact. No descendant of it is registrable, and no user-content path on the chatgpt.com origin (/g/…, /share/…) ever was.

The nine pre-existing entries keep Prefix, so their behaviour is byte for byte unchanged. Tightening any of them is a separate, deliberate decision: redirect_uri_permitted is re-checked at /oauth/authorize, not only at registration, so narrowing a vendor that appends a path segment would break its already-registered clients mid-flow. OAUTH_ALLOWED_REDIRECT_PREFIXES entries also stay prefixes, as the variable name implies.

The percent-encoding and dot-segment defenses are untouched and still covered by the existing assertions.

Related issues

Surfaced by the live submission attempt for the ChatGPT Plugins Directory; context in docs/openai-directory-submission.md.

Changes

  • src/auth.rs — add ("chatgpt.com", "/connector_platform_oauth_redirect", PathPin::Exact) to DEFAULT_ALLOWED_REDIRECTS, with a comment recording why both ChatGPT paths are pinned.
  • src/auth.rs — introduce PathPin so an entry declares whether its path matches exactly or as a prefix; redirect_uri_permitted honours it. Existing entries and env entries are Prefix, preserving current behaviour.
  • src/auth.rs — extend hosted_redirect_allow_list with the positive case, the non-segment-boundary near-miss (…_redirectEVIL) and the descendant negative (…_redirect/anything); add path_pin_modes covering both modes, the Exact pin on ChatGPT's stable callback, and the invariant that a trailing-slash entry is never Exact.
  • docs/openai-directory-submission.md — correct the readiness row and replace the "legacy redirect" note with the actual rule.

Testing

  • cargo build --locked --workspace --all-targets
  • cargo test --locked --workspace --all-targets — 270 tests, 0 failures
  • cargo clippy --workspace --all-targets — the 9 warnings are pre-existing in imcp2-core (calls.rs, discover.rs, tools.rs, management.rs); none in src/auth.rs, and this change adds none
  • npm test --prefix monitoring/mcp-status — not run; the dashboard is untouched

Both fixes were reproduced before being made. Removing the allow-list entry while keeping the new assertions fails hosted_redirect_allow_list at the positive case; flipping the entry from Exact to Prefix fails both the descendant negative and path_pin_modes. The live 400 was also confirmed directly against https://mcp.internetcomputer.org/mcp/oauth/register, where https://claude.ai/api/mcp/auth_callback registers 201 while all four ChatGPT paths returned invalid_redirect_uri.

A note on cargo fmt --all: it is not run here. Under stable 1.94 defaults it rewrites 19 files / ~4.5k lines across the whole workspace, and even with use_small_heuristics = "Max" it still wants ~6.3k lines, so the tree is not clean under any inferable config and no rustfmt.toml is checked in. The added lines were hand-matched to the surrounding style instead (≤100 columns, wide call style; assertions that would exceed 100 are wrapped the way their neighbours are). Worth settling separately by checking in the config the tree was formatted with.

Checklist

  • I have read the Contributing guidelines.
  • Docs (README / comments) updated for any user-visible change.
  • No secrets, credentials, or internal-only information are included.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd7VT72Qt16qiAJynu9EKj

The OpenAI directory submission failed at the MCP-details step with
`invalid_redirect_uri`: DCR refused
`https://chatgpt.com/connector_platform_oauth_redirect`, since the only
path pinned for `chatgpt.com` was `/connector/oauth/`.

OpenAI's two callback forms are not legacy and current, as the submission
doc assumed, but conditional on the authorization server. ChatGPT sends
`/connector/oauth/{callback_id}` only to a server without issuer
identification, and the stable `/connector_platform_oauth_redirect` to one
advertising `authorization_response_iss_parameter_supported` — which our AS
metadata does, so the stable path is the one a ChatGPT connection actually
registers with us.

Pin both paths in `DEFAULT_ALLOWED_REDIRECTS`. The new entry is an exact
vendor OAuth endpoint, the same shape as the `claude.ai` entry, so the
CWE-601 path pin is unchanged: no user-content path on the origin becomes
registrable, and `hosted_redirect_allow_list` covers the near-miss
(`…_redirectEVIL`) alongside the positive.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd7VT72Qt16qiAJynu9EKj
@aterga
aterga requested a balanced review from Copilot September 3, 2026 12:10
@aterga
aterga marked this pull request as ready for review September 3, 2026 12:11
@aterga
aterga requested a review from a team September 3, 2026 12:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new supposedly exact callback entry also permits arbitrary descendant paths.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds support for ChatGPT’s issuer-identification OAuth callback.

Changes:

  • Allows the stable ChatGPT redirect URI.
  • Adds positive and near-miss tests.
  • Updates submission documentation.
File summaries
File Description
src/auth.rs Adds and tests the callback allow-list entry.
docs/openai-directory-submission.md Documents ChatGPT’s callback-selection behavior.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/auth.rs Resolved
sea-snake
sea-snake previously approved these changes Sep 3, 2026
Review found that the new entry was not exact as its comment claimed:
`path_within_prefix` accepts any segment-boundary descendant, so DCR would
also have admitted `/connector_platform_oauth_redirect/anything`. Correct,
and broader than the single stable endpoint this trusts.

Make the matching mode a per-entry property (`PathPin::Exact` /
`PathPin::Prefix`) instead of an implicit property of the matcher, and pin
the new entry `Exact`.

The nine pre-existing entries keep `Prefix`, so their behaviour is byte for
byte unchanged. Tightening any of them is a separate, deliberate decision:
`redirect_uri_permitted` is re-checked at `/oauth/authorize`, not only at
registration, so narrowing a vendor that appends a path segment would break
its already-registered clients mid-flow. The doc block says so, and says
env entries stay prefixes, as `OAUTH_ALLOWED_REDIRECT_PREFIXES` implies.

Tests: the descendant negative review asked for, plus `path_pin_modes`
covering both modes, that ChatGPT's stable callback is `Exact`, and the
invariant that a trailing-slash entry is never `Exact` (where it would
match only a path ending in `/`, pinning nothing).

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd7VT72Qt16qiAJynu9EKj
Copilot AI review requested due to automatic review settings September 3, 2026 12:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The callback is narrowly allow-listed, existing behavior is preserved, and positive and negative cases are tested.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@aterga
aterga requested a review from sea-snake September 3, 2026 12:19
@aterga
aterga merged commit 5a7ddb5 into main Sep 3, 2026
14 checks passed
aterga added a commit that referenced this pull request Sep 3, 2026
* Check in rustfmt.toml so `cargo fmt --all` matches the tree

CONTRIBUTING.md and the pull request template both ask for `cargo fmt
--all` before opening a PR, and the coding guidelines ask to "keep the
tree `rustfmt`-clean" — but no rustfmt config was checked in anywhere, and
the tree was not clean. On stable 1.94.1 the documented step rewrote 18
files (4473 insertions, 1202 deletions): rustfmt's stock `fn_call_width`
and `chain_width` of 60 split the calls and method chains this codebase
keeps on one line. Following the instructions therefore meant either
shipping a whole-repo reformat or hand-matching the surrounding style and
skipping the step, which is what happened while preparing #189.

No configuration reproduces the tree exactly, because the tree was never
rustfmt output. A coordinate-descent sweep over every stable width knob
(`max_width`, the six `use_small_heuristics` sub-widths, `fn_params_layout`,
`style_edition`) bottoms out around 5700 residual diff lines, and the
best-fitting combination is a curve fit to inconsistent hand formatting
rather than a style anyone chose. 403 checked-in lines exceed 100 columns,
among them breakable code such as `resolve_did` in `calls.rs` at 103 — a
signature rustfmt would never emit at `max_width = 100`.

So this checks in the two settings that are defensible on their own: the
100-column budget the code is visibly written to (the line-length
histogram falls off a cliff there), and the widened heuristics that keep
chains intact, which is the difference the report of this problem
identified. Being unable to recover a config does not leave the repo
stuck: one reviewed reformat ends drift that otherwise recurs for every
contributor.

The residual reformat those settings still want is applied here and
nothing else, so it is reviewable on its own — 25 files, 1661 insertions,
1482 deletions, against 4473/1202 with no config at all. Purely
whitespace and line breaks plus rustfmt's import ordering; `cargo build`,
`cargo test` (270 tests) and the 11 pre-existing clippy warnings are
unchanged. After it, `cargo fmt --all -- --check` is clean and idempotent
on a fresh clone.

If maintainers format with a toolchain or editor setting that is not in
the repo, that config should be preferred over this one — it can be
swapped in and the reformat redone against it.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FefdMpLRBQ7cLihuQsi3Mf

* Add a formatting check to CI

CI ran build, test, the PocketIC e2e suite and the internal-identifier
scan, but nothing checked formatting — so the rustfmt-clean tree
CONTRIBUTING.md asks for was a request with no enforcement behind it, and
it had already stopped being true. Checking in `rustfmt.toml` fixes the
tree once; this is what keeps it fixed, because without it the drift just
recurs and the next contributor to run the documented `cargo fmt --all`
inherits someone else's reformat.

A separate `fmt` job rather than a step in `test`: the two failures are
independent and each should stay readable when the other fires, and since
the job compiles nothing it runs in seconds in parallel, adding no
wall-clock. `--check` only reports, never rewrites, and the local
reproduction is the `cargo fmt --all` already documented.

No new third-party action: this reuses `actions/checkout` at the same
pinned SHA as the other jobs, and takes rustfmt from the runner's rustup
like they take cargo. The toolchain is rolling `stable`, matching the
sibling jobs, which does mean a stable release that changes rustfmt's
output can turn this red with no code change — the comment records that
the fix then is to re-run `cargo fmt --all`, not to pin.

Verified against this branch: the check passes on the formatted tree, and
fails as intended when deliberate drift is introduced.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FefdMpLRBQ7cLihuQsi3Mf

* Fix the article in the fmt job's comment

Review nit: "an rustfmt-clean tree" should be "a rustfmt-clean tree" —
`rustfmt` starts with a consonant sound, so "an" is wrong. Comment text
only; the job itself is unchanged.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FefdMpLRBQ7cLihuQsi3Mf

---------

Co-authored-by: Claude Opus 5 <[email protected]>
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