Issue Summary

I have a redash instance hosted on AWS. I am creating a new seperate client app which can display data by fetching queries using api/queries

however when I try to connect with the api using web Fetch call, I face CORS error with the message “Access to fetch at ‘https://my-server.com/api/queries?api_key=xxxx’ from origin ‘https://dev-enviroment:3000’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource”.

To solve this, i came across an env variable “REDASH_CORS_ACCESS_CONTROL_ALLOW_ORIGIN” whose value I tried setting to :

  1. “*”
  2. “dev-environment”

But no success yet.

  • I also tried setting a manual proxy using http-proxy-middleware package which solves the error in dev enviorment. but on production this doesnot work

Can you guide me on how I can solve this CORS error

Technical details:

  • Redash Version: v8
  • Browser/OS: chrome & firefox
  • How did you install Redash: docker

How did you test your changes to REDASH_CORS_ACCESS_CONTROL_ALLOW_ORIGIN`? Did you restart the instance?

hey @k4s1m , yes for every changes i made to REDASH_CORS_ACCESS_CONTROL_ALLOW_ORIGIN I had restarted the instance.

The issue here is the CORS support is only partially implemented in Redash v8. I’ve posted another topic requesting more details from the Redash development team.

@arikfr - could you please look into this ?

I have been trouble this issue for a couple of weeks, I got answer.

surely you know, CORS is matter of ALLOW_* headers .

so You can override nginx configuration, so that adding headers on every request,
here’s solution.

  1. connect you redash server
  2. redash container is on /opt/redash/
  3. make a nginx config file default.conf
  4. default.conf
upstream redash {
  server redash:5000;
}
server {
  listen   80 default;

  gzip on;
  gzip_types *;
  gzip_proxied any;
  # Wide-open CORS config for nginx
  location / {
    if ($request_method = 'OPTIONS') {
      add_header 'Access-Control-Allow-Origin' '*';
      # Om nom nom cookies
      # add_header 'Access-Control-Allow-Credentials' 'true';
      add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
      # Custom headers and headers various browsers *should* be OK with but aren't
      add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
      # Tell client that this pre-flight info is valid for 20 days
      add_header 'Access-Control-Max-Age' 1728000;
      add_header 'Content-Type' 'text/plain charset=UTF-8';
      add_header 'Content-Length' 0;
      return 204;
    }
    if ($request_method = 'POST') {
       add_header 'Access-Control-Allow-Origin' '*';
       # add_header 'Access-Control-Allow-Credentials' 'true';
       add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
       add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
    }
    if ($request_method = 'GET') {
       add_header 'Access-Control-Allow-Origin' '*';
       # add_header 'Access-Control-Allow-Credentials' 'true';
       add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
       add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
    }
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
    proxy_pass       http://redash;
  }
}
  1. backup your docker-compose.yml
  2. update configuration of nginx part of docker-compose.yml
  nginx:
    image: redash/nginx:latest
    ports:
      - "80:80"
    depends_on:
      - server
    volumes:
      - ./default.conf:/etc/nginx/conf.d/default.conf
    links:
      - server:redash
    restart: always
  1. as you see, add volumes attribute for override default.conf

  2. stop nginx service and start

sudo docker-compose stop nginx
sudo docker-compose start -d nginx

hope you feel better.

2 Likes