-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Content-Security-Policy to configs (#121)
1. Creates a separate configuration for CSP: `csp.config.js` 2. Removes `App.getIniaialProps()` to re-enable static optimisations 3. Adds the header via `next.config.js`' `header()` method 4. Renames `config.js` to `env.config.js` to make it more clear
- Loading branch information
1 parent
b2e3145
commit 529d984
Showing
4 changed files
with
53 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/*! | ||
* Content-Security-Policy | ||
*/ | ||
const SELF = "'self'" | ||
const PRODUCION = '*.core.ac.uk' | ||
|
||
const config = { | ||
'default-src': [SELF, PRODUCION], | ||
'script-src': [SELF, '*.google-analytics.com'], | ||
// TODO: Remove 'unsafe-inline' when the Next.js' bug is resolved | ||
// See more: https://github.com/vercel/next.js/issues/17445 | ||
'style-src': [SELF, "'unsafe-inline'"], | ||
'img-src': [ | ||
SELF, | ||
PRODUCION, | ||
'data:', | ||
'maps.wikimedia.org', | ||
// Google Analytics may transport data via image: | ||
// https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#transport | ||
'*.google-analytics.com', | ||
], | ||
'connect-src': [SELF, PRODUCION, 'sentry.io', '*.google-analytics.com'], | ||
} | ||
|
||
if (process.env.NODE_ENV !== 'production') { | ||
// Allow hot module replacement using inlined scripts and styles | ||
config['script-src'].push("'unsafe-inline'", "'unsafe-eval'") | ||
config['style-src'].push("'unsafe-inline'") | ||
|
||
// Allow connection to the local hosts in development: | ||
// - local API is running on a different port | ||
// - `localhost` and `127.0.0.1` are not the same domain technically | ||
config['connect-src'].push('localhost:* 127.0.0.1:*') | ||
} | ||
|
||
const policy = Object.entries(config) | ||
.map(([directive, value]) => `${directive} ${value.join(' ')}`) | ||
.join(';') | ||
|
||
module.exports = policy |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters