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 Nonce #646

Closed
wants to merge 1 commit into from
Closed

CSP Nonce #646

wants to merge 1 commit into from

Conversation

g-stefan
Copy link

@g-stefan g-stefan commented Jun 5, 2024

This modification allow usage when CSP Nonce is set (same nonce on script and style).
The Content-Security-Policy headers are as follow:

  • script-src 'self' 'nonce-[foo-bar]' 'strict-dynamic';
  • style-src 'self' 'nonce-[foo-bar]';

The code uses the nonce from first document loaded script (can be the OverlayScrollbars source or other), as allowed by javascript CSP specification Nonce
I now can use OverlayScrollbars with more restrictive CSP. No need for unsafe-inline.

Without patch:

image

With patch:

image

Thank you!

@KingSora
Copy link
Owner

KingSora commented Jun 5, 2024

Good day @g-stefan :)

I havent really considered CSP before..

To me this implementation looks a little bit hacky, wouldn't something like this be better?

// asssign the nonce before you interact with the library
OverlayScrollbars.nonce('noncevalue');

// after nonce is assigned you can do everything
const osInstance = OverlayScrollbars(document.body, {});

@g-stefan
Copy link
Author

g-stefan commented Jun 5, 2024

Yes, is better.
The nonce must be applied to the style node fragment. I don't know the internals. How the style node is generated/extracted. So is a hacky way for me at the moment.
Thank you!

@g-stefan g-stefan closed this Jun 5, 2024
@KingSora
Copy link
Owner

@g-stefan I've published v2.9.0 which includes this change :)

@g-stefan
Copy link
Author

Tested. Works flawlessly!
Thank you!

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 this pull request may close these issues.

2 participants