-
Notifications
You must be signed in to change notification settings - Fork 8
CSS injection can be disallowed by CSP's style-src #1
Description
The isolation component of our library relies on injecting an inline <style> tag. If the client page is to contain CSP Policy Directives, we have the following options for maintaining compatibility with this library.
Option 1: unsafe-inline
We can specify that the client page must add 'unsafe-inline' to the style-src policy.
Content-Security-Policy: style-src ... 'unsafe-inline'
This may expose the client page to possible CSS attacks...
Option 2: domain-hosted css
To avoid inline styles, we can specify that the CSS required by this library must be exported to a css file hosted on some domain, say http://example.com/viewport.css (see css file here)
The domain hosting the CSS file must then be added to the style-src policy:
Content-Security-Policy: style-src ... example.com
The usage will contain an option for specifying the URL of the CSS file:
viewport.freeze(1.0, 'elementID', {styleUrl: 'http://example.com/viewport.css'});
// will add <link rel='stylesheet' href='http://example.com/viewport.css'> to document.head
viewport.thaw();
// will remove aforementioned <link> tagOption 3: modify element styles via JS
We could skirt CSP just by modifying the body child element's style.display property with JS. Two problems:
- the
style.displayproperty will have to be restored to its original value when thawing - elements that are added during freeze are not accounted for