mirror of
https://github.com/honojs/hono.git
synced 2024-11-22 02:27:49 +01:00
refactor(secure-headers): refine secureHeadersNonce init (#3535)
This commit is contained in:
parent
f8664b03a6
commit
15938b4896
@ -132,13 +132,12 @@ const generateNonce = () => {
|
||||
}
|
||||
|
||||
export const NONCE: ContentSecurityPolicyOptionHandler = (ctx) => {
|
||||
const nonce =
|
||||
ctx.get('secureHeadersNonce') ||
|
||||
(() => {
|
||||
const newNonce = generateNonce()
|
||||
ctx.set('secureHeadersNonce', newNonce)
|
||||
return newNonce
|
||||
})()
|
||||
const key = 'secureHeadersNonce'
|
||||
const init = ctx.get(key)
|
||||
const nonce = init || generateNonce()
|
||||
if (init == null) {
|
||||
ctx.set(key, nonce)
|
||||
}
|
||||
return `'nonce-${nonce}'`
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user