fix: generate one Content-Security-Policy nonce per render (#1480)
Co-authored-by: Marvin Hagemeister <marvin@deno.com>
This commit is contained in:
co-authored by
Marvin Hagemeister
parent
15d8a67a2c
commit
ab45c5c42c
@@ -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,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user