/Wiki/sources/honojs__hono/2026/https-hono-dev-llms-full-txt-nonce-attribute-499828ea2804-nonce-attribute-s0232-c0002.md
`nonce` attribute (3) - hono-docs
nonce attribute (3) Source evidence: /Sources/raw/honojs hono/honojs hono.md Canonical citation: https://hono.dev/llms full.txt nonce attribute Summary If yo...
nonce attribute (3)
Source evidence: /Sources/raw/honojshono/honojshono.md Canonical citation: https://hono.dev/llms-full.txt#nonce-attribute
Summary
If you want to generate the nonce value yourself, you can also specify a function as the following: ```tsx const app = new Hono () const myNonceGenerator: ContentSecurityPolicyOptionHandler = (c) => { // This function is called on every...
Content
If you want to generate the nonce value yourself, you can also specify a function as the following:
const app = new Hono<{
Variables: { myNonce: string }
}>()
const myNonceGenerator: ContentSecurityPolicyOptionHandler = (c) => {
// This function is called on every request.
const nonce = Math.random().toString(36).slice(2)
c.set('myNonce', nonce)
return `'nonce-${nonce}'`
}
app.get(
'*',
secureHeaders({
contentSecurityPolicy: {
scriptSrc: [myNonceGenerator, 'https://allowed1.example.com'],
},
})
)
app.get('/', (c) => {
return c.html(
<html>
<body>
{/** contents */}
<script src='/js/client.js' nonce={c.get('myNonce')} />
</body>
</html>
)
})