Skip to content
This repository has been archived by the owner on May 22, 2021. It is now read-only.

Handle Content-Security-Policy for self hosting FxA #1480

Merged
merged 1 commit into from
Jul 10, 2020
Merged
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
20 changes: 20 additions & 0 deletions server/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,26 @@ const conf = convict({
default: 'https://identity.mozilla.com/apps/send',
env: 'FXA_KEY_SCOPE'
},
fxa_csp_oauth_url: {
format: String,
default: '',
env: 'FXA_CSP_OAUTH_URL'
},
fxa_csp_content_url: {
format: String,
default: '',
env: 'FXA_CSP_CONTENT_URL'
},
fxa_csp_profile_url: {
format: String,
default: '',
env: 'FXA_CSP_PROFILE_URL'
},
fxa_csp_profileimage_url: {
format: String,
default: '',
env: 'FXA_CSP_PROFILEIMAGE_URL'
},
survey_url: {
format: String,
default: '',
Expand Down
24 changes: 21 additions & 3 deletions server/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ module.exports = function(app) {
next();
});
if (!IS_DEV) {
app.use(
helmet.contentSecurityPolicy({
let csp = {
directives: {
defaultSrc: ["'self'"],
connectSrc: [
Expand Down Expand Up @@ -62,9 +61,28 @@ module.exports = function(app) {
objectSrc: ["'none'"],
reportUri: '/__cspreport__'
}
})
}

csp.directives.connectSrc.push(config.base_url.replace(/^https:\/\//,'wss://'))
if(config.fxa_csp_oauth_url != ""){
csp.directives.connectSrc.push(config.fxa_csp_oauth_url)
}
if(config.fxa_csp_content_url != "" ){
csp.directives.connectSrc.push(config.fxa_csp_content_url)
}
if(config.fxa_csp_profile_url != "" ){
csp.directives.connectSrc.push(config.fxa_csp_profile_url)
}
if(config.fxa_csp_profileimage_url != ""){
csp.directives.imgSrc.push(config.fxa_csp_profileimage_url)
}


app.use(
helmet.contentSecurityPolicy(csp)
);
}

app.use(function(req, res, next) {
res.set('Pragma', 'no-cache');
res.set(
Expand Down