anythingmcp icon indicating copy to clipboard operation
anythingmcp copied to clipboard

OAuth popup flow fails with Microsoft 365 Copilot: helmet sends COOP same-origin on /auth/login and /callback

Open AXILTIADIGITAL opened this issue 1 week ago • 6 comments

Description

When connecting a self-hosted AnythingMCP server as a custom MCP connector in Microsoft 365 Copilot (authentication: DCR / OAuth 2.0), the login popup completes, but the connection never finishes. The popup loses its link to the Copilot window (window.opener is null).

Cause: packages/backend/src/main.ts calls helmet() (v8) without a crossOriginOpenerPolicy option, so helmet's default Cross-Origin-Opener-Policy: same-origin is sent on every response, including POST /auth/login (302 → /callback) and GET /callback (302 → Microsoft redirect with a valid code=). Microsoft requires COOP to be unsafe-none (or absent) on every page of the OAuth redirect chain, otherwise window.opener is lost.

Everything else works: DCR, the redirect URI and code issuance are fine.

Suggested fix: set crossOriginOpenerPolicy: { policy: 'unsafe-none' } for the OAuth routes (/auth/*, /callback, /authorize), or make COOP configurable (e.g. via an environment variable). Neither the dashboard nor an env var can change it today.

Workaround: overriding the header in the reverse proxy (Traefik headers middleware with customResponseHeaders on these paths) makes the flow work.

Steps to Reproduce

  1. Self-host AnythingMCP (Docker, behind Traefik/Coolify) with MCP_AUTH_MODE=both.
  2. In Microsoft 365 Copilot, add a custom MCP connector pointing at https://<host>/mcp, authentication DCR / OAuth 2.0.
  3. In the popup, sign in to AnythingMCP and approve.
  4. The popup is redirected to https://teams.microsoft.com/api/platform/v1.0/oAuthRedirect?code=….

Expected Behavior

The popup hands the code back to the Copilot window and the connector is connected.

Actual Behavior

Microsoft shows "Connection Didn't Complete – Your sign-in may have succeeded, but we couldn't finish the connection." window.opener is null on that page. A HAR capture shows Cross-Origin-Opener-Policy: same-origin on POST /auth/login and GET /callback.

Connector Type

No response

Deployment Method

Docker Compose

Version

v0.55.11

Relevant Logs

$ curl -sI https://<host>/auth/login | grep -i cross-origin-opener
cross-origin-opener-policy: same-origin

Environment

  • Ubuntu 24.04, Coolify 4.x, Traefik v3.7
  • Image helpcodeai/anythingmcp:latest (v0.55.11)
  • Client: Microsoft 365 Copilot (custom MCP connector)

AXILTIADIGITAL avatar Nov 26 '26 10:11 AXILTIADIGITAL

👋 Hi @AXILTIADIGITAL, thanks for opening your first issue on AnythingMCP!

A maintainer will triage this within ~48h. To help us help you faster:

  • For "how do I…" questions, Discussions / Q&A usually gets faster answers.
  • For feature requests, vote on Which integrations should we build next? so we can prioritise based on demand.
  • Bug? Please confirm the version and deployment mode (Docker / Railway / DO / Cloud) if you haven't already.

⭐ If AnythingMCP has been useful to you, a star helps others find it.

github-actions[bot] avatar Nov 26 '26 11:11 github-actions[bot]

Bildschirmfoto 2026-11-26 um 17 10 47

FYI Check your link

Target LINK = 404 Page ;-)

AXILTIADIGITAL avatar Nov 26 '26 16:11 AXILTIADIGITAL

Confirmed on current main: Helmet sets COOP globally, and I found no OAuth route override. After #985, I can take a narrowly scoped fix for the popup routes, with a browser regression that checks window.opener across two origins and verifies the dashboard header stays unchanged. Does that scope work?

Coding-Professional avatar Nov 27 '26 17:11 Coding-Professional

I opened #1919 for the broken link in the welcome message.

Coding-Professional avatar Nov 27 '26 19:11 Coding-Professional

Yes, that scope works, thanks for confirming. Please make sure /auth/*, /callback and /authorize are all covered, since Microsoft 365 Copilot checks window.opener across the whole redirect chain. Keeping same-origin on the dashboard is fine with me.

No rush on my side: I'm running a Traefik header override on those paths as a workaround in the meantime. Once your fix ships, I'll remove it and test again with M365 Copilot.

AXILTIADIGITAL avatar Nov 27 '26 19:11 AXILTIADIGITAL

Thanks @AXILTIADIGITAL for the clear report and the workaround, and thanks @Coding-Professional for confirming it.

Yes, that scope works for us. Please cover /auth/*, /callback and /authorize, and keep the dashboard on same-origin. The Cloud Caddy does not set COOP, so the backend header is the only one to change there. A note in the self-hosting docs for people who override headers in their own proxy would help too.

#1918 is going in today, so this can be next.

helpcodeai avatar Nov 28 '26 08:11 helpcodeai