mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-06-19 13:21:46 +00:00
v3.0.16 — bug fixes (#964)
* fix(mcp): MCP RFC compliant for more strict clients * fix(mcp): serve flat /.well-known/oauth-protected-resource for ChatGPT reconnect Clients such as ChatGPT probe the flat well-known URL on every fresh discovery cycle (i.e. after a full disconnect/reconnect where cached OAuth state is cleared). The SDK's mcpAuthMetadataRouter only serves the path-based form /.well-known/oauth-protected-resource/mcp, so the flat probe returned 404. Without the resource metadata, ChatGPT fell back to the issuer URL as the resource parameter (https://…/ instead of https://…/mcp). The authorize handler then rejected it with invalid_target and redirected back to ChatGPT's callback with an error — showing the user the TREK home page instead of the consent form. Add an explicit GET handler for the flat URL that returns the same protected resource metadata, so the resource URI is discovered correctly on the first probe. * fix(mcp): fix OAuth popup blank page — SW denylist and COOP header Service worker was intercepting /oauth/authorize navigate requests (not in denylist), serving index.html, and React Router's catch-all redirected to / instead of the SDK authorize handler. Helmet's default COOP: same-origin isolated the /oauth/consent popup from its cross-origin opener, making window.opener null and breaking the popup-based OAuth completion signal for ChatGPT and similar clients. * fix(ntfy): encode non-Latin-1 header values with RFC 2047 to prevent ByteString crash Todo/trip names containing chars like → or € (and non-Latin-1 locale templates for Czech, Chinese, Russian, etc.) caused the Fetch API to throw when setting the ntfy Title header. Apply RFC 2047 base64 encoded-word encoding for any header value containing chars above U+00FF; ntfy decodes this automatically. * docs(mcp): document Cloudflare bot detection blocking ChatGPT MCP requests Add Cloudflare WAF note to MCP-Setup and a full troubleshooting entry covering root cause (IP reputation + UA heuristics), free-plan limitation (disable Bot Fight Mode entirely, with explicit warning), and paid-plan WAF skip rule with the full expression syntax and path table for all MCP/OAuth/.well-known routes. * fix(pwa): detect upstream proxy auth challenges and recover gracefully Behind Cloudflare Zero Trust or Pangolin, cross-origin auth redirects on /api/* calls surface as CORS errors (error.response === undefined) that the existing 401 interceptor never catches, leaving the PWA stuck with network-error toasts instead of re-authenticating. New connectivity module probes /api/health every 30s using fetch with cache:no-store and inspects Content-Type to reliably detect whether the server is reachable vs intercepted by an upstream proxy. axios interceptor changes: - On !error.response + navigator.onLine: run probeNow(); if the health probe also fails (proxy is intercepting all requests), trigger a guarded window.location.reload() so the edge proxy can intercept the top-level navigation and run its auth flow (covers CF Access and Pangolin 302 mode) - On error.response status 401 with text/html body: same reload path, covering Pangolin header-auth extended compatibility mode which returns 401+HTML instead of a 302 redirect. TREK own 401s are always JSON so there is no collision with the existing AUTH_REQUIRED branch. - sessionStorage flag prevents reload loops; cleared on any successful response so the guard resets after re-auth. /api/health excluded from SW NetworkFirst cache (vite.config.js regex) and Cache-Control: no-store added server-side so probes always hit the network and cannot be served stale from the 24h api-data cache. LoginPage caches last-known appConfig in localStorage so the SSO button renders in OIDC+UN/PW dual mode even when the config fetch is intercepted by the proxy. Auto-redirect to IdP skipped when config comes from cache to avoid redirect loops while the proxy is challenging. Fixes discussion #836. * fix(files): add bottom-nav padding to files tab wrapper on mobile * fix(budget): expose toolbar on mobile so users can add budget categories * fix(pwa): unregister SW before proxy-reauth reload so Pangolin can challenge WorkBox's NavigationRoute served the cached SPA shell on window.location.reload(), meaning Pangolin/CF Access never saw the navigation and the app was left stuck showing stale offline data. Unregistering the SW first lets the navigation reach the network so the upstream proxy can run its auth flow. Also rebuilds server/public with corrected sw.js (health excluded from NetworkFirst, /oauth/ and /.well-known/ added to NavigationRoute denylist). * chore: remove committed build artifacts from server/public Dockerfile and Proxmox community script both rebuild client/dist and copy it into server/public at build time — committed artifacts were never used. Replace with .gitkeep and add server/public/* to .gitignore. * chore: add build-from-sources script
This commit is contained in:
@@ -6,6 +6,8 @@ This page explains how to connect an AI assistant to your TREK instance. TREK su
|
||||
|
||||

|
||||
|
||||
> **Cloudflare users:** If your TREK instance is proxied through Cloudflare, Bot Fight Mode and Super Bot Fight Mode will block MCP requests from ChatGPT. Claude.ai is not affected. See [Troubleshooting → MCP requests blocked by Cloudflare WAF](#mcp-requests-blocked-by-cloudflare-waf-bot-fight-mode) for the fix.
|
||||
|
||||
## Option A: OAuth 2.1 (recommended)
|
||||
|
||||
OAuth 2.1 is the preferred connection method. You grant specific scopes during the consent step and no token management is required afterward — TREK issues short-lived access tokens and automatically rotates refresh tokens.
|
||||
|
||||
@@ -251,3 +251,55 @@ environment:
|
||||
- MCP_RATE_LIMIT=600 # requests per minute per user (default: 300)
|
||||
- MCP_MAX_SESSION_PER_USER=50 # concurrent sessions per user (default: 20)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## MCP requests blocked by Cloudflare WAF (Bot Fight Mode)
|
||||
|
||||
**Cause:** When TREK is proxied through Cloudflare, **Bot Fight Mode** and **Super Bot Fight Mode** classify requests from ChatGPT as bots and block them at the WAF level — before the request ever reaches TREK. This is specific to ChatGPT; Claude.ai is not affected. ChatGPT's exit node IPs have low reputation scores in Cloudflare's threat intelligence and the User-Agent matches Cloudflare's automated-traffic heuristics. TREK itself never receives the request, so there is nothing in TREK's logs; the block is silent from TREK's perspective.
|
||||
|
||||
Symptoms:
|
||||
- ChatGPT shows a connection error or times out immediately after OAuth completes.
|
||||
- Cloudflare's Security → Events log shows blocked requests to `/mcp` with action `block` and source `bfm` (Bot Fight Mode) or `managed_rule`.
|
||||
|
||||
**Fix — Option 1: Disable Bot Fight Mode (free plan and paid plan)**
|
||||
|
||||
In the Cloudflare dashboard for your zone: **Security → Bots → Bot Fight Mode → Off** (or Super Bot Fight Mode → Off).
|
||||
|
||||
This is the only option available on the **free plan**. It disables bot blocking for the entire zone — all probe bots, scrapers, and crawlers that Cloudflare would otherwise block will reach your server. Only use this if you have no alternative.
|
||||
|
||||
**Fix — Option 2: WAF skip rule for MCP paths (paid plan only)**
|
||||
|
||||
> WAF custom rules require a **paid Cloudflare plan** (Pro or above). This option is not available on the free plan.
|
||||
|
||||
Create a WAF skip rule that bypasses bot management only for the MCP and OAuth paths, leaving protection in place for the rest of the site:
|
||||
|
||||
1. Go to **Security → WAF → Custom rules** and click **Create rule**.
|
||||
2. Enter the following expression (replace `trek.example.com` with your domain):
|
||||
|
||||
```
|
||||
(http.host eq "trek.example.com") and (
|
||||
http.request.uri.path eq "/mcp" or
|
||||
http.request.uri.path starts_with "/oauth/" or
|
||||
http.request.uri.path starts_with "/.well-known/"
|
||||
)
|
||||
```
|
||||
|
||||
This covers all paths that ChatGPT's servers hit during discovery, OAuth, and MCP calls:
|
||||
|
||||
| Path | Purpose |
|
||||
|---|---|
|
||||
| `/mcp` | MCP endpoint (GET, POST, DELETE) |
|
||||
| `/oauth/authorize` | OAuth authorization handler |
|
||||
| `/oauth/register` | Dynamic client registration |
|
||||
| `/oauth/token` | Token issuance |
|
||||
| `/oauth/userinfo` | User info (for domain claiming) |
|
||||
| `/oauth/revoke` | Token revocation |
|
||||
| `/.well-known/oauth-authorization-server` | RFC 8414 AS metadata |
|
||||
| `/.well-known/oauth-protected-resource` | RFC 9728 flat resource metadata |
|
||||
| `/.well-known/openid-configuration` | OIDC discovery |
|
||||
|
||||
3. Set the action to **Skip** and check **Bot Fight Mode** (and/or **Super Bot Fight Mode**) under the skip options.
|
||||
4. Save and deploy.
|
||||
|
||||
This allows MCP and OAuth traffic through while keeping Cloudflare bot protection active for all other paths.
|
||||
|
||||
Reference in New Issue
Block a user