Hi everyone,
I’m posting this here to help other community members who might run into the same issue: After updating to n8n v1.87.x (v1.88.0 in my case), I constantly experienced the ‘Connection lost’ error in the UI, accompanied by ResponseError: Invalid origin!
in the n8n container’s Docker logs.
My Setup:
- Self-hosted n8n via Docker (using multiple workers in queue mode)
- External access via a Cloudflare Tunnel (Cloudflared)
Problem Description: The UI constantly lost connection to the backend, severely impacting usability. The error started occurring after n8n v1.87 introduced stricter security checks for push endpoints (SSE/WebSockets) (see PR #14365).
Attempted Solutions (Without Success): I checked the usual configurations for running behind a reverse proxy and made sure they were correct:
N8N_HOST=n8n.example.com
(hostname only)N8N_PROTOCOL=https
WEBHOOK_URL=https://n8n.example.com
N8N_TRUST_PROXY='172.16.0.0/12, 192.168.0.0/16, 10.0.0.0/8'
(Example covering common private/Docker ranges; more specific ranges might be needed depending on your setup)- Ensured the ‘HTTP Host Header’ override field in the Cloudflare Tunnel settings was empty.
Despite these correct settings, the Invalid origin!
error persisted.
Diagnosis (The Cause): The crucial clue came from the Cloudflare Tunnel’s Live Logs. For requests to the /rest/push
endpoint, the logs showed that the Origin
header was being sent to n8n without the scheme:
JSON"Origin": [ "n8n.example.com" ]
However, based on the configuration (N8N_PROTOCOL
+ N8N_HOST
), n8n expects the value https://n8n.example.com
. Since the values didn’t match exactly, the security check failed.
The Solution: The solution was to instruct Cloudflare to explicitly set the Origin
header to the correct value before the request reaches your tunnel and thus n8n. This was achieved using a Cloudflare Transform Rule:
- In the Cloudflare Dashboard, navigate to your domain → Rules → Transform Rules.
- Create a “Modify Request Header” rule.
- Filter:
Hostname equals n8n.example.com
- Modification:
Set static
HeaderOrigin
tohttps://n8n.example.com
- Deploy the rule.
After this rule was active, the Origin
header was correctly transmitted to n8n, and the Invalid origin!
error, along with the ‘Connection lost’ message, disappeared immediately.
I hope this helps others who encounter a similar issue when running n8n behind a Cloudflare Tunnel!
Best regards
Florian
TL;DR: If you get the ‘Invalid origin!’ error after updating to n8n >= 1.87.0 while using a Cloudflare Tunnel: Create a Cloudflare Transform Rule (Modify Request Header) for your n8n hostname that statically sets the Origin
header to your full HTTPS URL (e.g., https://n8n.example.com
).