Skip to content

graphql-yoga and helmet #2891

Answered by EmrysMyrddin
Marsup asked this question in Q&A
Jun 26, 2023 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Hi,
Since the GraphiQL page is actually loaded from unpkg.com, you need to configure helmet to allow execution of scripts from this source. You will also need to allow inline scripts execution since GraphiQL is bundled using Webpack, which rely on injection of script tags at runtime.

Here is an example that worked for me:

app.use(
  helmet({
    contentSecurityPolicy: {
      directives: {
        'style-src': ["'self'", 'unpkg.com'],
        'script-src': ["'self'", 'unpkg.com', "'unsafe-inline'"],
        'img-src': ["'self'", 'raw.githubusercontent.com']
      }
    }
  })
)

If you want this configuration to be enabled only for the graphiql route (to avoid enabling unsafe-inline everyw…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Marsup
Comment options

Answer selected by Marsup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants