Skip to content
Myr

refactor(secure-headers): refine secureHeadersNonce init (#3535)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Cotton Hou · committed by GitHub · parent f8664b0 · Browse files · 1 file+6 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+6 added−7 removed

  • other:+6 added−7 removed

1 file+6 added−7 removed

modified:src/middleware/secure-headers/secure-headers.ts+6 added-7 removed
130 unmodified lines
131 return encodeBase64(buffer)132}133134export const NONCE: ContentSecurityPolicyOptionHandler = (ctx) => {135 const nonce =136 ctx.get('secureHeadersNonce') ||137 (() => {138 const newNonce = generateNonce()139 ctx.set('secureHeadersNonce', newNonce)140 return newNonce141 })()135 const key = 'secureHeadersNonce'136 const init = ctx.get(key)137 const nonce = init || generateNonce()138 if (init == null) {139 ctx.set(key, nonce)140 }141 return `'nonce-${nonce}'`142}143144/**
187 unmodified lines