diff options
author | Lukas Reschke <lukas@owncloud.com> | 2015-01-19 11:56:04 +0100 |
---|---|---|
committer | Lukas Reschke <lukas@owncloud.com> | 2015-03-02 19:07:46 +0100 |
commit | bbd5f2841561911461d992483cab54f5c18fa342 (patch) | |
tree | 113e9ab1919c8fb42a7fd90db79139b783a643c9 /lib/base.php | |
parent | 1155ad6e389e47e110a415f22eddda1570dc9ff2 (diff) | |
download | nextcloud-server-bbd5f2841561911461d992483cab54f5c18fa342.tar.gz nextcloud-server-bbd5f2841561911461d992483cab54f5c18fa342.zip |
Let users configure security headers in their Webserver
Doing this in the PHP code is not the right approach for multiple reasons:
1. A bug in the PHP code prevents them from being added to the response.
2. They are only added when something is served via PHP and not in other cases (that makes for example the newest IE UXSS which is not yet patched by Microsoft exploitable on ownCloud)
3. Some headers such as the Strict-Transport-Security might require custom modifications by administrators. This was not possible before and lead to buggy situations.
This pull request moves those headers out of the PHP code and adds a security check to the admin settings performed via JS.
Diffstat (limited to 'lib/base.php')
-rw-r--r-- | lib/base.php | 33 |
1 files changed, 4 insertions, 29 deletions
diff --git a/lib/base.php b/lib/base.php index 1f2e90deefd..84616090ec8 100644 --- a/lib/base.php +++ b/lib/base.php @@ -247,34 +247,6 @@ class OC { } } - public static function checkSSL() { - $request = \OC::$server->getRequest(); - - // redirect to https site if configured - if (\OC::$server->getSystemConfig()->getValue('forcessl', false)) { - // Default HSTS policy - $header = 'Strict-Transport-Security: max-age=31536000'; - - // If SSL for subdomains is enabled add "; includeSubDomains" to the header - if(\OC::$server->getSystemConfig()->getValue('forceSSLforSubdomains', false)) { - $header .= '; includeSubDomains'; - } - header($header); - ini_set('session.cookie_secure', true); - - if ($request->getServerProtocol() <> 'https' && !OC::$CLI) { - $url = 'https://' . $request->getServerHost() . $request->getRequestUri(); - header("Location: $url"); - exit(); - } - } else { - // Invalidate HSTS headers - if ($request->getServerProtocol() === 'https') { - header('Strict-Transport-Security: max-age=0'); - } - } - } - public static function checkMaintenanceMode() { // Allow ajax update script to execute without being stopped if (\OC::$server->getSystemConfig()->getValue('maintenance', false) && OC::$SUBURI != '/core/ajax/update.php') { @@ -569,8 +541,11 @@ class OC { self::initTemplateEngine(); self::checkConfig(); self::checkInstalled(); - self::checkSSL(); + OC_Response::addSecurityHeaders(); + if(self::$server->getRequest()->getServerProtocol() === 'https') { + ini_set('session.cookie_secure', true); + } $errors = OC_Util::checkServer(\OC::$server->getConfig()); if (count($errors) > 0) { |