2014-02-03 11:48:17 +00:00
/ *
* Copyright ( c ) 2014
*
* This file is licensed under the Affero General Public License version 3
* or later .
*
* See the COPYING - README file .
*
* /
( function ( ) {
OC . SetupChecks = {
2015-07-29 14:41:22 +00:00
/* Message types */
MESSAGE _TYPE _INFO : 0 ,
MESSAGE _TYPE _WARNING : 1 ,
MESSAGE _TYPE _ERROR : 2 ,
2014-02-03 11:48:17 +00:00
/ * *
* Check whether the WebDAV connection works .
*
* @ return $ . Deferred object resolved with an array of error messages
* /
checkWebDAV : function ( ) {
var deferred = $ . Deferred ( ) ;
var afterCall = function ( xhr ) {
var messages = [ ] ;
if ( xhr . status !== 207 && xhr . status !== 401 ) {
2015-07-29 15:40:42 +00:00
messages . push ( {
2017-11-15 01:53:47 +00:00
msg : t ( 'core' , 'Your web server is not yet properly set up to allow file synchronization, because the WebDAV interface seems to be broken.' ) ,
2015-07-29 15:40:42 +00:00
type : OC . SetupChecks . MESSAGE _TYPE _ERROR
} ) ;
2014-02-03 11:48:17 +00:00
}
deferred . resolve ( messages ) ;
} ;
$ . ajax ( {
type : 'PROPFIND' ,
url : OC . linkToRemoteBase ( 'webdav' ) ,
data : '<?xml version="1.0"?>' +
'<d:propfind xmlns:d="DAV:">' +
'<d:prop><d:resourcetype/></d:prop>' +
'</d:propfind>' ,
2015-12-10 17:08:40 +00:00
complete : afterCall ,
allowAuthErrors : true
2014-02-03 11:48:17 +00:00
} ) ;
return deferred . promise ( ) ;
} ,
2016-01-08 21:32:11 +00:00
/ * *
* Check whether the . well - known URLs works .
*
* @ param url the URL to test
* @ param placeholderUrl the placeholder URL - can be found at oc _defaults . docPlaceholderUrl
2016-01-12 08:53:23 +00:00
* @ param { boolean } runCheck if this is set to false the check is skipped and no error is returned
2016-01-08 21:32:11 +00:00
* @ return $ . Deferred object resolved with an array of error messages
* /
2016-01-12 08:53:23 +00:00
checkWellKnownUrl : function ( url , placeholderUrl , runCheck ) {
2016-01-08 21:32:11 +00:00
var deferred = $ . Deferred ( ) ;
2016-01-12 08:53:23 +00:00
if ( runCheck === false ) {
deferred . resolve ( [ ] ) ;
return deferred . promise ( ) ;
}
2016-01-08 21:32:11 +00:00
var afterCall = function ( xhr ) {
var messages = [ ] ;
if ( xhr . status !== 207 ) {
var docUrl = placeholderUrl . replace ( 'PLACEHOLDER' , 'admin-setup-well-known-URL' ) ;
messages . push ( {
2017-11-15 01:53:47 +00:00
msg : t ( 'core' , 'Your web server is not properly set up to resolve "{url}". Further information can be found in the <a target="_blank" rel="noreferrer noopener" href="{docLink}">documentation</a>.' , { docLink : docUrl , url : url } ) ,
2016-01-12 08:15:57 +00:00
type : OC . SetupChecks . MESSAGE _TYPE _INFO
2016-01-08 21:32:11 +00:00
} ) ;
}
deferred . resolve ( messages ) ;
} ;
$ . ajax ( {
type : 'PROPFIND' ,
url : url ,
2016-06-23 09:54:49 +00:00
complete : afterCall ,
allowAuthErrors : true
2016-01-08 21:32:11 +00:00
} ) ;
return deferred . promise ( ) ;
} ,
2014-02-03 11:48:17 +00:00
/ * *
* Runs setup checks on the server side
*
* @ return $ . Deferred object resolved with an array of error messages
* /
checkSetup : function ( ) {
var deferred = $ . Deferred ( ) ;
var afterCall = function ( data , statusText , xhr ) {
var messages = [ ] ;
if ( xhr . status === 200 && data ) {
2014-12-06 14:34:53 +00:00
if ( ! data . serverHasInternetConnection ) {
2015-07-29 15:40:42 +00:00
messages . push ( {
2017-11-15 01:53:47 +00:00
msg : t ( 'core' , 'This server has no working Internet connection: Multiple endpoints could not be reached. 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. Establish a connection from this server to the Internet to enjoy all features.' ) ,
2015-07-29 15:40:42 +00:00
type : OC . SetupChecks . MESSAGE _TYPE _WARNING
} ) ;
2014-02-03 11:48:17 +00:00
}
2015-03-26 13:51:33 +00:00
if ( ! data . isMemcacheConfigured ) {
2015-07-29 14:41:22 +00:00
messages . push ( {
2017-11-15 01:53:47 +00:00
msg : t ( 'core' , 'No memory cache has been configured. To enhance performance, please configure a memcache, if available. Further information can be found in the <a target="_blank" rel="noreferrer noopener" href="{docLink}">documentation</a>.' , { docLink : data . memcacheDocs } ) ,
2015-07-29 15:40:42 +00:00
type : OC . SetupChecks . MESSAGE _TYPE _INFO
2015-07-29 14:41:22 +00:00
} ) ;
2015-03-26 13:51:33 +00:00
}
2015-05-26 12:11:38 +00:00
if ( ! data . isUrandomAvailable ) {
2015-07-29 15:40:42 +00:00
messages . push ( {
2017-11-15 01:53:47 +00:00
msg : t ( 'core' , '/dev/urandom is not readable by PHP which is highly discouraged for security reasons. Further information can be found in the <a target="_blank" rel="noreferrer noopener" href="{docLink}">documentation</a>.' , { docLink : data . securityDocs } ) ,
2015-07-29 15:40:42 +00:00
type : OC . SetupChecks . MESSAGE _TYPE _WARNING
} ) ;
2015-05-26 12:11:38 +00:00
}
2015-07-27 14:29:05 +00:00
if ( data . isUsedTlsLibOutdated ) {
2015-07-29 15:40:42 +00:00
messages . push ( {
msg : data . isUsedTlsLibOutdated ,
type : OC . SetupChecks . MESSAGE _TYPE _WARNING
} ) ;
2015-07-27 14:29:05 +00:00
}
2015-07-28 08:06:26 +00:00
if ( data . phpSupported && data . phpSupported . eol ) {
2015-08-18 12:42:57 +00:00
messages . push ( {
2017-11-15 01:53:47 +00:00
msg : t ( 'core' , 'You are currently running PHP {version}. Upgrade your PHP version to take advantage of <a target="_blank" rel="noreferrer noopener" href="{phpLink}">performance and security updates provided by the PHP Group</a> as soon as your distribution supports it.' , { version : data . phpSupported . version , phpLink : 'https://secure.php.net/supported-versions.php' } ) ,
2015-08-18 12:42:57 +00:00
type : OC . SetupChecks . MESSAGE _TYPE _INFO
} ) ;
2015-07-28 08:06:26 +00:00
}
2017-12-04 21:49:01 +00:00
if ( data . phpSupported && data . phpSupported . version . substr ( 0 , 3 ) === '5.6' ) {
messages . push ( {
msg : t ( 'core' , 'You are currently running PHP 5.6. The current major version of Nextcloud is the last that is supported on PHP 5.6. It is recommended to upgrade the PHP version to 7.0+ to be able to upgrade to Nextcloud 14.' ) ,
type : OC . SetupChecks . MESSAGE _TYPE _INFO
} ) ;
}
2015-07-25 18:18:32 +00:00
if ( ! data . forwardedForHeadersWorking ) {
2015-08-18 12:42:57 +00:00
messages . push ( {
2017-11-15 01:53:47 +00:00
msg : t ( 'core' , 'The reverse proxy header configuration is incorrect, or you are accessing Nextcloud from a trusted proxy. If not, this is a security issue and can allow an attacker to spoof their IP address as visible to the Nextcloud. Further information can be found in the <a target="_blank" rel="noreferrer noopener" href="{docLink}">documentation</a>.' , { docLink : data . reverseProxyDocs } ) ,
2015-08-18 12:42:57 +00:00
type : OC . SetupChecks . MESSAGE _TYPE _WARNING
} ) ;
2015-07-25 18:18:32 +00:00
}
2015-10-02 14:17:56 +00:00
if ( ! data . isCorrectMemcachedPHPModuleInstalled ) {
messages . push ( {
2017-10-19 10:16:04 +00:00
msg : t ( 'core' , 'Memcached is configured as distributed cache, but the wrong PHP module "memcache" is installed. \\OC\\Memcache\\Memcached only supports "memcached" and not "memcache". See the <a target="_blank" rel="noreferrer noopener" href="{wikiLink}">memcached wiki about both modules</a>.' , { wikiLink : 'https://code.google.com/p/memcached/wiki/PHPClientComparison' } ) ,
2015-10-02 14:17:56 +00:00
type : OC . SetupChecks . MESSAGE _TYPE _WARNING
} ) ;
}
Add code integrity check
This PR implements the base foundation of the code signing and integrity check. In this PR implemented is the signing and verification logic, as well as commands to sign single apps or the core repository.
Furthermore, there is a basic implementation to display problems with the code integrity on the update screen.
Code signing basically happens the following way:
- There is a ownCloud Root Certificate authority stored `resources/codesigning/root.crt` (in this PR I also ship the private key which we obviously need to change before a release :wink:). This certificate is not intended to be used for signing directly and only is used to sign new certificates.
- Using the `integrity:sign-core` and `integrity:sign-app` commands developers can sign either the core release or a single app. The core release needs to be signed with a certificate that has a CN of `core`, apps need to be signed with a certificate that either has a CN of `core` (shipped apps!) or the AppID.
- The command generates a signature.json file of the following format:
```json
{
"hashes": {
"/filename.php": "2401fed2eea6f2c1027c482a633e8e25cd46701f811e2d2c10dc213fd95fa60e350bccbbebdccc73a042b1a2799f673fbabadc783284cc288e4f1a1eacb74e3d",
"/lib/base.php": "55548cc16b457cd74241990cc9d3b72b6335f2e5f45eee95171da024087d114fcbc2effc3d5818a6d5d55f2ae960ab39fd0414d0c542b72a3b9e08eb21206dd9"
},
"certificate": "-----BEGIN CERTIFICATE-----MIIBvTCCASagAwIBAgIUPvawyqJwCwYazcv7iz16TWxfeUMwDQYJKoZIhvcNAQEF\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTAx\nNDEzMTcxMFoXDTE2MTAxNDEzMTcxMFowEzERMA8GA1UEAwwIY29udGFjdHMwgZ8w\nDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANoQesGdCW0L2L+a2xITYipixkScrIpB\nkX5Snu3fs45MscDb61xByjBSlFgR4QI6McoCipPw4SUr28EaExVvgPSvqUjYLGps\nfiv0Cvgquzbx/X3mUcdk9LcFo1uWGtrTfkuXSKX41PnJGTr6RQWGIBd1V52q1qbC\nJKkfzyeMeuQfAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAvF/KIhRMQ3tYTmgHWsiM\nwDMgIDb7iaHF0fS+/Nvo4PzoTO/trev6tMyjLbJ7hgdCpz/1sNzE11Cibf6V6dsz\njCE9invP368Xv0bTRObRqeSNsGogGl5ceAvR0c9BG+NRIKHcly3At3gLkS2791bC\niG+UxI/MNcWV0uJg9S63LF8=\n-----END CERTIFICATE-----",
"signature": "U29tZVNpZ25lZERhdGFFeGFtcGxl"
}
```
`hashes` is an array of all files in the folder with their corresponding SHA512 hashes (this is actually quite cheap to calculate), the `certificate` is the certificate used for signing. It has to be issued by the ownCloud Root Authority and it's CN needs to be permitted to perform the required action. The `signature` is then a signature of the `hashes` which can be verified using the `certificate`.
Steps to do in other PRs, this is already a quite huge one:
- Add nag screen in case the code check fails to ensure that administrators are aware of this.
- Add code verification also to OCC upgrade and unify display code more.
- Add enforced code verification to apps shipped from the appstore with a level of "official"
- Add enfocrced code verification to apps shipped from the appstore that were already signed in a previous release
- Add some developer documentation on how devs can request their own certificate
- Check when installing ownCloud
- Add support for CRLs to allow revoking certificates
**Note:** The upgrade checks are only run when the instance has a defined release channel of `stable` (defined in `version.php`). If you want to test this, you need to change the channel thus and then generate the core signature:
```
➜ master git:(add-integrity-checker) ✗ ./occ integrity:sign-core --privateKey=resources/codesigning/core.key --certificate=resources/codesigning/core.crt
Successfully signed "core"
```
Then increase the version and you should see something like the following:
![2015-11-04_12-02-57](https://cloud.githubusercontent.com/assets/878997/10936336/6adb1d14-82ec-11e5-8f06-9a74801c9abf.png)
As you can see a failed code check will not prevent the further update. It will instead just be a notice to the admin. In a next step we will add some nag screen.
For packaging stable releases this requires the following additional steps as a last action before zipping:
1. Run `./occ integrity:sign-core` once
2. Run `./occ integrity:sign-app` _for each_ app. However, this can be simply automated using a simple foreach on the apps folder.
2015-11-03 19:26:06 +00:00
if ( ! data . hasPassedCodeIntegrityCheck ) {
messages . push ( {
msg : t (
'core' ,
2017-11-15 01:53:47 +00:00
'Some files have not passed the integrity check. Further information on how to resolve this issue can be found in the <a target="_blank" rel="noreferrer noopener" href="{docLink}">documentation</a>. (<a href="{codeIntegrityDownloadEndpoint}">List of invalid files…</a> / <a href="{rescanEndpoint}">Rescan…</a>)' ,
Add code integrity check
This PR implements the base foundation of the code signing and integrity check. In this PR implemented is the signing and verification logic, as well as commands to sign single apps or the core repository.
Furthermore, there is a basic implementation to display problems with the code integrity on the update screen.
Code signing basically happens the following way:
- There is a ownCloud Root Certificate authority stored `resources/codesigning/root.crt` (in this PR I also ship the private key which we obviously need to change before a release :wink:). This certificate is not intended to be used for signing directly and only is used to sign new certificates.
- Using the `integrity:sign-core` and `integrity:sign-app` commands developers can sign either the core release or a single app. The core release needs to be signed with a certificate that has a CN of `core`, apps need to be signed with a certificate that either has a CN of `core` (shipped apps!) or the AppID.
- The command generates a signature.json file of the following format:
```json
{
"hashes": {
"/filename.php": "2401fed2eea6f2c1027c482a633e8e25cd46701f811e2d2c10dc213fd95fa60e350bccbbebdccc73a042b1a2799f673fbabadc783284cc288e4f1a1eacb74e3d",
"/lib/base.php": "55548cc16b457cd74241990cc9d3b72b6335f2e5f45eee95171da024087d114fcbc2effc3d5818a6d5d55f2ae960ab39fd0414d0c542b72a3b9e08eb21206dd9"
},
"certificate": "-----BEGIN CERTIFICATE-----MIIBvTCCASagAwIBAgIUPvawyqJwCwYazcv7iz16TWxfeUMwDQYJKoZIhvcNAQEF\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTAx\nNDEzMTcxMFoXDTE2MTAxNDEzMTcxMFowEzERMA8GA1UEAwwIY29udGFjdHMwgZ8w\nDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANoQesGdCW0L2L+a2xITYipixkScrIpB\nkX5Snu3fs45MscDb61xByjBSlFgR4QI6McoCipPw4SUr28EaExVvgPSvqUjYLGps\nfiv0Cvgquzbx/X3mUcdk9LcFo1uWGtrTfkuXSKX41PnJGTr6RQWGIBd1V52q1qbC\nJKkfzyeMeuQfAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAvF/KIhRMQ3tYTmgHWsiM\nwDMgIDb7iaHF0fS+/Nvo4PzoTO/trev6tMyjLbJ7hgdCpz/1sNzE11Cibf6V6dsz\njCE9invP368Xv0bTRObRqeSNsGogGl5ceAvR0c9BG+NRIKHcly3At3gLkS2791bC\niG+UxI/MNcWV0uJg9S63LF8=\n-----END CERTIFICATE-----",
"signature": "U29tZVNpZ25lZERhdGFFeGFtcGxl"
}
```
`hashes` is an array of all files in the folder with their corresponding SHA512 hashes (this is actually quite cheap to calculate), the `certificate` is the certificate used for signing. It has to be issued by the ownCloud Root Authority and it's CN needs to be permitted to perform the required action. The `signature` is then a signature of the `hashes` which can be verified using the `certificate`.
Steps to do in other PRs, this is already a quite huge one:
- Add nag screen in case the code check fails to ensure that administrators are aware of this.
- Add code verification also to OCC upgrade and unify display code more.
- Add enforced code verification to apps shipped from the appstore with a level of "official"
- Add enfocrced code verification to apps shipped from the appstore that were already signed in a previous release
- Add some developer documentation on how devs can request their own certificate
- Check when installing ownCloud
- Add support for CRLs to allow revoking certificates
**Note:** The upgrade checks are only run when the instance has a defined release channel of `stable` (defined in `version.php`). If you want to test this, you need to change the channel thus and then generate the core signature:
```
➜ master git:(add-integrity-checker) ✗ ./occ integrity:sign-core --privateKey=resources/codesigning/core.key --certificate=resources/codesigning/core.crt
Successfully signed "core"
```
Then increase the version and you should see something like the following:
![2015-11-04_12-02-57](https://cloud.githubusercontent.com/assets/878997/10936336/6adb1d14-82ec-11e5-8f06-9a74801c9abf.png)
As you can see a failed code check will not prevent the further update. It will instead just be a notice to the admin. In a next step we will add some nag screen.
For packaging stable releases this requires the following additional steps as a last action before zipping:
1. Run `./occ integrity:sign-core` once
2. Run `./occ integrity:sign-app` _for each_ app. However, this can be simply automated using a simple foreach on the apps folder.
2015-11-03 19:26:06 +00:00
{
docLink : data . codeIntegrityCheckerDocumentation ,
codeIntegrityDownloadEndpoint : OC . generateUrl ( '/settings/integrity/failed' ) ,
rescanEndpoint : OC . generateUrl ( '/settings/integrity/rescan?requesttoken={requesttoken}' , { 'requesttoken' : OC . requestToken } )
}
) ,
type : OC . SetupChecks . MESSAGE _TYPE _ERROR
} ) ;
}
2017-02-15 06:40:36 +00:00
if ( ! data . isOpcacheProperlySetup ) {
messages . push ( {
msg : t (
'core' ,
2017-11-15 01:53:47 +00:00
'The PHP OPcache is not properly configured. <a target="_blank" rel="noreferrer noopener" href="{docLink}">For better performance it is recommended</a> to use the following settings in the <code>php.ini</code>:' ,
2017-02-15 06:40:36 +00:00
{
docLink : data . phpOpcacheDocumentation ,
}
2017-05-21 23:21:28 +00:00
) + "<pre><code>opcache.enable=1\nopcache.enable_cli=1\nopcache.interned_strings_buffer=8\nopcache.max_accelerated_files=10000\nopcache.memory_consumption=128\nopcache.save_comments=1\nopcache.revalidate_freq=1</code></pre>" ,
2017-02-15 06:40:36 +00:00
type : OC . SetupChecks . MESSAGE _TYPE _INFO
} ) ;
}
2017-03-16 10:48:28 +00:00
if ( ! data . isSettimelimitAvailable ) {
messages . push ( {
msg : t (
'core' ,
2017-11-15 01:53:47 +00:00
'The PHP function "set_time_limit" is not available. This could result in scripts being halted mid-execution, breaking your installation. Enabling this function is strongly recommended.' ) ,
2017-03-16 10:48:28 +00:00
type : OC . SetupChecks . MESSAGE _TYPE _WARNING
} ) ;
}
2017-12-13 11:36:48 +00:00
if ( ! data . hasFreeTypeSupport ) {
messages . push ( {
msg : t (
'core' ,
2018-01-14 14:58:36 +00:00
'Your PHP does not have FreeType support, resulting in breakage of profile pictures and the settings interface.'
2017-12-13 11:36:48 +00:00
) ,
type : OC . SetupChecks . MESSAGE _TYPE _INFO
} )
}
2018-06-04 14:20:01 +00:00
if ( data . hasMissingIndexes ) {
var listOfMissingIndexes = "" ;
data . hasMissingIndexes . forEach ( function ( element ) {
listOfMissingIndexes += "<li>" ;
listOfMissingIndexes += t ( 'core' , 'Missing index "{indexName}" in table "{tableName}".' , element ) ;
listOfMissingIndexes += "</li>" ;
} ) ;
messages . push ( {
msg : t (
'core' ,
'The database is missing some indexes. Due to the fact that adding indexes on big tables could take some time they were not added automatically. By running "occ db:add-missing-indices" those missing indexes could be added manually while the instance keeps running. Once the indexes are added queries to those tables are usually much faster.'
) + "<ul>" + listOfMissingIndexes + "</ul>" ,
type : OC . SetupChecks . MESSAGE _TYPE _INFO
} )
}
2014-02-03 11:48:17 +00:00
} else {
2015-07-29 15:40:42 +00:00
messages . push ( {
msg : t ( 'core' , 'Error occurred while checking server setup' ) ,
type : OC . SetupChecks . MESSAGE _TYPE _ERROR
} ) ;
2014-02-03 11:48:17 +00:00
}
deferred . resolve ( messages ) ;
} ;
$ . ajax ( {
type : 'GET' ,
2015-12-10 17:08:40 +00:00
url : OC . generateUrl ( 'settings/ajax/checksetup' ) ,
allowAuthErrors : true
2014-02-03 11:48:17 +00:00
} ) . then ( afterCall , afterCall ) ;
return deferred . promise ( ) ;
2015-01-19 10:56:04 +00:00
} ,
/ * *
* 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' ,
2015-12-10 17:08:40 +00:00
url : OC . generateUrl ( 'heartbeat' ) ,
allowAuthErrors : true
2015-01-19 10:56:04 +00:00
} ) . then ( afterCall , afterCall ) ;
return deferred . promise ( ) ;
} ,
2016-02-01 17:14:10 +00:00
checkDataProtected : function ( ) {
var deferred = $ . Deferred ( ) ;
if ( oc _dataURL === false ) {
return deferred . resolve ( [ ] ) ;
}
var afterCall = function ( xhr ) {
var messages = [ ] ;
2016-12-05 16:09:23 +00:00
// .ocdata is an empty file in the data directory - if this is readable then the data dir is not protected
if ( xhr . status === 200 && xhr . responseText === '' ) {
2016-02-01 17:14:10 +00:00
messages . push ( {
2017-11-15 01:53:47 +00:00
msg : t ( 'core' , 'Your data directory and files are probably accessible from the Internet. The .htaccess file is not working. It is strongly recommended that you configure your web server so that the data directory is no longer accessible, or move the data directory outside the web server document root.' ) ,
2016-02-01 17:14:10 +00:00
type : OC . SetupChecks . MESSAGE _TYPE _ERROR
} ) ;
}
deferred . resolve ( messages ) ;
} ;
$ . ajax ( {
type : 'GET' ,
2016-12-05 16:09:23 +00:00
url : OC . linkTo ( '' , oc _dataURL + '/.ocdata?t=' + ( new Date ( ) ) . getTime ( ) ) ,
2016-06-23 09:54:49 +00:00
complete : afterCall ,
allowAuthErrors : true
2016-02-01 17:14:10 +00:00
} ) ;
return deferred . promise ( ) ;
} ,
2015-01-19 10:56:04 +00:00
/ * *
* 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 = {
2017-05-13 18:54:08 +00:00
'X-XSS-Protection' : [ '1; mode=block' ] ,
'X-Content-Type-Options' : [ 'nosniff' ] ,
'X-Robots-Tag' : [ 'none' ] ,
'X-Frame-Options' : [ 'SAMEORIGIN' , 'DENY' ] ,
'X-Download-Options' : [ 'noopen' ] ,
'X-Permitted-Cross-Domain-Policies' : [ 'none' ] ,
2015-01-19 10:56:04 +00:00
} ;
for ( var header in securityHeaders ) {
2017-05-13 18:54:08 +00:00
var option = securityHeaders [ header ] [ 0 ] ;
if ( ! xhr . getResponseHeader ( header ) || xhr . getResponseHeader ( header ) . toLowerCase ( ) !== option . toLowerCase ( ) ) {
2017-11-15 01:53:47 +00:00
var msg = t ( 'core' , 'The "{header}" HTTP header is not set to "{expected}". This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.' , { header : header , expected : option } ) ;
2017-05-13 18:54:08 +00:00
if ( xhr . getResponseHeader ( header ) && securityHeaders [ header ] . length > 1 && xhr . getResponseHeader ( header ) . toLowerCase ( ) === securityHeaders [ header ] [ 1 ] . toLowerCase ( ) ) {
2017-11-15 01:53:47 +00:00
msg = t ( 'core' , 'The "{header}" HTTP header is not set to "{expected}". Some features might not work correctly, as it is recommended to adjust this setting accordingly.' , { header : header , expected : option } ) ;
2017-05-13 18:54:08 +00:00
}
2015-07-29 15:40:42 +00:00
messages . push ( {
2017-05-13 18:54:08 +00:00
msg : msg ,
2015-07-29 15:40:42 +00:00
type : OC . SetupChecks . MESSAGE _TYPE _WARNING
} ) ;
2015-01-19 10:56:04 +00:00
}
}
2018-06-02 19:29:36 +00:00
if ( ! xhr . getResponseHeader ( 'Referrer-Policy' ) ||
( xhr . getResponseHeader ( 'Referrer-Policy' ) . toLowerCase ( ) !== 'no-referrer' &&
xhr . getResponseHeader ( 'Referrer-Policy' ) . toLowerCase ( ) !== 'no-referrer-when-downgrade' &&
xhr . getResponseHeader ( 'Referrer-Policy' ) . toLowerCase ( ) !== 'strict-origin' &&
xhr . getResponseHeader ( 'Referrer-Policy' ) . toLowerCase ( ) !== 'strict-origin-when-cross-origin' ) ) {
messages . push ( {
msg : t ( 'core' , 'The "{header}" HTTP header is not set to "{val1}", "{val2}", "{val3}" or "{val4}". This can leak referer information. See the <a target="_blank" rel="noreferrer noopener" href="{link}">W3C Recommendation</a>.' ,
{
header : 'Referrer-Policy' ,
val1 : 'no-referrer' ,
val2 : 'no-referrer-when-downgrade' ,
val3 : 'strict-origin' ,
val4 : 'strict-origin-when-cross-origin' ,
link : 'https://www.w3.org/TR/referrer-policy/'
} ) ,
type : OC . SetupChecks . MESSAGE _TYPE _INFO
} ) ;
}
2015-01-19 10:56:04 +00:00
} else {
2015-07-29 15:40:42 +00:00
messages . push ( {
msg : t ( 'core' , 'Error occurred while checking server setup' ) ,
type : OC . SetupChecks . MESSAGE _TYPE _ERROR
} ) ;
2015-01-19 10:56:04 +00:00
}
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 ) {
2016-08-25 11:24:50 +00:00
var tipsUrl = OC . generateUrl ( 'settings/admin/tips-tricks' ) ;
2015-01-19 10:56:04 +00:00
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 ) {
2015-06-15 08:39:25 +00:00
transportSecurityValidity = transportSecurityValidity . substring ( 8 , firstComma ) ;
2015-01-19 10:56:04 +00:00
} else {
transportSecurityValidity = transportSecurityValidity . substring ( 8 ) ;
}
}
2016-04-13 06:40:49 +00:00
var minimumSeconds = 15552000 ;
2015-06-15 08:39:25 +00:00
if ( isNaN ( transportSecurityValidity ) || transportSecurityValidity <= ( minimumSeconds - 1 ) ) {
2015-07-29 15:40:42 +00:00
messages . push ( {
2017-11-15 01:53:47 +00:00
msg : t ( 'core' , 'The "Strict-Transport-Security" HTTP header is not set to at least "{seconds}" seconds. For enhanced security, it is recommended to enable HSTS as described in the <a href="{docUrl}" rel="noreferrer noopener">security tips</a>.' , { 'seconds' : minimumSeconds , docUrl : tipsUrl } ) ,
2015-07-29 15:40:42 +00:00
type : OC . SetupChecks . MESSAGE _TYPE _WARNING
} ) ;
2015-01-19 10:56:04 +00:00
}
} else {
2015-07-29 15:40:42 +00:00
messages . push ( {
2017-11-15 01:53:47 +00:00
msg : t ( 'core' , 'Accessing site insecurely via HTTP. You are strongly adviced to set up your server to require HTTPS instead, as described in the <a href="{docUrl}">security tips</a>.' , { docUrl : tipsUrl } ) ,
2015-07-29 15:40:42 +00:00
type : OC . SetupChecks . MESSAGE _TYPE _WARNING
} ) ;
2015-01-19 10:56:04 +00:00
}
} else {
2015-07-29 15:40:42 +00:00
messages . push ( {
msg : t ( 'core' , 'Error occurred while checking server setup' ) ,
type : OC . SetupChecks . MESSAGE _TYPE _ERROR
} ) ;
2015-01-19 10:56:04 +00:00
}
return messages ;
2014-02-03 11:48:17 +00:00
}
} ;
} ) ( ) ;