Skip to content
This repository was archived by the owner on Apr 3, 2019. It is now read-only.

Commit 76b2014

Browse files
Shane Tomlinsonvladikoff
authored andcommitted
feat(server): Remove unsafe-eval and reportOnly CSP rules! (#4595) r=vladikoff,jrgm
`unsafe-eval` was added to allow Selenium tests to run. With geckodriver, unsafe-eval is no longer needed! This removes support for unsafe-eval, and only hooks up the reportOnly CSP middleware if there are any declarations. fixes #4594
1 parent 59cba43 commit 76b2014

File tree

4 files changed

+15
-32
lines changed

4 files changed

+15
-32
lines changed

server/bin/fxa-content-server.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ function makeApp() {
8787
app.use(csp({ rules: cspRulesBlocking }));
8888
}
8989
if (config.get('csp.reportOnlyEnabled')) {
90-
app.use(csp({ rules: cspRulesReportOnly }));
90+
// There has to be more than a `reportUri`
91+
// to enable reportOnly CSP.
92+
if (Object.keys(cspRulesReportOnly.directives).length > 1) {
93+
app.use(csp({ rules: cspRulesReportOnly }));
94+
}
9195
}
9296
if (config.get('hpkp.enabled')) {
9397
app.use(hpkp(config));

server/lib/csp/blocking.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,8 @@ module.exports = function (config) {
3737
// The sha of the embedded <style> tag in default-profile.svg.
3838
const EMBEDDED_STYLE_SHA = "'sha256-9n6ek6ecEYlqel7uDyKLy6fdGNo3vw/uScXSq9ooQlk='";
3939
// keyword sources - https://www.w3.org/TR/CSP2/#keyword_source
40-
// Note: "'unsafe-inline'" is not yet used in this module.
40+
// Note: "'unsafe-inline'" and "'unsafe-eval'" are not used in this module.
4141
const SELF = "'self'";
42-
const UNSAFE_EVAL = "'unsafe-eval'";
43-
4442

4543
function addCdnRuleIfRequired(target) {
4644
if (CDN_URL !== PUBLIC_URL) {
@@ -75,11 +73,7 @@ module.exports = function (config) {
7573
objectSrc: [NONE],
7674
reportUri: config.get('csp.reportUri'),
7775
scriptSrc: addCdnRuleIfRequired([
78-
SELF,
79-
// allow unsafe-eval for functional tests. A report-only middleware
80-
// is also added that does not allow 'unsafe-eval' so that we can see
81-
// if other scripts are being added.
82-
UNSAFE_EVAL
76+
SELF
8377
]),
8478
styleSrc: addCdnRuleIfRequired([
8579
SELF,
@@ -101,8 +95,7 @@ module.exports = function (config) {
10195
PROFILE_IMAGES_SERVER,
10296
PROFILE_SERVER,
10397
PUBLIC_URL,
104-
SELF,
105-
UNSAFE_EVAL
98+
SELF
10699
}
107100
};
108101

server/lib/csp/report-only.js

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,16 @@
55

66
/**
77
* reportOnlyCspMiddleware is where to declare experimental rules that
8-
* will not cause a resource to be blocked if it runs afowl of a rule, but will
9-
* cause the resource to be reported.
8+
* will not cause a resource to be blocked if it runs afowl of a rule, but
9+
* will cause the resource to be reported.
10+
*
11+
* If no directives other than `reportUri` are declared, the CSP reportOnly
12+
* middleware will not be added.
1013
*/
1114
module.exports = function (config) {
12-
var CDN_URL = config.get('static_resource_url');
13-
var PUBLIC_URL = config.get('public_url');
14-
var SELF = "'self'";
15-
16-
function addCdnRuleIfRequired(target) {
17-
if (CDN_URL !== PUBLIC_URL) {
18-
target.push(CDN_URL);
19-
}
20-
21-
return target;
22-
}
23-
2415
return {
2516
directives: {
26-
reportUri: config.get('csp.reportOnlyUri'),
27-
scriptSrc: addCdnRuleIfRequired([
28-
SELF
29-
])
17+
reportUri: config.get('csp.reportOnlyUri')
3018
},
3119
reportOnly: true
3220
};

tests/server/csp.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,8 @@ define([
7777
assert.include(objectSrc, Sources.NONE);
7878

7979
const scriptSrc = directives.scriptSrc;
80-
assert.lengthOf(scriptSrc, 3);
80+
assert.lengthOf(scriptSrc, 2);
8181
assert.include(scriptSrc, Sources.SELF);
82-
assert.include(scriptSrc, Sources.UNSAFE_EVAL);
8382
assert.include(scriptSrc, CDN_SERVER);
8483

8584
const styleSrc = directives.styleSrc;
@@ -91,4 +90,3 @@ define([
9190

9291
registerSuite(suite);
9392
});
94-

0 commit comments

Comments
 (0)