Skip to content

Commit

Permalink
Merge pull request #14198 from strapi/hotfix/graphql-should-exist
Browse files Browse the repository at this point in the history
Loading a plugin should always verify its presence
  • Loading branch information
alexandrebodin committed Aug 24, 2022
2 parents a52b053 + fd8e4c6 commit 33d0b0c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
9 changes: 6 additions & 3 deletions packages/core/strapi/lib/middlewares/body.js
Expand Up @@ -27,12 +27,15 @@ function getFiles(ctx) {
module.exports = (config, { strapi }) => {
const bodyConfig = defaultsDeep(defaults, config);

const { config: gqlConfig } = strapi.plugin('graphql');
const gqlEndpoint = gqlConfig('endpoint');
let gqlEndpoint;
if (strapi.plugin('graphql')) {
const { config: gqlConfig } = strapi.plugin('graphql');
gqlEndpoint = gqlConfig('endpoint');
}

return async (ctx, next) => {
// TODO: find a better way later
if (ctx.url === gqlEndpoint) {
if (gqlEndpoint && ctx.url === gqlEndpoint) {
await next();
} else {
try {
Expand Down
13 changes: 7 additions & 6 deletions packages/core/strapi/lib/middlewares/security.js
Expand Up @@ -35,13 +35,14 @@ module.exports =
(config, { strapi }) =>
(ctx, next) => {
let helmetConfig = defaultsDeep(defaults, config);
const { config: gqlConfig } = strapi.plugin('graphql');
const gqlEndpoint = gqlConfig('endpoint');
const specialPaths = ['/documentation'];

if (
ctx.method === 'GET' &&
[gqlEndpoint, '/documentation'].some((str) => ctx.path.startsWith(str))
) {
if (strapi.plugin('graphql')) {
const { config: gqlConfig } = strapi.plugin('graphql');
specialPaths.push(gqlConfig('endpoint'));
}

if (ctx.method === 'GET' && specialPaths.some((str) => ctx.path.startsWith(str))) {
helmetConfig = merge(helmetConfig, {
contentSecurityPolicy: {
directives: {
Expand Down

0 comments on commit 33d0b0c

Please sign in to comment.