chproxy icon indicating copy to clipboard operation
chproxy copied to clipboard

allow_cors may break CORS

Open nezed opened this issue 5 years ago • 3 comments

users[].allow_cors = true may lead to multiple Access-Control-Allow-Origin headers

Actual behaviour:

Responses with multiple headers is rejected by Chrome browser with following error:

The 'Access-Control-Allow-Origin' header contains multiple values 'http://ui.tabix.io, *', but only one is allowed.

Steps to reproduce:

  1. add_http_cors_header = 1 is default behaviour for tabix.io and grafana-clickhouse plugin, also it may be set as default for some users.
  2. In this case clickhouse-server responses includes Access-Control-Allow-Origin: * header.
  3. Setting chproxy option users[].allow_cors = true leads to injecting second Access-Control-Allow-Origin: origin header.
  4. Response that contains two CROS headers and is rejected by Chrome
    Access-Control-Allow-Origin: *                     # by clickhouse-server
    Access-Control-Allow-Origin: http://ui.tabix.io    # by chproxy
    

Expected behaviour

One of this

  1. don't add Allow-Origin header is response already has one
    • if users[].allow_cors = true then drop all Allow-Origin headers in source response if any and write single Allow-Origin header in same manner as chproxy does now
    • if users[].allow_cors = false then do nothing (user may expect that add_http_cors_header will take effect and experience troubles if chproxy changes this behaviour)

For me option 2 looks way better, at least because it respects real Origin header value from client

nezed avatar Jun 16 '20 19:06 nezed

Thanks for so detailed report @nezed!

hagen1778 avatar Jun 22 '20 17:06 hagen1778

any updates on this?

bobelev avatar Nov 16 '20 21:11 bobelev

@hagen1778 any updates on this?

seifchen avatar Apr 28 '21 02:04 seifchen