Skip to content

Commit 42c309a

Browse files
authored
fix csp errors in with-strict-csp-app example (#14262)
Added proper content security policies in the dev environment fixes: #14221
1 parent e87b739 commit 42c309a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

examples/with-strict-csp/pages/_document.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ const cspHashOf = (text) => {
66
hash.update(text)
77
return `'sha256-${hash.digest('base64')}'`
88
}
9-
109
export default class MyDocument extends Document {
1110
render() {
12-
const csp = `default-src 'self'; script-src 'self' ${cspHashOf(
11+
let csp = `default-src 'self'; script-src 'self' ${cspHashOf(
1312
NextScript.getInlineScriptSource(this.props)
1413
)}`
14+
if (process.env.NODE_ENV !== 'production') {
15+
csp = `style-src 'self' 'unsafe-inline'; font-src 'self' data:; default-src 'self'; script-src 'unsafe-eval' 'self' ${cspHashOf(
16+
NextScript.getInlineScriptSource(this.props)
17+
)}`
18+
}
1519

1620
return (
1721
<html>

0 commit comments

Comments
 (0)