Skip to content

Content Security Policy

Stef Walter edited this page Nov 30, 2016 · 4 revisions

Content Security Policy is a way of telling the browser to be more strict on where it can load javascript or CSS from and where it can connect to. It mitigates whole swaths of possible security issues. Given perfect code, Content Security Policy wouldn't be necessary. But we all know about perfect code.

Cockpit runs as a real user login session. That means once you're logged in the javascript running in the web browser has access to your system just like you do. This is similar to running an application on a Linux desktop, or tools in a logged in terminal shell.

What we need to ensure is that only the code Cockpit explicitly loaded is executed, and no other code (eg: included by way of an XSS attack) gets run. Content Security Policy helps us enforce this.

Component Configuration

By default Cockpit components are loaded into the browser with a rather strict security policy. It allows no inline javascript, and no inline CSS. Eval is disabled. The strict policy prevents the browser from loading resources resources or connecting to other machines.

You can place a line in your manifest.json that changes the default policy. It's recommended not to.

Dependencies

Some javascript libraries need to be aware of CSP, and adjust their behavior to not fall afoul of the policy. Here's a list of the libraries we've used with CSP and where we've run into problems.

The list is incomplete.

Clone this wiki locally