Create and pass nonce value through middleware
This commit is contained in:
parent
969b304193
commit
0807f51d6c
@ -78,6 +78,8 @@ async function setBody(context: RequestContext) {
|
||||
}
|
||||
|
||||
async function setHeaders(context: RequestContext) {
|
||||
const nonce = crypto.randomUUID().replace(/-/g, "");
|
||||
context.data.nonce = nonce;
|
||||
const response = await context.next();
|
||||
|
||||
const rtvValues = [
|
||||
@ -110,11 +112,13 @@ async function setHeaders(context: RequestContext) {
|
||||
],
|
||||
"media-src": ["https://mediaproxy.carcrushers.cc"],
|
||||
"script-src": ["https://challenges.cloudflare.com", "'self'"],
|
||||
"style-src": [`nonce-${nonce}`, "'self'"],
|
||||
};
|
||||
|
||||
const directives = [];
|
||||
|
||||
for (const [k, v] of Object.entries(policies)) directives.push(`${k} ${v}`);
|
||||
for (const [k, v] of Object.entries(policies))
|
||||
directives.push(`${k} ${v.join(" ")}`);
|
||||
|
||||
response.headers.set("Content-Security-Policy", directives.join("; "));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user