Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSP not working for specific routes? (Google Maps) #430

Closed
MickL opened this issue Apr 21, 2024 · 3 comments · Fixed by #429
Closed

CSP not working for specific routes? (Google Maps) #430

MickL opened this issue Apr 21, 2024 · 3 comments · Fixed by #429
Labels
bug Something isn't working

Comments

@MickL
Copy link

MickL commented Apr 21, 2024

Maybe I get it wrong but setting CSP for specific routes doesnt seem to work:

routeRules: {
   '/contact': {
      security: {
        headers: {
          contentSecurityPolicy: {
            'img-src': [
              'https://maps.googleapis.com',
              'https://maps.gstatic.com',
            ], // For Google Maps
          },
        },
      },
    },
}

If I set it globally it works:

security: {
    headers: {
      contentSecurityPolicy: {
        'img-src': [
          "'self'",
          "data:",
          'https://maps.googleapis.com',
          'https://maps.gstatic.com',
        ], // For Google Maps
      },
    },
  },

If I got the docs right and the first example should work I will create a reproduction sandbox.

@MickL MickL added the bug Something isn't working label Apr 21, 2024
@vejja
Copy link
Collaborator

vejja commented Apr 21, 2024

Hi @MickL
Route rules are merged additively with array syntax.
You can overwrite global settings substitutively with string syntax :

routeRules: {
   '/contact': {
      security: {
        headers: {
          contentSecurityPolicy: {
            'img-src': 'https://maps.googleapis.com https://maps.gstatic.com'
            // For Google Maps
          },
        },
      },
    },
}

This is explained in the docs here

FYI we are aware that this is quite complex and not very intuitive. Right now we are constrained by the Nitro router, but we are planning to change this in the future (merging will always be substitutive, which will work as you expect), see PR #429

@MickL
Copy link
Author

MickL commented Apr 21, 2024

If it is merged, shouldn’t it work they way I wrote it? Or am I missing something?

@vejja
Copy link
Collaborator

vejja commented Apr 21, 2024

Sorry I might have misunderstood
What headers do you get ?

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants