Description
In its default configuration Fider uses overly broad Content-Security-Policy (CSP) and Cross-Origin-Resource-Sharing (CORS) configurations.
CSP header
I noticed the following exceptions in the Content-Security-Policy header, namely:
https://fonts.googleapis.com
https://*.paddle.com
https://fonts.gstatic.com
The file engine.go
specifies the affected CSP directives:
var (
cspBase = "base-uri 'self'"
cspDefault = "default-src 'self'"
cspStyle = "style-src 'self' 'unsafe-inline' https://fonts.googleapis.com https://*.paddle.com %[2]s"
cspScript = "script-src 'self' 'nonce-%[1]s' https://www.google-analytics.com https://*.paddle.com %[2]s"
cspFont = "font-src 'self' https://fonts.gstatic.com data: %[2]s"
cspImage = "img-src 'self' https: data: %[2]s"
cspObject = "object-src 'none'"
cspFrame = "frame-src 'self' https://*.paddle.com"
cspMedia = "media-src 'none'"
cspConnect = "connect-src 'self' https://www.google-analytics.com %[2]s"
//CspPolicyTemplate is the template used to generate the policy
CspPolicyTemplate = fmt.Sprintf("%s; %s; %s; %s; %s; %s; %s; %s; %s; %s", cspBase, cspDefault, cspStyle, cspScript, cspImage, cspFont, cspObject, cspMedia, cspConnect, cspFrame)
)
In a basic setup without external integrations such as Google Analytics and Paddle I do not see any use in allowing those domains.
Additionally, the Google Fonts do not seem to be necessary, as I prohibit cross-origin requests via CORS on my instance of Fider completely and I have no font issues.
I would recommend setting those directives only when the administrator enables the respective features.
This probably also renders the dependency of fetching Google Fonts obsolete:
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
Reference:
CORS header
The file cors.go
defines the Access-Control-Allow-Origin
to allow all cross-origins (*
). This allows any domain to perform cross-site requests and read the respective reponses.
Line 11 in a357ddd
To set this securely, the environment variable BASE_URL
could provide the value.
Reference: