From bdf9f7273832bdabee6ee425500daed52ccc0ce3 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Thu, 24 Sep 2026 22:31:38 -0700 Subject: [PATCH] Add SRI to template script --- index.html | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index c41bfa6..72d6460 100644 --- a/index.html +++ b/index.html @@ -255,12 +255,13 @@ setTimeout(() => copyButton.style.setProperty('--display', 'none'), 2500); }) - document.querySelector('#download').addEventListener('click', e => { + document.querySelector('#download').addEventListener('click', async e => { e.preventDefault(); const encrypted = document.querySelector('#ciphertext').textContent; const script = template.match(/([\s\S]*)<\/script>/i)?.[1]; const injectedScript = `const content = '${encrypted}'; ${decrypt.toString()} ${script}`; - const output = template.replace(/([\s\S]*<\/script>/i, `$1>${injectedScript}<\/script>`); + const scriptHash = new Uint8Array(await crypto.subtle.digest('SHA-512', new TextEncoder().encode(injectedScript))).toBase64(); + const output = template.replace(/([\s\S]*<\/script>/i, `$1 integrity="sha512-${scriptHash}">${injectedScript}<\/script>`); downloadHtml(output, `${Date.now()}.html`); }) -- 2.47.3