CORS Error

Hi, i have been use a webhook for a post request. But the app (UI Bakery made) gives me these error:

0 Unknown Error. This could be a CORS issue - try configuring your server to allow requests enable cross-origin resource sharing

Access Control Allow Header is set.

What can it be ?

Thanks,
Stefan

Hey @Stefan,

When others have run into this in the past, the solution was to run everything behind a proxy, which, in my opinion, is the right way to do this anyway. You are simply asking for trouble if you are running n8n “naked” on the internet.

Ok ? I use your Docker Version, this runs behind a proxy ? Right ?

If you run n8n with docker then there will just be n8n and no proxy.

If you use run n8n as described in our Server Setup Guide then there will be a proxy in front of it. In this case traefik.

About your CORS issue. Did you try to make a request with curl to see if the Access Control Allow Header gets returned correctly? What value did you set?

Here an earlier discussion about CORS:

Jan, when you use the Docker Version. You need this parameter in Docker Compose

traefik.frontend.headers.customResponseHeaders=Access-Control-Allow-Origin:*

Then it works !

Thanks,
Stefan

1 Like

Interesting. But it should also work if you set it as a response header an the Webhook-Node. At least in our setup it is working fine. Can not imagine that traefik would remove that.

I had to add a few more labels to my docker:

      - traefik.http.middlewares.cors.headers.customResponseHeaders.Access-Control-Allow-Origin=*
      - traefik.http.middlewares.cors.headers.customResponseHeaders.Access-Control-Allow-Methods=GET, POST, OPTIONS
      - traefik.http.middlewares.cors.headers.customResponseHeaders.Access-Control-Allow-Headers=DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization
      - traefik.http.routers.n8n.middlewares=cors@docker
6 Likes

Thank you for this, it made my problems with CORS go away immediately as well!

A question regarding security though since I feel I need to learn, what exactly does it mean to remove f.e. the Access-Control-Allow-Origin from the proxy? Doesn’t this remove the whole purpose with a proxy? On the other hand, if you can’t even access your own n8n backend it’s really not useful anyway so… I don’t really know what to think of this?

Thanks again

@JulioC_me Man, you made my day. For the whole day I tried to solve that. And only your advice helped

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.