Skip to content

Commit

Permalink
fix: update csp default handling
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenle committed Mar 14, 2024
1 parent f3e63b3 commit e087f30
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions packages/root/src/render/render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -533,11 +533,18 @@ export class Renderer {
const securityConfig: Partial<RootSecurityConfig> = {};

if (isTrueOrUndefined(userConfig.contentSecurityPolicy)) {
// CSP default values from:
// https://csp.withgoogle.com/docs/strict-csp.html
securityConfig.contentSecurityPolicy = {
directives: {
'base-uri': ["'none'"],
'object-src': ["'none'"],
'script-src': ["'self'"],
// NOTE: nonce is automatically added to this list.
'script-src': [
"'unsafe-inline'",
"'unsafe-eval'",
"'strict-dynamic' https: http:",
],
},
reportOnly: true,
};
Expand Down Expand Up @@ -580,17 +587,8 @@ export class Renderer {
if (typeof contentSecurityPolicy === 'object') {
const directives = contentSecurityPolicy.directives || {};
if (options.nonce) {
// CSP default values from:
// https://csp.withgoogle.com/docs/strict-csp.html
if (!directives['object-src']) {
directives['object-src'] = ["'none'"];
}
if (!directives['base-uri']) {
directives['base-uri'] = ["'none'"];
}
if (!directives['script-src']) {
directives['script-src'] = [
"'self'",
"'unsafe-inline'",
"'unsafe-eval'",
"'strict-dynamic' https: http:",
Expand Down

0 comments on commit e087f30

Please sign in to comment.