File tree Expand file tree Collapse file tree 4 files changed +30
-3
lines changed Expand file tree Collapse file tree 4 files changed +30
-3
lines changed Original file line number Diff line number Diff line change 1- version : 2
1+ version : 2.1
22jobs :
33 build :
44 docker :
3636 - run :
3737 name : release
3838 command : yarn run semantic-release || true
39+ workflows :
40+ build-and-deploy :
41+ jobs :
42+ - build :
43+ context :
44+ - github-release
45+ - npm-release
Original file line number Diff line number Diff line change @@ -122,3 +122,13 @@ const html = (
122122 < / html>
123123)
124124` ` `
125+
126+ ## Content Security Policy
127+
128+ Make sure your header includes this meta tag:
129+
130+ ` ` ` jsx
131+ < meta property= " csp-nonce" content= {nonce} / >
132+ ` ` `
133+
134+ And in SSR, pass the ` nonce` to ` registry .scriptTags ({ nonce })` .
Original file line number Diff line number Diff line change @@ -29,8 +29,8 @@ export class ScriptsRegistry {
2929 results: { [ src : string ] : { error : ?Error } } = { }
3030 promises: { [ src : string ] : Promise < any > } = { }
3131
32- scriptTags ( ) : React . Node {
33- return this . scripts . map ( props => < script key = { props . src } { ...props } /> )
32+ scriptTags ( options ?: { | nonce ?: string | } ) : React . Node {
33+ return this . scripts . map ( props => < script key = { props . src } nonce = { options ? options . nonce : undefined } { ...props } /> )
3434 }
3535}
3636
Original file line number Diff line number Diff line change 22/* eslint-env browser */
33import { type InnerProps } from './index'
44
5+ let nonce
6+ function getNonce ( ) : string | void {
7+ if ( nonce === undefined ) {
8+ const node = document . querySelector ( 'meta[property="csp-nonce"], meta[name="csp-nonce"]' )
9+ nonce = node ? node . getAttribute ( 'content' ) ?? null : null
10+ }
11+ return nonce
12+ }
13+
514const loadScript = async ( {
615 scriptsRegistry,
716 onLoad,
@@ -29,6 +38,7 @@ const loadScript = async ({
2938 return new Promise ( ( resolve : ( ) = > void , reject : ( error ? : Error ) = > void ) => {
3039 const script = document . createElement ( 'script' )
3140 script . src = src
41+ script . nonce = getNonce ( )
3242 Object . keys ( props ) . forEach ( key => script . setAttribute ( key , props [ key ] ) )
3343 script . onload = resolve
3444 script . onerror = reject
You can’t perform that action at this time.
0 commit comments