mirror of
https://github.com/strapi/strapi.git
synced 2025-11-02 10:55:37 +00:00
Merge pull request #11433 from strapi/v4/security-allow-gql-doc-playgrounds
Lighten the security config for /document and /graphql playgrounds
This commit is contained in:
commit
28169ce6f9
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const { defaultsDeep } = require('lodash/fp');
|
||||
const { defaultsDeep, merge } = require('lodash/fp');
|
||||
const helmet = require('koa-helmet');
|
||||
|
||||
const defaults = {
|
||||
@ -27,4 +27,19 @@ const defaults = {
|
||||
/**
|
||||
* @type {import('./').MiddlewareFactory}
|
||||
*/
|
||||
module.exports = config => helmet(defaultsDeep(defaults, config));
|
||||
module.exports = config => (ctx, next) => {
|
||||
let helmetConfig = defaultsDeep(defaults, config);
|
||||
|
||||
if (ctx.method === 'GET' && ['/graphql', '/documentation'].includes(ctx.path)) {
|
||||
helmetConfig = merge(helmetConfig, {
|
||||
contentSecurityPolicy: {
|
||||
directives: {
|
||||
'script-src': ["'self'", "'unsafe-inline'", 'cdn.jsdelivr.net'],
|
||||
'img-src': ["'self'", 'data:', 'cdn.jsdelivr.net'],
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return helmet(helmetConfig)(ctx, next);
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user