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

Fix: adding nonce as a option in wavesurfer parameters to solve CSP problems #3858

Merged

Conversation

andrezarzur
Copy link
Contributor

Short description

Resolves #3602

Implementation details

I've added the nonce property as a new parameter in the WaveSurferOptions type. In the renderer.ts it checks if it was passed, and if it was, it adds it to the style being injected. This assumes you have the nonce value in your frontend to be able to be passed as a option.

How to test it

Try adding a valid nonce value to your WaveSurfer element like this: {nonce: 'example-value'}

Screenshots

image
image

Checklist

  • This PR is covered by e2e tests
  • It introduces no breaking API changes

src/wavesurfer.ts Outdated Show resolved Hide resolved
src/renderer.ts Outdated
shadow.innerHTML = `
<style>
<style ${nonce ? `nonce="${nonce}"` : ''}>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be sanitized for XSS. Something like nonce.replace(/"/g, '')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like this you mean?

<style ${nonce ? `nonce="${nonce.replace(/"/g, '')}"` : ''}>

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better above where you do const nonce

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@katspaugh I've also added some type validation just to avoid any errors

Copy link
Owner

@katspaugh katspaugh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you! ❤️

@katspaugh katspaugh merged commit abb95fa into katspaugh:main Sep 6, 2024
2 checks passed
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.

CSP set to nonce, <style nonce="QWHzeTLwpGPwTNySpBKyHH8k"> not set
2 participants