File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33 < head >
44 < meta charset ="UTF-8 " />
55 < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
6+ < meta name ="csp-nonce " content ="testnonce123 " />
7+ < meta
8+ http-equiv ="Content-Security-Policy "
9+ content ="
10+ style-src 'self' 'nonce-testnonce123';
11+ style-src-attr 'unsafe-inline';
12+ "
13+ />
614 < title > SuperDoc</ title >
715 </ head >
816 < body >
Original file line number Diff line number Diff line change @@ -219,6 +219,9 @@ export class SuperDoc extends EventEmitter {
219219 // Initialize collaboration if configured
220220 await this . #initCollaboration( this . config . modules ) ;
221221
222+ // Apply csp nonce if provided
223+ if ( this . config . cspNonce ) this . #patchNaiveUIStyles( ) ;
224+
222225 // this.#initTelemetry();
223226 this . #initVueApp( ) ;
224227 this . #initListeners( ) ;
@@ -259,6 +262,19 @@ export class SuperDoc extends EventEmitter {
259262 } ;
260263 }
261264
265+ #patchNaiveUIStyles( ) {
266+ const cspNonce = this . config . cspNonce ;
267+
268+ const originalCreateElement = document . createElement
269+ document . createElement = function ( tagName ) {
270+ const element = originalCreateElement . call ( this , tagName )
271+ if ( tagName . toLowerCase ( ) === 'style' ) {
272+ element . setAttribute ( 'nonce' , cspNonce )
273+ }
274+ return element
275+ }
276+ }
277+
262278 #initDocuments( ) {
263279 const doc = this . config . document ;
264280 const hasDocumentConfig = ! ! doc && typeof doc === 'object' && Object . keys ( this . config . document ) ?. length ;
Original file line number Diff line number Diff line change @@ -77,6 +77,7 @@ const init = async () => {
7777 // isNewFile: true,
7878 // },
7979 // ],
80+ cspNonce: ' testnonce123' ,
8081 modules: {
8182 comments: {
8283 // comments: sampleComments,
You can’t perform that action at this time.
0 commit comments