fix: generate one Content-Security-Policy nonce per render (#1480)

Co-authored-by: Marvin Hagemeister <marvin@deno.com>
This commit is contained in:
jviide
2023-07-20 11:56:09 +02:00
committed by GitHub
co-authored by Marvin Hagemeister
parent 15d8a67a2c
commit ab45c5c42c
2 changed files with 47 additions and 25 deletions
+30
View File
@@ -896,3 +896,33 @@ Deno.test({
sanitizeOps: false,
sanitizeResources: false,
});
Deno.test({
name: "Generate a single nonce value per page",
async fn() {
await withPageName("./tests/fixture/main.ts", async (page, address) => {
await page.goto(address);
await page.waitForSelector("p");
const nonceValues = await page.evaluate(() =>
Array.from(
new Set(
Array.from(document.querySelectorAll("[nonce]")).map((el) =>
el.getAttribute("nonce")
),
),
)
);
assertEquals(
nonceValues.length,
1,
`Found more than 1 nonce value per render`,
);
});
},
sanitizeOps: false,
sanitizeResources: false,
});