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
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,10 @@ class Renderer extends EventEmitter<RendererEvents> {
const div = document.createElement('div')
const shadow = div.attachShadow({ mode: 'open' })

const nonce = this.options.nonce;

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

:host {
user-select: none;
min-width: 1px;
Expand Down
2 changes: 2 additions & 0 deletions src/wavesurfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ export type WaveSurferOptions = {
fetchParams?: RequestInit
/** Playback "backend" to use, defaults to MediaElement */
backend?: 'WebAudio' | 'MediaElement'
/** Nonce for CSP if necessary */
nonce?: string
andrezarzur marked this conversation as resolved.
Show resolved Hide resolved
}

const defaultOptions = {
Expand Down