feat: add nonce for inline scripts (#1772)

This commit is contained in:
Marvin Hagemeister
2023-09-14 09:39:53 +02:00
committed by GitHub
parent e67a8dc106
commit 6d9afd62ab
6 changed files with 101 additions and 64 deletions
+8
View File
@@ -35,6 +35,7 @@ export class RenderState {
// Preact state
ownerStack: VNode[] = [];
owners = new Map<VNode, VNode>();
#nonce = "";
constructor(
routeOptions: RenderStateRouteOptions,
@@ -50,6 +51,13 @@ export class RenderState {
if (error) this.routeOptions.error = error;
}
getNonce(): string {
if (this.#nonce === "") {
this.#nonce = crypto.randomUUID().replace(/-/g, "");
}
return this.#nonce;
}
clearTmpState() {
this.renderingUserTemplate = false;
this.ownerStack = [];