Skip to content
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

Implement Content Security Policy #2873

Closed
sandstrom opened this issue Feb 4, 2015 · 6 comments · Fixed by #29545
Closed

Implement Content Security Policy #2873

sandstrom opened this issue Feb 4, 2015 · 6 comments · Fixed by #29545
Labels
enhancement New value added to drive a business result Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more!

Comments

@sandstrom
Copy link

Kibana is an excellent tool for log data (via Logstash). Log data is raw (it should be), but this also increases the vulnerability to XSS. Perhaps it would be a good idea to harden Kibana with CSP.

https://developer.mozilla.org/en-US/docs/Web/Security/CSP
http://www.html5rocks.com/en/tutorials/security/content-security-policy/

@rashidkpc rashidkpc added this to the 4.1.0 milestone Feb 4, 2015
@rashidkpc rashidkpc added v4.1.0 and removed v4.1.0 labels Mar 2, 2015
@rashidkpc rashidkpc removed this from the 4.1.0 milestone Mar 2, 2015
@rashidkpc rashidkpc added v4.2.0 and removed v4.1.0 labels Apr 8, 2015
@rashidkpc rashidkpc assigned panda01 and unassigned simianhacker Jun 10, 2015
@rashidkpc rashidkpc removed the v4.2.0 label Jul 15, 2015
@tbragin tbragin added the Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc label Feb 16, 2017
@epixa epixa removed the good first issue low hanging fruit label Jan 8, 2018
@epixa
Copy link
Contributor

epixa commented Jan 9, 2018

I think we should target this for CSP (on newlines for readability):

default-src 'self'         // also covers script-src and connect-src in addition to others
connect-src <configurable> // see below
object-src 'none'
base-uri 'self'            // this could be 'none' since we don't use it, but we've said we want to use it
form-action 'none'         // blocked on server by csrf anyway
sandbox allow-scripts      // allows js, but not eval and not inline

connect-src locks down requests such as xhr to a specific set of hosts, but it is very common for people to want to make certain requests across domains, so this really needs to be something can be configured at least by plugins if not through kibana.yml. Out of the box, we should use self though.

I think the only inline script we use right now is the bootstrapping code in the initial payload, but #15904 should remove that need.

Unfortunately, I think we'll unsafe-eval on sandbox for the time being because angular does some controlled eval stuff in its rendering/digest code. We should verify the extent of this and then aggressively get rid of all usage of it though so we can remove this as soon as possible.

@thomasneirynck
Copy link
Contributor

thomasneirynck commented Jan 9, 2018

I think we should keep unsafe-eval. Disallowing it prevents us to use other libraries as well. An example is Vega. The library ensures input expressions are parsed safely, but uses eval to generate executable javascript.

A blanket block of eval is a course method to ensure security. Rather, I would like us to evaluate the impact of script-injection attacks on a library-2-library basis, instead of enforcing it by a CSP, particularly as it pertains to unsafe-eval.

@sandstrom
Copy link
Author

sandstrom commented Jan 9, 2018

Ideally the CSP lockdown should be as tight as possible.

One alternative (in case a tight lockdown is impossible) is to use the newer strict-dynamic keyword. It basically establishes a 'chain of trust', where blessed script tags (via nonce or hash), and any subsequent scripts these scripts may load, are allowed to execute. With strict-dynamic the 'unsafeness' of unsafe-eval is much less of a problem.

More details:
https://csp.withgoogle.com/docs/strict-csp.html

@nyurik
Copy link
Contributor

nyurik commented Jan 11, 2018

I did a sample code with a very restrictive CSP rule set for the main window, and a much more relaxed (anything goes) rules for the iframe content in this test: https://github.com/nyurik/csp-vega-test . Note that the <iframe srcdoc="..."> attribute would not work because in that case CSP rules are still applied to iframe's content. It only works with the src="...". Kibana server should provide a sandbox-oriented downloads (e.g. just the Vega libraries bundle and some simple HTML for the iframe content). Who would be the best person to talk to about changes to Kibana core for this?

@epixa epixa added Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! and removed Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc labels Jan 29, 2018
@epixa epixa added enhancement New value added to drive a business result and removed release_note:enhancement labels Dec 11, 2018
@epixa
Copy link
Contributor

epixa commented Feb 4, 2019

Our initial CSP implementation was merged in #29545, so I'm going to close this, and we can track any future changes to this policy as discrete issues.

@epixa epixa closed this as completed Feb 4, 2019
@nyurik
Copy link
Contributor

nyurik commented Jul 1, 2020

Just FYI -- Vega 5.13.0 adds a slower CSP-compliant interpreter version in case we ever get to the point of a full CSP lock down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New value added to drive a business result Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants