Skip to content

Commit

Permalink
removeMiddelware
Browse files Browse the repository at this point in the history
  • Loading branch information
brucedonovan committed Oct 16, 2023
1 parent 4f6ec65 commit b85ce4a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import Document, { Html, Head, Main, NextScript } from 'next/document';


function randomNonce(length = 32) {
let nonce = '';
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const charactersLength = characters.length;
for (let i = 0; i < length; i++) {
nonce += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return nonce;
}

export default class MyDocument extends Document {
render() {
const nonce = randomNonce();
const csp = `object-src 'none'; base-uri 'none'; script-src 'self' 'unsafe-eval' 'unsafe-inline' https: http: 'nonce-${nonce}' 'strict-dynamic'`

return (
<Html>
<Head>
Expand All @@ -12,11 +23,12 @@ export default class MyDocument extends Document {
rel="stylesheet"
/>
<link rel="shortcut icon" href="/favicons/favicon.ico" />
<meta httpEquiv="Content-Security-Policy" content={csp} />
<meta httpEquiv='X-Frame-Options' content='DENY' />
</Head>
<body>
<Main />
<NextScript />
<NextScript nonce={nonce} />
</body>
</Html>
);
Expand Down
File renamed without changes.

0 comments on commit b85ce4a

Please sign in to comment.