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

5082 - Make content-security-policy more strict #5107

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion api/src/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,29 @@ app.use(
// runs with a bunch of defaults: https://github.com/helmetjs/helmet
hpkp: false, // explicitly block dangerous header
contentSecurityPolicy: {
/* jshint ignore:start */
directives: {
frameSrc: ['\'self\''] // prettier-ignore
defaultSrc: ["'none'"],
fontSrc: ["'self'"],
manifestSrc: ["'self'"],
connectSrc: ["'self'"],
formAction: ["'self'"],
imgSrc: [
"'self'",
'data:' // unsafe
],
scriptSrc: [
"'self'",
"'sha256-6i0jYw/zxQO6q9fIxqI++wftTrPWB3yxt4tQqy6By6k='", // Explicitly allow the telemetry script setting startupTimes
"'unsafe-eval'" // AngularJS and several dependencies require this
],
styleSrc: [
"'self'",
"'unsafe-inline'" // angular-ui-bootstrap
],
},
/* jshint ignore:end */
browserSniff: false,
},
})
);
Expand Down
22 changes: 22 additions & 0 deletions tests/e2e/content-security-policy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const utils = require('../utils');
const { expect } = require('chai');

describe('Content Security Policy', () => {
beforeEach(done => {
utils.resetBrowser();
done();
});

/*
If this test fails, you've probably changed the inline telemetry script
If the change is intentional, take the hash recommended in this error and replace the telemetry hash in the API helmet configuration
*/
it('Telemetry script is not blocked by CSP', done => {
browser.manage()
.logs()
.get('browser').then(function(logEntries) {
logEntries.forEach(entry => expect(entry.message).to.not.include('Refused to execute inline script'));
done();
});
});
});
8 changes: 4 additions & 4 deletions webapp/src/templates/inbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="css/inbox.css" />
<link rel="shortcut icon" href="/favicon.ico">
<link rel="manifest" href="manifest.json">
<title id="app"></title>
<script type="text/javascript">
window.startupTimes = {};
window.startupTimes.start = performance.now();
</script>
<link rel="stylesheet" type="text/css" href="css/inbox.css" />
<link rel="shortcut icon" href="/favicon.ico">
<link rel="manifest" href="manifest.json">
<title id="app"></title>
</head>
<body class="inbox {{currentTab}}" ng-controller="InboxCtrl" ng-class="{'show-content': showContent, 'bootstrapped': version && dbWarmedUp, 'select-mode': selectMode}">

Expand Down