Skip to content

Commit

Permalink
Fix: adding nonce as a option in wavesurfer parameters to solve CSP p…
Browse files Browse the repository at this point in the history
…roblems (#3858)

* feat: adding nonce option for wavesurfer config

* fix: adding prepare script to build on install

* fix: removing the prepare script to be able to create the pull request

* fix: making XSS adjustments
  • Loading branch information
andrezarzur authored Sep 6, 2024
1 parent 6ee08b0 commit abb95fa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
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 cspNonce = this.options.cspNonce && typeof this.options.cspNonce === 'string' ? this.options.cspNonce.replace(/"/g, '') : '';

shadow.innerHTML = `
<style>
<style${cspNonce ? ` nonce="${cspNonce}"` : ''}>
: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 */
cspNonce?: string
}

const defaultOptions = {
Expand Down

0 comments on commit abb95fa

Please sign in to comment.