@@ -579,6 +579,41 @@ private static function performSameSiteCookieProtection(IConfig $config): void {
579579 }
580580 }
581581
582+ /**
583+ * This function adds some security related headers to all requests served via base.php
584+ * The implementation of this function has to happen here to ensure that all third-party
585+ * components (e.g. SabreDAV) also benefit from this headers.
586+ */
587+ private static function addSecurityHeaders (): void {
588+ /**
589+ * FIXME: Content Security Policy for legacy components. This
590+ * can be removed once \OCP\AppFramework\Http\Response from the AppFramework
591+ * is used everywhere.
592+ * @see \OCP\AppFramework\Http\Response::getHeaders
593+ */
594+ $ policy = 'default-src \'self \'; '
595+ . 'script-src \'self \' \'nonce- ' . \OC ::$ server ->getContentSecurityPolicyNonceManager ()->getNonce () . '\'; '
596+ . 'style-src \'self \' \'unsafe-inline \'; '
597+ . 'frame-src *; '
598+ . 'img-src * data: blob:; '
599+ . 'font-src \'self \' data:; '
600+ . 'media-src *; '
601+ . 'connect-src *; '
602+ . 'object-src \'none \'; '
603+ . 'base-uri \'self \'; ' ;
604+ header ('Content-Security-Policy: ' . $ policy );
605+
606+ // Send fallback headers for installations that don't have the possibility to send
607+ // custom headers on the webserver side
608+ if (getenv ('modHeadersAvailable ' ) !== 'true ' ) {
609+ header ('Referrer-Policy: no-referrer ' ); // https://www.w3.org/TR/referrer-policy/
610+ header ('X-Content-Type-Options: nosniff ' ); // Disable sniffing the content type for IE
611+ header ('X-Frame-Options: SAMEORIGIN ' ); // Disallow iFraming from other domains
612+ header ('X-Permitted-Cross-Domain-Policies: none ' ); // https://www.adobe.com/devnet/adobe-media-server/articles/cross-domain-xml-for-streaming.html
613+ header ('X-Robots-Tag: noindex, nofollow ' ); // https://developers.google.com/webmasters/control-crawl-index/docs/robots_meta_tag
614+ }
615+ }
616+
582617 public static function init (): void {
583618 // First handle PHP configuration and copy auth headers to the expected
584619 // $_SERVER variable before doing anything Server object related
@@ -702,7 +737,7 @@ public static function init(): void {
702737 self ::checkConfig ();
703738 self ::checkInstalled ($ systemConfig );
704739
705- OC_Response ::addSecurityHeaders ();
740+ self ::addSecurityHeaders ();
706741
707742 self ::performSameSiteCookieProtection ($ config );
708743
0 commit comments