Skip to content

Commit f4e8116

Browse files
authored
Merge pull request #55387 from nextcloud/fix/remove-legacy-oc-response
fix: Delete legacy OC_Response
2 parents 10e3192 + eb54143 commit f4e8116

File tree

4 files changed

+36
-86
lines changed

4 files changed

+36
-86
lines changed

lib/base.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

lib/composer/composer/autoload_classmap.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2179,7 +2179,6 @@
21792179
'OC_Helper' => $baseDir . '/lib/private/legacy/OC_Helper.php',
21802180
'OC_Hook' => $baseDir . '/lib/private/legacy/OC_Hook.php',
21812181
'OC_JSON' => $baseDir . '/lib/private/legacy/OC_JSON.php',
2182-
'OC_Response' => $baseDir . '/lib/private/legacy/OC_Response.php',
21832182
'OC_Template' => $baseDir . '/lib/private/legacy/OC_Template.php',
21842183
'OC_User' => $baseDir . '/lib/private/legacy/OC_User.php',
21852184
'OC_Util' => $baseDir . '/lib/private/legacy/OC_Util.php',

lib/composer/composer/autoload_static.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2220,7 +2220,6 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
22202220
'OC_Helper' => __DIR__ . '/../../..' . '/lib/private/legacy/OC_Helper.php',
22212221
'OC_Hook' => __DIR__ . '/../../..' . '/lib/private/legacy/OC_Hook.php',
22222222
'OC_JSON' => __DIR__ . '/../../..' . '/lib/private/legacy/OC_JSON.php',
2223-
'OC_Response' => __DIR__ . '/../../..' . '/lib/private/legacy/OC_Response.php',
22242223
'OC_Template' => __DIR__ . '/../../..' . '/lib/private/legacy/OC_Template.php',
22252224
'OC_User' => __DIR__ . '/../../..' . '/lib/private/legacy/OC_User.php',
22262225
'OC_Util' => __DIR__ . '/../../..' . '/lib/private/legacy/OC_Util.php',

lib/private/legacy/OC_Response.php

Lines changed: 0 additions & 83 deletions
This file was deleted.

0 commit comments

Comments
 (0)