@@ -26,6 +26,11 @@ export interface ContentSecurityPolicyMiddlewareOptions {
2626 * allowlisted to run as inline scripts.
2727 */
2828 inlineScriptHashes ?: string [ ] ;
29+
30+ /**
31+ * Origin for Playground preview iframes.
32+ */
33+ playgroundPreviewOrigin : string ;
2934}
3035
3136/**
@@ -39,7 +44,7 @@ export interface ContentSecurityPolicyMiddlewareOptions {
3944 * https://speakerdeck.com/lweichselbaum/csp-a-successful-mess-between-hardening-and-mitigation
4045 */
4146export const contentSecurityPolicyMiddleware = (
42- opts : ContentSecurityPolicyMiddlewareOptions = { }
47+ opts : ContentSecurityPolicyMiddlewareOptions
4348) : Koa . Middleware => {
4449 const cspHeaderValue = [
4550 // TODO(aomarks) We should also enable trusted types, but that will require
@@ -71,13 +76,8 @@ export const contentSecurityPolicyMiddleware = (
7176 // them for automatic reloads.
7277 `connect-src 'self' https://unpkg.com/${ opts . devMode ? ` ws:` : '' } ` ,
7378
74- // TODO(aomarks) These frame-src directives are only needed for embedding
75- // Playground previews. We can know the exact origin that is being used for
76- // Playground previews, so we could restrict this further by passing that in
77- // as a parameter to the middleware.
78- //
79- // In dev mode, http: is needed for http://localhost Playground iframes.
80- `frame-src https:${ opts . devMode ? ' http:' : '' } ` ,
79+ // Playground previews and embedded YouTube videos.
80+ `frame-src ${ opts . playgroundPreviewOrigin } https://www.youtube-nocookie.com/` ,
8181
8282 // We need 'unsafe-inline' because CodeMirror uses inline styles See
8383 // https://discuss.codemirror.net/t/inline-styles-and-content-security-policy/1311/2
0 commit comments