Discourse_docker (blocked:csp) error with svg-sprite when using subfolders

We do have all the logic in place for SVG sprites in subfolder scenarios, and it’s used successfully by a number of sites. In this case, we’ve hit a very specific edge case. Checking the key variables in @vkozyrev’s site (on the browser console)

> Discourse.SvgSpritePath
"/svg-sprite/sales-community-staging.rainmakers.co/svg-2-8ed106e6e3d908b1b86898dfe93a7bac0fd358f4.js"
> Discourse.BaseUri
"/sales-community"

Looks good. Now, when we load the SVG sprite sheet, we use loadScript, which in turn calls Discourse.getURL. This function is responsible for adding the subfolder prefix. Trying that out:

> Discourse.getURL(Discourse.SvgSpritePath)
"/svg-sprite/sales-community-staging.rainmakers.co/svg-2-8ed106e6e3d908b1b86898dfe93a7bac0fd358f4.js"

Huh… that didn’t do anything. Another random URL works fine:

> Discourse.getURL("/blah")
"/sales-community/blah"

A little more digging turns up this line inside getUrl

if (url.indexOf(Discourse.BaseUri) !== -1) return url;

Or, in english, “if the URL already contains the subfolder prefix, give up”. So the issue here is that @vkozyrev’s subfolder prefix (/sales-community) is included in the middle of the SVG sprite sheet URL

/svg-sprite/sales-community-staging.rainmakers.co/svg-2-8ed106e6e3d908b1b86898dfe93a7bac0fd358f4.js

I’ve made the check more specific, so it only checks for the subfolder prefix at the beginning of the URL:

https://github.com/discourse/discourse/pull/8794

Although it does make me think of other potential issues… e.g. if someone wanted their subfolder prefix to be /t or /about, or any other URL which we use in Discourse :thinking:

10 Likes