Issue with Relative Path Causing CORS Error on Discourse Sites

Are you using a CDN on either of these sites? I have noticed that code highlighting is no longer working on my site, and I think it’s because of this:

In my case, my CDN is not returning an Access-Control-Allow-Origin header for the highlightjs file. I notice that Meta’s CDN does include that header, so I wonder what is different.

$ curl --silent -I https://d3bpeqsaub0i6y.cloudfront.net/highlight-js/meta.discourse.org/9797975efac87d28baa695ae13ca72ccaf5120f5.js | grep -i access-control
access-control-allow-origin: *
access-control-allow-methods: GET, HEAD, OPTIONS

However, those headers are not being served by the origin server:

$ curl --silent -I https://meta.discourse.org/highlight-js/meta.discourse.org/9797975efac87d28baa695ae13ca72ccaf5120f5.js | grep -i access-control
<no output>

As far as I can tell, Discourse is meant to add access-control headers to the highlightjs files:

However, those headers are only applied if the request is a “CDN request”:

This only works if Discourse is configured with a separate host name for “CDN requests”.

1 Like