mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
fix(coderd): omit frame-ancestors CSP for embed routes (#24529)
This commit is contained in:
+8
-4
@@ -2037,16 +2037,20 @@ func New(options *Options) *API {
|
||||
cspMW := httpmw.CSPHeaders(options.Telemetry.Enabled(), cspProxyHosts, additionalCSPHeaders)
|
||||
|
||||
// Embed routes (e.g. VS Code extension chat) are designed to be
|
||||
// loaded inside iframes, so they need a relaxed frame-ancestors
|
||||
// policy instead of the default 'self'. However, if the operator
|
||||
// explicitly configured frame-ancestors via CODER_ADDITIONAL_CSP_POLICY,
|
||||
// loaded inside iframes, so they must not include frame-ancestors
|
||||
// in their CSP. The CSP wildcard '*' only matches network schemes
|
||||
// (http, https, ws, wss) and cannot cover custom schemes like
|
||||
// vscode-webview://, so the only way to allow all embedders is
|
||||
// to omit the directive entirely. If the operator explicitly
|
||||
// configured frame-ancestors via CODER_ADDITIONAL_CSP_POLICY,
|
||||
// respect that setting.
|
||||
|
||||
embedCSPHeaders := make(map[httpmw.CSPFetchDirective][]string, len(additionalCSPHeaders))
|
||||
for k, v := range additionalCSPHeaders {
|
||||
embedCSPHeaders[k] = v
|
||||
}
|
||||
if _, ok := additionalCSPHeaders[httpmw.CSPFrameAncestors]; !ok {
|
||||
embedCSPHeaders[httpmw.CSPFrameAncestors] = []string{"*"}
|
||||
embedCSPHeaders[httpmw.CSPFrameAncestors] = []string{}
|
||||
}
|
||||
embedCSPMW := httpmw.CSPHeaders(options.Telemetry.Enabled(), cspProxyHosts, embedCSPHeaders)
|
||||
embedHandler := embedCSPMW(compressHandler(httpmw.HSTS(api.SiteHandler, options.StrictTransportSecurityCfg)))
|
||||
|
||||
Reference in New Issue
Block a user