-
Notifications
You must be signed in to change notification settings - Fork 666
CONSOLE-4263: Add initial Content Security Policy for Console web application #14156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -673,6 +673,27 @@ func (s *Server) indexHandler(w http.ResponseWriter, r *http.Request) { | |
| return | ||
| } | ||
|
|
||
| // This Content Security Policy (CSP) applies to Console web application resources. | ||
| // Console CSP is deployed in report-only mode via "Content-Security-Policy-Report-Only" header. | ||
| // See https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP for details on CSP specification. | ||
| cspSources := "'self'" | ||
| if s.K8sMode == "off-cluster" { | ||
| // Console local development involves a webpack server running on port 8080 | ||
| cspSources = cspSources + " http://localhost:8080 ws://localhost:8080" | ||
| } | ||
|
||
| cspDirectives := []string{ | ||
| fmt.Sprintf("default-src %s", cspSources), | ||
| fmt.Sprintf("base-uri %s", cspSources), | ||
| fmt.Sprintf("img-src %s data:", cspSources), | ||
| fmt.Sprintf("font-src %s data:", cspSources), | ||
|
Comment on lines
+687
to
+688
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry, what does an empty
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This allows the web application to use In this case, we allow using Using
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, this should be a valid value 👍 |
||
| fmt.Sprintf("script-src %s 'unsafe-eval'", cspSources), | ||
| fmt.Sprintf("style-src %s 'unsafe-inline'", cspSources), | ||
| "frame-src 'none'", | ||
| "frame-ancestors 'none'", | ||
| "object-src 'none'", | ||
| } | ||
|
||
| w.Header().Set("Content-Security-Policy-Report-Only", strings.Join(cspDirectives, "; ")) | ||
|
|
||
| plugins := make([]string, 0, len(s.EnabledConsolePlugins)) | ||
| for plugin := range s.EnabledConsolePlugins { | ||
| plugins = append(plugins, plugin) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when dynamic plugin triggers CSP violation, we can only see warning message
Content Security Policy violation detectedContent Security Policy violation seems to originate from plugin ${pluginName}doesn't printThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yapei @jhadvig
When detecting whether the CSP violation originates from a dynamic plugin or from Console application code itself, we look at
blockedURIandsourceFileproperties - if their values start with{consoleBaseURL}/api/plugins/prefix, it means that the associated resource is fetched via Console Bridge server's plugin asset endpoint which allows us to infer the name of the dynamic plugin.This is why the message is phrased "seems to originate from plugin" instead of just "originates from plugin". Any CSP violations which are due to
{consoleBaseURL}/api/plugins/...requests are associated with dynamic plugins, but any dynamic plugin can also make requests to other (non-Console) endpoints.If a plugin makes requests to non-Console endpoints (regardless of whether the requested service is inside or outside the cluster) it will trigger CSP violations which we have no way of associating with that dynamic plugin. These kind of CSP violations will be logged, but the "seems to originate from plugin" will not apply to them.
Each dynamic plugin team should test their own plugin on a cluster and ensure there are no CSP violations that may be traced back to their plugin.
In case a plugin really needs to make requests to non-Console endpoints then it should explicitly list such endpoints via
ConsolePlugincustom resource (CONSOLE-4265).