Skip to content

Enforce CSP #551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,12 @@ export const contentSecurityPolicyMiddleware = (

// TODO(aomarks) We use some data: URLs for SVGs in docs.css. There's
// probably a simpler way.
//
// The ytimg.com domain is needed for embedded YouTube videos.
`img-src 'self' data: https://i.ytimg.com/`,
//
// The googletagmanager.com domain is needed for Google Analytics
// (https://developers.google.com/tag-manager/web/csp).
`img-src 'self' data: https://i.ytimg.com/ https://www.googletagmanager.com/`,

// Disallow any embeds, applets, etc. This would usually be covered by
// `default-src: 'none'`, but we can't set that for the reason explained
Expand Down Expand Up @@ -201,9 +205,7 @@ export const contentSecurityPolicyMiddleware = (
} else {
policy = strictFallbackCsp;
}
// TODO(aomarks) Remove -Report-Only suffix when we are confident the
// policy is working.
ctx.set('Content-Security-Policy-Report-Only', policy);
ctx.set('Content-Security-Policy', policy);
return next();
};
};