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

PlausibleProvider not passing nonce to preload link and init script #110

Open
eliezerbasubi opened this issue Nov 27, 2023 · 5 comments · Fixed by #111
Open

PlausibleProvider not passing nonce to preload link and init script #110

eliezerbasubi opened this issue Nov 27, 2023 · 5 comments · Fixed by #111

Comments

@eliezerbasubi
Copy link

Hey there,

After adding CSP to a Nextjs app, the plausible preload link is being blocked. This is because the link in the header doesn't have the nonce populated to it.

Refused to load the script 'https://plausible.customdomain.com/js/script.js' because it violates the following Content Security Policy directive: "script-src 'self' https: 'nonce-MThjMmQ0NDItNTAzYi00ODQ4LTlhMzktMWJlZjQwODkyYWVh' 'strict-dynamic'". Note that 'strict-dynamic' is present, so host-based allowlisting is disabled. Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.

Although the nonce is being passed to the scriptProps prop, the script loaded with the ID of next-plausible-init is not capturing the nonce.

Screenshot 2023-11-27 at 15 30 25
@4lejandrito
Copy link
Owner

This may be related: #90.

@eliezerbasubi
Copy link
Author

While they appear to be related, there is a distinction: the preloaded link in the header is being blocked by CSP.
As for the inline script, my suggestion would be to spread the scriptProps to the inline script to prevent it from being blocked by CSP if configured.

@4lejandrito
Copy link
Owner

Published as next-plausible@3.12.0. The nonce parameter will be inherited from scriptProps automatically.

@eliezerbasubi
Copy link
Author

Published as next-plausible@3.12.0. The nonce parameter will be inherited from scriptProps automatically.

Great!

Although this update resolves the issue with the inline script, the preloaded script link in the head is still being blocked by CSP because the nonce is not being passed.

Screenshot 2023-11-28 at 13 41 59

Either Next.js or this package appears to be injecting a preloaded script link into the head that doesn't contain the nonce.

@4lejandrito 4lejandrito reopened this Nov 28, 2023
@4lejandrito
Copy link
Owner

I will look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants