diff --git a/deno_dist/middleware/secure-headers/index.ts b/deno_dist/middleware/secure-headers/index.ts index 7120ba21e..ccb85b785 100644 --- a/deno_dist/middleware/secure-headers/index.ts +++ b/deno_dist/middleware/secure-headers/index.ts @@ -1,6 +1,6 @@ -import { Buffer } from "node:buffer"; import type { Context } from '../../context.ts' import type { MiddlewareHandler } from '../../types.ts' +import { encodeBase64 } from '../../utils/encode.ts' declare module '../../context.ts' { interface ContextVariableMap { @@ -113,7 +113,7 @@ type SecureHeadersCallback = ( const generateNonce = () => { const buffer = new Uint8Array(16) crypto.getRandomValues(buffer) - return Buffer.from(buffer).toString('base64') + return encodeBase64(buffer) } export const NONCE: ContentSecurityPolicyOptionHandler = (ctx) => { const nonce = diff --git a/src/middleware/secure-headers/index.ts b/src/middleware/secure-headers/index.ts index 545ae6a39..33f0909b9 100644 --- a/src/middleware/secure-headers/index.ts +++ b/src/middleware/secure-headers/index.ts @@ -1,5 +1,6 @@ import type { Context } from '../../context' import type { MiddlewareHandler } from '../../types' +import { encodeBase64 } from '../../utils/encode' declare module '../../context' { interface ContextVariableMap { @@ -112,7 +113,7 @@ type SecureHeadersCallback = ( const generateNonce = () => { const buffer = new Uint8Array(16) crypto.getRandomValues(buffer) - return Buffer.from(buffer).toString('base64') + return encodeBase64(buffer) } export const NONCE: ContentSecurityPolicyOptionHandler = (ctx) => { const nonce =