|
4 | 4 | "fmt"
|
5 | 5 | "net/http"
|
6 | 6 | "strings"
|
| 7 | + |
| 8 | + "github.com/coder/coder/v2/codersdk" |
7 | 9 | )
|
8 | 10 |
|
9 | 11 | // cspDirectives is a map of all csp fetch directives to their values.
|
@@ -55,7 +57,7 @@ const (
|
55 | 57 | // Example: https://github.com/coder/coder/issues/15118
|
56 | 58 | //
|
57 | 59 | //nolint:revive
|
58 |
| -func CSPHeaders(telemetry bool, websocketHosts func() []string, staticAdditions map[CSPFetchDirective][]string) func(next http.Handler) http.Handler { |
| 60 | +func CSPHeaders(experiments codersdk.Experiments, telemetry bool, websocketHosts func() []string, staticAdditions map[CSPFetchDirective][]string) func(next http.Handler) http.Handler { |
59 | 61 | return func(next http.Handler) http.Handler {
|
60 | 62 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
61 | 63 | // Content-Security-Policy disables loading certain content types and can prevent XSS injections.
|
@@ -88,13 +90,20 @@ func CSPHeaders(telemetry bool, websocketHosts func() []string, staticAdditions
|
88 | 90 | CSPDirectiveMediaSrc: {"'self'"},
|
89 | 91 | // Report all violations back to the server to log
|
90 | 92 | CSPDirectiveReportURI: {"/api/v2/csp/reports"},
|
91 |
| - CSPFrameAncestors: {"'self'"}, |
92 | 93 |
|
93 | 94 | // Only scripts can manipulate the dom. This prevents someone from
|
94 | 95 | // naming themselves something like '<svg onload="alert(/cross-site-scripting/)" />'.
|
95 | 96 | // "require-trusted-types-for" : []string{"'script'"},
|
96 | 97 | }
|
97 | 98 |
|
| 99 | + if experiments.Enabled(codersdk.ExperimentAITasks) { |
| 100 | + // AI tasks use iframe embeds of local apps. |
| 101 | + // TODO: Handle region domains too, not just path based apps |
| 102 | + cspSrcs.Append(CSPFrameAncestors, `'self'`) |
| 103 | + } else { |
| 104 | + cspSrcs.Append(CSPFrameAncestors, `'none'`) |
| 105 | + } |
| 106 | + |
98 | 107 | if telemetry {
|
99 | 108 | // If telemetry is enabled, we report to coder.com.
|
100 | 109 | cspSrcs.Append(CSPDirectiveConnectSrc, "https://coder.com")
|
|
0 commit comments