summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2015-03-04 09:36:01 +0100
committerMorris Jobke <hey@morrisjobke.de>2015-03-04 09:36:01 +0100
commitf1d74e8803efc2d642dd37751eff928ec42b8ec6 (patch)
tree698fe18880f63be71b54ea9f5b2ae64b64377db8 /core
parent84785a6a390733fead61af5856c56dbc9ad19cd9 (diff)
parentb4cfc79b5a09ea53c8a76082e1d0bf85abf0e579 (diff)
downloadnextcloud-server-f1d74e8803efc2d642dd37751eff928ec42b8ec6.tar.gz
nextcloud-server-f1d74e8803efc2d642dd37751eff928ec42b8ec6.zip
Merge pull request #14651 from owncloud/add-some-headers-to-htaccess-for-my-best-friend-jenkins
Let users configure security headers in their Webserver
Diffstat (limited to 'core')
-rw-r--r--core/js/core.json1
-rw-r--r--core/js/js.js8
-rw-r--r--core/js/setupchecks.js96
-rw-r--r--core/js/tests/specs/setupchecksSpec.js337
4 files changed, 441 insertions, 1 deletions
diff --git a/core/js/core.json b/core/js/core.json
index 7f3b313e898..b32ca5ca8f3 100644
--- a/core/js/core.json
+++ b/core/js/core.json
@@ -24,6 +24,7 @@
"config.js",
"multiselect.js",
"oc-requesttoken.js",
+ "setupchecks.js",
"../search/js/search.js"
]
}
diff --git a/core/js/js.js b/core/js/js.js
index 1e9ae4cc695..f24694124ad 100644
--- a/core/js/js.js
+++ b/core/js/js.js
@@ -211,6 +211,14 @@ var OC={
},
/**
+ * Protocol that is used to access this ownCloud instance
+ * @return {string} Used protocol
+ */
+ getProtocol: function() {
+ return window.location.protocol.split(':')[0];
+ },
+
+ /**
* get the absolute path to an image file
* if no extension is given for the image, it will automatically decide
* between .png and .svg based on what the browser supports
diff --git a/core/js/setupchecks.js b/core/js/setupchecks.js
index 00e73162c55..d5bd1c465b2 100644
--- a/core/js/setupchecks.js
+++ b/core/js/setupchecks.js
@@ -70,7 +70,101 @@
url: OC.generateUrl('settings/ajax/checksetup')
}).then(afterCall, afterCall);
return deferred.promise();
+ },
+
+ /**
+ * Runs generic checks on the server side, the difference to dedicated
+ * methods is that we use the same XHR object for all checks to save
+ * requests.
+ *
+ * @return $.Deferred object resolved with an array of error messages
+ */
+ checkGeneric: function() {
+ var self = this;
+ var deferred = $.Deferred();
+ var afterCall = function(data, statusText, xhr) {
+ var messages = [];
+ messages = messages.concat(self._checkSecurityHeaders(xhr));
+ messages = messages.concat(self._checkSSL(xhr));
+ deferred.resolve(messages);
+ };
+
+ $.ajax({
+ type: 'GET',
+ url: OC.generateUrl('heartbeat')
+ }).then(afterCall, afterCall);
+
+ return deferred.promise();
+ },
+
+ /**
+ * Runs check for some generic security headers on the server side
+ *
+ * @param {Object} xhr
+ * @return {Array} Array with error messages
+ */
+ _checkSecurityHeaders: function(xhr) {
+ var messages = [];
+
+ if (xhr.status === 200) {
+ var securityHeaders = {
+ 'X-XSS-Protection': '1; mode=block',
+ 'X-Content-Type-Options': 'nosniff',
+ 'X-Robots-Tag': 'none',
+ 'X-Frame-Options': 'SAMEORIGIN'
+ };
+
+ for (var header in securityHeaders) {
+ if(xhr.getResponseHeader(header) !== securityHeaders[header]) {
+ messages.push(
+ t('core', 'The "{header}" HTTP header is not configured to equal to "{expected}". This is a potential security risk and we recommend adjusting this setting.', {header: header, expected: securityHeaders[header]})
+ );
+ }
+ }
+ } else {
+ messages.push(t('core', 'Error occurred while checking server setup'));
+ }
+
+ return messages;
+ },
+
+ /**
+ * Runs check for some SSL configuration issues on the server side
+ *
+ * @param {Object} xhr
+ * @return {Array} Array with error messages
+ */
+ _checkSSL: function(xhr) {
+ var messages = [];
+
+ if (xhr.status === 200) {
+ if(OC.getProtocol() === 'https') {
+ // Extract the value of 'Strict-Transport-Security'
+ var transportSecurityValidity = xhr.getResponseHeader('Strict-Transport-Security');
+ if(transportSecurityValidity !== null && transportSecurityValidity.length > 8) {
+ var firstComma = transportSecurityValidity.indexOf(";");
+ if(firstComma !== -1) {
+ transportSecurityValidity = transportSecurityValidity.substring(0, firstComma);
+ } else {
+ transportSecurityValidity = transportSecurityValidity.substring(8);
+ }
+ }
+
+ if(isNaN(transportSecurityValidity) || transportSecurityValidity <= 2678399) {
+ messages.push(
+ t('core', 'The "Strict-Transport-Security" HTTP header is not configured to least "2,678,400" seconds. This is a potential security risk and we recommend adjusting this setting.')
+ );
+ }
+ } else {
+ messages.push(
+ t('core', 'You are accessing this site via HTTP. We strongly suggest you configure your server to require using HTTPS instead.')
+ );
+ }
+ } else {
+ messages.push(t('core', 'Error occurred while checking server setup'));
+ }
+
+ return messages;
}
};
})();
-
diff --git a/core/js/tests/specs/setupchecksSpec.js b/core/js/tests/specs/setupchecksSpec.js
new file mode 100644
index 00000000000..487e28a6204
--- /dev/null
+++ b/core/js/tests/specs/setupchecksSpec.js
@@ -0,0 +1,337 @@
+/**
+ * Copyright (c) 2015 Lukas Reschke <lukas@owncloud.com>
+ *
+ * This file is licensed under the Affero General Public License version 3
+ * or later.
+ *
+ * See the COPYING-README file.
+ *
+ */
+
+describe('OC.SetupChecks tests', function() {
+ var suite = this;
+ var protocolStub;
+
+ beforeEach( function(){
+ protocolStub = sinon.stub(OC, 'getProtocol');
+ suite.server = sinon.fakeServer.create();
+ });
+
+ afterEach( function(){
+ suite.server.restore();
+ protocolStub.restore();
+ });
+
+ describe('checkWebDAV', function() {
+ it('should fail with another response status code than 201 or 207', function(done) {
+ var async = OC.SetupChecks.checkWebDAV();
+
+ suite.server.requests[0].respond(200);
+
+ async.done(function( data, s, x ){
+ expect(data).toEqual(['Your web server is not yet set up properly to allow file synchronization because the WebDAV interface seems to be broken.']);
+ done();
+ });
+ });
+
+ it('should return no error with a response status code of 207', function(done) {
+ var async = OC.SetupChecks.checkWebDAV();
+
+ suite.server.requests[0].respond(207);
+
+ async.done(function( data, s, x ){
+ expect(data).toEqual([]);
+ done();
+ });
+ });
+
+ it('should return no error with a response status code of 401', function(done) {
+ var async = OC.SetupChecks.checkWebDAV();
+
+ suite.server.requests[0].respond(401);
+
+ async.done(function( data, s, x ){
+ expect(data).toEqual([]);
+ done();
+ });
+ });
+ });
+
+ describe('checkSetup', function() {
+ it('should return an error if server has no internet connection', function(done) {
+ var async = OC.SetupChecks.checkSetup();
+
+ suite.server.requests[0].respond(
+ 200,
+ {
+ 'Content-Type': 'application/json'
+ },
+ JSON.stringify({data: {serverHasInternetConnection: false}})
+ );
+
+ async.done(function( data, s, x ){
+ expect(data).toEqual(['This server has no working Internet connection. This means that some of the features like mounting external storage, notifications about updates or installation of third-party apps will not work. Accessing files remotely and sending of notification emails might not work, either. We suggest to enable Internet connection for this server if you want to have all features.', 'Your data directory and your files are probably accessible from the Internet. The .htaccess file is not working. We strongly suggest that you configure your web server in a way that the data directory is no longer accessible or you move the data directory outside the web server document root.']);
+ done();
+ });
+ });
+
+ it('should return an error if server has no internet connection and data directory is not protected', function(done) {
+ var async = OC.SetupChecks.checkSetup();
+
+ suite.server.requests[0].respond(
+ 200,
+ {
+ 'Content-Type': 'application/json'
+ },
+ JSON.stringify({data: {serverHasInternetConnection: false, dataDirectoryProtected: false}})
+ );
+
+ async.done(function( data, s, x ){
+ expect(data).toEqual(['This server has no working Internet connection. This means that some of the features like mounting external storage, notifications about updates or installation of third-party apps will not work. Accessing files remotely and sending of notification emails might not work, either. We suggest to enable Internet connection for this server if you want to have all features.', 'Your data directory and your files are probably accessible from the Internet. The .htaccess file is not working. We strongly suggest that you configure your web server in a way that the data directory is no longer accessible or you move the data directory outside the web server document root.']);
+ done();
+ });
+ });
+
+ it('should return an error if the response has no statuscode 200', function(done) {
+ var async = OC.SetupChecks.checkSetup();
+
+ suite.server.requests[0].respond(
+ 500,
+ {
+ 'Content-Type': 'application/json'
+ },
+ JSON.stringify({data: {serverHasInternetConnection: false, dataDirectoryProtected: false}})
+ );
+
+ async.done(function( data, s, x ){
+ expect(data).toEqual(['Error occurred while checking server setup']);
+ done();
+ });
+ });
+ });
+
+ describe('checkGeneric', function() {
+ it('should return an error if the response has no statuscode 200', function(done) {
+ var async = OC.SetupChecks.checkGeneric();
+
+ suite.server.requests[0].respond(
+ 500,
+ {
+ 'Content-Type': 'application/json'
+ }
+ );
+
+ async.done(function( data, s, x ){
+ expect(data).toEqual(['Error occurred while checking server setup', 'Error occurred while checking server setup']);
+ done();
+ });
+ });
+
+ it('should return all errors if all headers are missing', function(done) {
+ protocolStub.returns('https');
+ var async = OC.SetupChecks.checkGeneric();
+
+ suite.server.requests[0].respond(
+ 200,
+ {
+ 'Content-Type': 'application/json',
+ 'Strict-Transport-Security': '2678400'
+ }
+ );
+
+ async.done(function( data, s, x ){
+ expect(data).toEqual(['The "X-XSS-Protection" HTTP header is not configured to equal to "1; mode=block". This is a potential security risk and we recommend adjusting this setting.', 'The "X-Content-Type-Options" HTTP header is not configured to equal to "nosniff". This is a potential security risk and we recommend adjusting this setting.', 'The "X-Robots-Tag" HTTP header is not configured to equal to "none". This is a potential security risk and we recommend adjusting this setting.', 'The "X-Frame-Options" HTTP header is not configured to equal to "SAMEORIGIN". This is a potential security risk and we recommend adjusting this setting.']);
+ done();
+ });
+ });
+
+ it('should return only some errors if just some headers are missing', function(done) {
+ protocolStub.returns('https');
+ var async = OC.SetupChecks.checkGeneric();
+
+ suite.server.requests[0].respond(
+ 200,
+ {
+ 'X-Robots-Tag': 'none',
+ 'X-Frame-Options': 'SAMEORIGIN',
+ 'Strict-Transport-Security': '2678400'
+
+ }
+ );
+
+ async.done(function( data, s, x ){
+ expect(data).toEqual(['The "X-XSS-Protection" HTTP header is not configured to equal to "1; mode=block". This is a potential security risk and we recommend adjusting this setting.', 'The "X-Content-Type-Options" HTTP header is not configured to equal to "nosniff". This is a potential security risk and we recommend adjusting this setting.']);
+ done();
+ });
+ });
+
+ it('should return none errors if all headers are there', function(done) {
+ protocolStub.returns('https');
+ var async = OC.SetupChecks.checkGeneric();
+
+ suite.server.requests[0].respond(
+ 200,
+ {
+ 'X-XSS-Protection': '1; mode=block',
+ 'X-Content-Type-Options': 'nosniff',
+ 'X-Robots-Tag': 'none',
+ 'X-Frame-Options': 'SAMEORIGIN',
+ 'Strict-Transport-Security': '2678400'
+ }
+ );
+
+ async.done(function( data, s, x ){
+ expect(data).toEqual([]);
+ done();
+ });
+ });
+ });
+
+ it('should return a SSL warning if HTTPS is not used', function(done) {
+ protocolStub.returns('http');
+ var async = OC.SetupChecks.checkGeneric();
+
+ suite.server.requests[0].respond(200,
+ {
+ 'X-XSS-Protection': '1; mode=block',
+ 'X-Content-Type-Options': 'nosniff',
+ 'X-Robots-Tag': 'none',
+ 'X-Frame-Options': 'SAMEORIGIN'
+ }
+ );
+
+ async.done(function( data, s, x ){
+ expect(data).toEqual(['You are accessing this site via HTTP. We strongly suggest you configure your server to require using HTTPS instead.']);
+ done();
+ });
+ });
+
+ it('should return an error if the response has no statuscode 200', function(done) {
+ var async = OC.SetupChecks.checkGeneric();
+
+ suite.server.requests[0].respond(
+ 500,
+ {
+ 'Content-Type': 'application/json'
+ },
+ JSON.stringify({data: {serverHasInternetConnection: false, dataDirectoryProtected: false}})
+ );
+ async.done(function( data, s, x ){
+ expect(data).toEqual(['Error occurred while checking server setup', 'Error occurred while checking server setup']);
+ done();
+ });
+ });
+
+ it('should return a SSL warning if SSL used without Strict-Transport-Security-Header', function(done) {
+ protocolStub.returns('https');
+ var async = OC.SetupChecks.checkGeneric();
+
+ suite.server.requests[0].respond(200,
+ {
+ 'X-XSS-Protection': '1; mode=block',
+ 'X-Content-Type-Options': 'nosniff',
+ 'X-Robots-Tag': 'none',
+ 'X-Frame-Options': 'SAMEORIGIN'
+ }
+ );
+
+ async.done(function( data, s, x ){
+ expect(data).toEqual(['The "Strict-Transport-Security" HTTP header is not configured to least "2,678,400" seconds. This is a potential security risk and we recommend adjusting this setting.']);
+ done();
+ });
+ });
+
+ it('should return a SSL warning if SSL used with to small Strict-Transport-Security-Header', function(done) {
+ protocolStub.returns('https');
+ var async = OC.SetupChecks.checkGeneric();
+
+ suite.server.requests[0].respond(200,
+ {
+ 'Strict-Transport-Security': '2678399',
+ 'X-XSS-Protection': '1; mode=block',
+ 'X-Content-Type-Options': 'nosniff',
+ 'X-Robots-Tag': 'none',
+ 'X-Frame-Options': 'SAMEORIGIN'
+ }
+ );
+
+ async.done(function( data, s, x ){
+ expect(data).toEqual(['The "Strict-Transport-Security" HTTP header is not configured to least "2,678,400" seconds. This is a potential security risk and we recommend adjusting this setting.']);
+ done();
+ });
+ });
+
+ it('should return a SSL warning if SSL used with to a bogus Strict-Transport-Security-Header', function(done) {
+ protocolStub.returns('https');
+ var async = OC.SetupChecks.checkGeneric();
+
+ suite.server.requests[0].respond(200,
+ {
+ 'Strict-Transport-Security': 'iAmABogusHeader342',
+ 'X-XSS-Protection': '1; mode=block',
+ 'X-Content-Type-Options': 'nosniff',
+ 'X-Robots-Tag': 'none',
+ 'X-Frame-Options': 'SAMEORIGIN'
+ }
+ );
+
+ async.done(function( data, s, x ){
+ expect(data).toEqual(['The "Strict-Transport-Security" HTTP header is not configured to least "2,678,400" seconds. This is a potential security risk and we recommend adjusting this setting.']);
+ done();
+ });
+ });
+
+ it('should return no SSL warning if SSL used with to exact the minimum Strict-Transport-Security-Header', function(done) {
+ protocolStub.returns('https');
+ var async = OC.SetupChecks.checkGeneric();
+
+ suite.server.requests[0].respond(200, {
+ 'Strict-Transport-Security': '2678400',
+ 'X-XSS-Protection': '1; mode=block',
+ 'X-Content-Type-Options': 'nosniff',
+ 'X-Robots-Tag': 'none',
+ 'X-Frame-Options': 'SAMEORIGIN'
+ });
+
+ async.done(function( data, s, x ){
+ expect(data).toEqual([]);
+ done();
+ });
+ });
+
+ it('should return no SSL warning if SSL used with to more than the minimum Strict-Transport-Security-Header', function(done) {
+ protocolStub.returns('https');
+ var async = OC.SetupChecks.checkGeneric();
+
+ suite.server.requests[0].respond(200, {
+ 'Strict-Transport-Security': '12678400',
+ 'X-XSS-Protection': '1; mode=block',
+ 'X-Content-Type-Options': 'nosniff',
+ 'X-Robots-Tag': 'none',
+ 'X-Frame-Options': 'SAMEORIGIN'
+ });
+
+ async.done(function( data, s, x ){
+ expect(data).toEqual([]);
+ done();
+ });
+ });
+
+ it('should return no SSL warning if SSL used with to more than the minimum Strict-Transport-Security-Header and includeSubDomains parameter', function(done) {
+ protocolStub.returns('https');
+ var async = OC.SetupChecks.checkGeneric();
+
+ suite.server.requests[0].respond(200, {
+ 'Strict-Transport-Security': '12678400; includeSubDomains',
+ 'X-XSS-Protection': '1; mode=block',
+ 'X-Content-Type-Options': 'nosniff',
+ 'X-Robots-Tag': 'none',
+ 'X-Frame-Options': 'SAMEORIGIN'
+ });
+
+ async.done(function( data, s, x ){
+ expect(data).toEqual([]);
+ done();
+ });
+ });
+});