2014-02-03 15:48:17 +04: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 17:41:22 +03:00
/* Message types */
MESSAGE _TYPE _INFO : 0 ,
MESSAGE _TYPE _WARNING : 1 ,
MESSAGE _TYPE _ERROR : 2 ,
2014-02-03 15:48:17 +04: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 18:40:42 +03:00
messages . push ( {
2017-11-15 04:53:47 +03: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 18:40:42 +03:00
type : OC . SetupChecks . MESSAGE _TYPE _ERROR
} ) ;
2014-02-03 15:48:17 +04: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>' ,
2020-02-22 00:13:49 +03:00
contentType : 'application/xml; charset=utf-8' ,
2015-12-10 20:08:40 +03:00
complete : afterCall ,
allowAuthErrors : true
2014-02-03 15:48:17 +04:00
} ) ;
return deferred . promise ( ) ;
} ,
2016-01-09 00:32:11 +03:00
/ * *
* Check whether the . well - known URLs works .
*
* @ param url the URL to test
2019-05-14 12:14:29 +03:00
* @ param placeholderUrl the placeholder URL - can be found at OC . theme . docPlaceholderUrl
2016-01-12 11:53:23 +03:00
* @ param { boolean } runCheck if this is set to false the check is skipped and no error is returned
2018-12-18 21:53:18 +03:00
* @ param { int | int [ ] } expectedStatus the expected HTTP status to be returned by the URL , 207 by default
2016-01-09 00:32:11 +03:00
* @ return $ . Deferred object resolved with an array of error messages
* /
2020-12-14 17:56:07 +03:00
checkWellKnownUrl : function ( verb , url , placeholderUrl , runCheck , expectedStatus , checkCustomHeader ) {
2018-10-10 14:33:57 +03:00
if ( expectedStatus === undefined ) {
2018-12-18 21:53:18 +03:00
expectedStatus = [ 207 ] ;
}
if ( ! Array . isArray ( expectedStatus ) ) {
expectedStatus = [ expectedStatus ] ;
2018-10-10 14:33:57 +03:00
}
2016-01-09 00:32:11 +03:00
var deferred = $ . Deferred ( ) ;
2016-01-12 11:53:23 +03:00
if ( runCheck === false ) {
deferred . resolve ( [ ] ) ;
return deferred . promise ( ) ;
}
2016-01-09 00:32:11 +03:00
var afterCall = function ( xhr ) {
var messages = [ ] ;
2020-12-14 17:56:07 +03:00
var customWellKnown = xhr . getResponseHeader ( 'X-NEXTCLOUD-WELL-KNOWN' )
if ( expectedStatus . indexOf ( xhr . status ) === - 1 || ( checkCustomHeader && ! customWellKnown ) ) {
2016-01-09 00:32:11 +03:00
var docUrl = placeholderUrl . replace ( 'PLACEHOLDER' , 'admin-setup-well-known-URL' ) ;
messages . push ( {
2021-03-01 22:09:44 +03:00
msg : t ( 'core' , 'Your web server is not properly set up to resolve "{url}". Further information can be found in the {linkstart}documentation ↗{linkend}.' , { url : url } )
. replace ( '{linkstart}' , '<a target="_blank" rel="noreferrer noopener" class="external" href="' + docUrl + '">' )
. replace ( '{linkend}' , '</a>' ) ,
2016-01-12 11:15:57 +03:00
type : OC . SetupChecks . MESSAGE _TYPE _INFO
2016-01-09 00:32:11 +03:00
} ) ;
}
deferred . resolve ( messages ) ;
} ;
$ . ajax ( {
2020-12-14 17:56:07 +03:00
type : verb ,
2016-01-09 00:32:11 +03:00
url : url ,
2016-06-23 12:54:49 +03:00
complete : afterCall ,
allowAuthErrors : true
2016-01-09 00:32:11 +03:00
} ) ;
return deferred . promise ( ) ;
} ,
2019-02-20 00:20:33 +03:00
/ * *
* Check whether the . well - known URLs works .
*
* @ param url the URL to test
2019-05-14 12:14:29 +03:00
* @ param placeholderUrl the placeholder URL - can be found at OC . theme . docPlaceholderUrl
2019-02-20 00:20:33 +03:00
* @ param { boolean } runCheck if this is set to false the check is skipped and no error is returned
*
* @ return $ . Deferred object resolved with an array of error messages
* /
checkProviderUrl : function ( url , placeholderUrl , runCheck ) {
var expectedStatus = [ 200 ] ;
var deferred = $ . Deferred ( ) ;
if ( runCheck === false ) {
deferred . resolve ( [ ] ) ;
return deferred . promise ( ) ;
}
var afterCall = function ( xhr ) {
var messages = [ ] ;
if ( expectedStatus . indexOf ( xhr . status ) === - 1 ) {
2019-02-20 12:54:39 +03:00
var docUrl = placeholderUrl . replace ( 'PLACEHOLDER' , 'admin-nginx' ) ;
2019-02-20 00:20:33 +03:00
messages . push ( {
2021-03-01 22:09:44 +03:00
msg : t ( 'core' , 'Your web server is not properly set up to resolve "{url}". This is most likely related to a web server configuration that was not updated to deliver this folder directly. Please compare your configuration against the shipped rewrite rules in ".htaccess" for Apache or the provided one in the documentation for Nginx at it\'s {linkstart}documentation page ↗{linkend}. On Nginx those are typically the lines starting with "location ~" that need an update.' , { docLink : docUrl , url : url } )
. replace ( '{linkstart}' , '<a target="_blank" rel="noreferrer noopener" class="external" href="' + docUrl + '">' )
. replace ( '{linkend}' , '</a>' ) ,
2019-02-20 12:54:39 +03:00
type : OC . SetupChecks . MESSAGE _TYPE _WARNING
2019-02-20 00:20:33 +03:00
} ) ;
}
deferred . resolve ( messages ) ;
} ;
$ . ajax ( {
type : 'GET' ,
url : url ,
complete : afterCall ,
allowAuthErrors : true
} ) ;
return deferred . promise ( ) ;
} ,
2018-11-29 19:01:43 +03:00
/ * *
* Check whether the WOFF2 URLs works .
*
* @ param url the URL to test
2019-05-14 12:14:29 +03:00
* @ param placeholderUrl the placeholder URL - can be found at OC . theme . docPlaceholderUrl
2018-11-29 19:01:43 +03:00
* @ return $ . Deferred object resolved with an array of error messages
* /
checkWOFF2Loading : function ( url , placeholderUrl ) {
var deferred = $ . Deferred ( ) ;
var afterCall = function ( xhr ) {
var messages = [ ] ;
if ( xhr . status !== 200 ) {
var docUrl = placeholderUrl . replace ( 'PLACEHOLDER' , 'admin-nginx' ) ;
messages . push ( {
2021-03-01 22:09:44 +03:00
msg : t ( 'core' , 'Your web server is not properly set up to deliver .woff2 files. This is typically an issue with the Nginx configuration. For Nextcloud 15 it needs an adjustement to also deliver .woff2 files. Compare your Nginx configuration to the recommended configuration in our {linkstart}documentation ↗{linkend}.' , { docLink : docUrl , url : url } )
. replace ( '{linkstart}' , '<a target="_blank" rel="noreferrer noopener" class="external" href="' + docUrl + '">' )
. replace ( '{linkend}' , '</a>' ) ,
2018-11-29 19:01:43 +03:00
type : OC . SetupChecks . MESSAGE _TYPE _WARNING
} ) ;
}
deferred . resolve ( messages ) ;
} ;
$ . ajax ( {
type : 'GET' ,
url : url ,
complete : afterCall ,
allowAuthErrors : true
} ) ;
return deferred . promise ( ) ;
} ,
2014-02-03 15:48:17 +04: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 ) {
2018-06-13 12:45:49 +03:00
if ( ! data . isGetenvServerWorking ) {
messages . push ( {
msg : t ( 'core' , 'PHP does not seem to be setup properly to query system environment variables. The test with getenv("PATH") only returns an empty response.' ) + ' ' +
2021-03-01 22:09:44 +03:00
t ( 'core' , 'Please check the {linkstart}installation documentation ↗{linkend} for PHP configuration notes and the PHP configuration of your server, especially when using php-fpm.' )
. replace ( '{linkstart}' , '<a target="_blank" rel="noreferrer noopener" class="external" href="' + OC . theme . docPlaceholderUrl . replace ( 'PLACEHOLDER' , 'admin-php-fpm' ) + '">' )
. replace ( '{linkend}' , '</a>' ) ,
2018-06-13 12:45:49 +03:00
type : OC . SetupChecks . MESSAGE _TYPE _WARNING
} ) ;
}
if ( data . isReadOnlyConfig ) {
messages . push ( {
msg : t ( 'core' , 'The read-only config has been enabled. This prevents setting some configurations via the web-interface. Furthermore, the file needs to be made writable manually for every update.' ) ,
type : OC . SetupChecks . MESSAGE _TYPE _INFO
} ) ;
}
if ( ! data . hasValidTransactionIsolationLevel ) {
messages . push ( {
msg : t ( 'core' , 'Your database does not run with "READ COMMITTED" transaction isolation level. This can cause problems when multiple actions are executed in parallel.' ) ,
type : OC . SetupChecks . MESSAGE _TYPE _ERROR
} ) ;
}
if ( ! data . hasFileinfoInstalled ) {
messages . push ( {
msg : t ( 'core' , 'The PHP module "fileinfo" is missing. It is strongly recommended to enable this module to get the best results with MIME type detection.' ) ,
type : OC . SetupChecks . MESSAGE _TYPE _INFO
} ) ;
}
if ( ! data . hasWorkingFileLocking ) {
messages . push ( {
2021-03-01 22:09:44 +03:00
msg : t ( 'core' , 'Transactional file locking is disabled, this might lead to issues with race conditions. Enable "filelocking.enabled" in config.php to avoid these problems. See the {linkstart}documentation ↗{linkend} for more information.' )
. replace ( '{linkstart}' , '<a target="_blank" rel="noreferrer noopener" class="external" href="' + OC . theme . docPlaceholderUrl . replace ( 'PLACEHOLDER' , 'admin-transactional-locking' ) + '">' )
. replace ( '{linkend}' , '</a>' ) ,
2018-06-13 12:45:49 +03:00
type : OC . SetupChecks . MESSAGE _TYPE _WARNING
} ) ;
}
if ( data . suggestedOverwriteCliURL !== '' ) {
messages . push ( {
msg : t ( 'core' , 'If your installation is not installed at the root of the domain and uses system cron, there can be issues with the URL generation. To avoid these problems, please set the "overwrite.cli.url" option in your config.php file to the webroot path of your installation (suggestion: "{suggestedOverwriteCliURL}")' , { suggestedOverwriteCliURL : data . suggestedOverwriteCliURL } ) ,
type : OC . SetupChecks . MESSAGE _TYPE _WARNING
} ) ;
}
2020-12-03 13:12:41 +03:00
if ( ! data . isDefaultPhoneRegionSet ) {
messages . push ( {
2020-12-17 11:14:21 +03:00
msg : t ( 'core' , 'Your installation has no default phone region set. This is required to validate phone numbers in the profile settings without a country code. To allow numbers without a country code, please add "default_phone_region" with the respective {linkstart}ISO 3166-1 code ↗{linkend} of the region to your config file.' )
. replace ( '{linkstart}' , '<a target="_blank" rel="noreferrer noopener" class="external" href="https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements">' )
. replace ( '{linkend}' , '</a>' ) ,
2020-12-03 13:12:41 +03:00
type : OC . SetupChecks . MESSAGE _TYPE _INFO
} ) ;
}
2018-06-13 12:45:49 +03:00
if ( data . cronErrors . length > 0 ) {
var listOfCronErrors = "" ;
data . cronErrors . forEach ( function ( element ) {
listOfCronErrors += "<li>" ;
listOfCronErrors += element . error ;
listOfCronErrors += ' ' ;
listOfCronErrors += element . hint ;
listOfCronErrors += "</li>" ;
} ) ;
messages . push ( {
msg : t (
'core' ,
'It was not possible to execute the cron job via CLI. The following technical errors have appeared:'
) + "<ul>" + listOfCronErrors + "</ul>" ,
type : OC . SetupChecks . MESSAGE _TYPE _ERROR
} )
}
if ( data . cronInfo . diffInSeconds > 3600 ) {
messages . push ( {
2021-03-02 13:41:45 +03:00
msg : t ( 'core' , 'Last background job execution ran {relativeTime}. Something seems wrong. {linkstart}Check the background job settings ↗{linkend}.' , { relativeTime : data . cronInfo . relativeTime } )
2021-03-01 22:09:44 +03:00
. replace ( '{linkstart}' , '<a target="_blank" rel="noreferrer noopener" class="external" href="' + data . cronInfo . backgroundJobsUrl + '">' )
. replace ( '{linkend}' , '</a>' ) ,
2018-06-13 12:45:49 +03:00
type : OC . SetupChecks . MESSAGE _TYPE _ERROR
} ) ;
}
2019-06-25 14:37:31 +03:00
if ( data . serverHasInternetConnectionProblems ) {
2015-07-29 18:40:42 +03:00
messages . push ( {
2017-11-15 04:53:47 +03: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 18:40:42 +03:00
type : OC . SetupChecks . MESSAGE _TYPE _WARNING
} ) ;
2014-02-03 15:48:17 +04:00
}
2015-03-26 16:51:33 +03:00
if ( ! data . isMemcacheConfigured ) {
2015-07-29 17:41:22 +03:00
messages . push ( {
2021-03-01 22:09:44 +03: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 {linkstart}documentation ↗{linkend}.' )
. replace ( '{linkstart}' , '<a target="_blank" rel="noreferrer noopener" class="external" href="' + data . memcacheDocs + '">' )
. replace ( '{linkend}' , '</a>' ) ,
2015-07-29 18:40:42 +03:00
type : OC . SetupChecks . MESSAGE _TYPE _INFO
2015-07-29 17:41:22 +03:00
} ) ;
2015-03-26 16:51:33 +03:00
}
2018-07-27 12:20:47 +03:00
if ( ! data . isRandomnessSecure ) {
2015-07-29 18:40:42 +03:00
messages . push ( {
2021-03-01 22:09:44 +03:00
msg : t ( 'core' , 'No suitable source for randomness found by PHP which is highly discouraged for security reasons. Further information can be found in the {linkstart}documentation ↗{linkend}.' )
. replace ( '{linkstart}' , '<a target="_blank" rel="noreferrer noopener" class="external" href="' + data . securityDocs + '">' )
. replace ( '{linkend}' , '</a>' ) ,
2018-07-27 12:20:47 +03:00
type : OC . SetupChecks . MESSAGE _TYPE _ERROR
2015-07-29 18:40:42 +03:00
} ) ;
2015-05-26 15:11:38 +03:00
}
2015-07-27 17:29:05 +03:00
if ( data . isUsedTlsLibOutdated ) {
2015-07-29 18:40:42 +03:00
messages . push ( {
msg : data . isUsedTlsLibOutdated ,
type : OC . SetupChecks . MESSAGE _TYPE _WARNING
} ) ;
2015-07-27 17:29:05 +03:00
}
2020-02-23 20:00:47 +03:00
if ( data . phpSupported && data . phpSupported . eol ) {
2015-08-18 15:42:57 +03:00
messages . push ( {
2021-03-01 22:09:44 +03:00
msg : t ( 'core' , 'You are currently running PHP {version}. Upgrade your PHP version to take advantage of {linkstart}performance and security updates provided by the PHP Group ↗{linkend} as soon as your distribution supports it.' , { version : data . phpSupported . version } )
. replace ( '{linkstart}' , '<a target="_blank" rel="noreferrer noopener" class="external" href="https://secure.php.net/supported-versions.php">' )
. replace ( '{linkend}' , '</a>' ) ,
2015-08-18 15:42:57 +03:00
type : OC . SetupChecks . MESSAGE _TYPE _INFO
2020-02-23 20:00:47 +03:00
} )
2015-07-28 11:06:26 +03:00
}
2020-02-23 20:00:47 +03:00
if ( data . phpSupported && data . phpSupported . version . substr ( 0 , 3 ) === '7.2' ) {
2017-12-05 00:49:01 +03:00
messages . push ( {
2020-09-10 12:08:25 +03:00
msg : t ( 'core' , 'Nextcloud 20 is the last release supporting PHP 7.2. Nextcloud 21 requires at least PHP 7.3.' ) ,
2017-12-05 00:49:01 +03:00
type : OC . SetupChecks . MESSAGE _TYPE _INFO
2020-02-23 20:00:47 +03:00
} )
2017-12-05 00:49:01 +03:00
}
2015-07-25 21:18:32 +03:00
if ( ! data . forwardedForHeadersWorking ) {
2015-08-18 15:42:57 +03:00
messages . push ( {
2021-03-01 22:09:44 +03: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 {linkstart}documentation ↗{linkend}.' )
. replace ( '{linkstart}' , '<a target="_blank" rel="noreferrer noopener" class="external" href="' + data . reverseProxyDocs + '">' )
. replace ( '{linkend}' , '</a>' ) ,
2015-08-18 15:42:57 +03:00
type : OC . SetupChecks . MESSAGE _TYPE _WARNING
} ) ;
2015-07-25 21:18:32 +03:00
}
2015-10-02 17:17:56 +03:00
if ( ! data . isCorrectMemcachedPHPModuleInstalled ) {
messages . push ( {
2021-03-01 22:09:44 +03: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 {linkstart}memcached wiki about both modules ↗{linkend}.' )
. replace ( '{linkstart}' , '<a target="_blank" rel="noreferrer noopener" class="external" href="https://code.google.com/p/memcached/wiki/PHPClientComparison">' )
. replace ( '{linkend}' , '</a>' ) ,
2015-10-02 17:17:56 +03: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 22:26:06 +03:00
if ( ! data . hasPassedCodeIntegrityCheck ) {
messages . push ( {
2021-03-01 22:09:44 +03:00
msg : t ( 'core' , 'Some files have not passed the integrity check. Further information on how to resolve this issue can be found in the {linkstart1}documentation ↗{linkend}. ({linkstart2}List of invalid files…{linkend} / {linkstart3}Rescan…{linkend})' )
. replace ( '{linkstart1}' , '<a target="_blank" rel="noreferrer noopener" class="external" href="' + data . codeIntegrityCheckerDocumentation + '">' )
. replace ( '{linkstart2}' , '<a href="' + OC . generateUrl ( '/settings/integrity/failed' ) + '">' )
. replace ( '{linkstart3}' , '<a href="' + OC . generateUrl ( '/settings/integrity/rescan?requesttoken={requesttoken}' , { 'requesttoken' : OC . requestToken } ) + '">' )
. replace ( /{linkend}/g , '</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 22:26:06 +03:00
type : OC . SetupChecks . MESSAGE _TYPE _ERROR
} ) ;
}
2018-05-07 21:46:19 +03:00
if ( ! data . hasOpcacheLoaded ) {
messages . push ( {
2021-03-01 22:09:44 +03:00
msg : t ( 'core' , 'The PHP OPcache module is not loaded. {linkstart}For better performance it is recommended ↗{linkend} to load it into your PHP installation.' )
. replace ( '{linkstart}' , '<a target="_blank" rel="noreferrer noopener" class="external" href="' + data . phpOpcacheDocumentation + '">' )
. replace ( '{linkend}' , '</a>' ) ,
2018-05-07 21:46:19 +03:00
type : OC . SetupChecks . MESSAGE _TYPE _INFO
} ) ;
} else if ( ! data . isOpcacheProperlySetup ) {
2017-02-15 09:40:36 +03:00
messages . push ( {
2021-03-02 13:41:45 +03:00
msg : t ( 'core' , 'The PHP OPcache module is not properly configured. {linkstart}For better performance it is recommended ↗{linkend} to use the following settings in the <code>php.ini</code>:' )
2021-03-01 22:09:44 +03:00
. replace ( '{linkstart}' , '<a target="_blank" rel="noreferrer noopener" class="external" href="' + data . phpOpcacheDocumentation + '">' )
. replace ( '{linkend}' , '</a>' ) + "<pre><code>opcache.enable=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 09:40:36 +03:00
type : OC . SetupChecks . MESSAGE _TYPE _INFO
} ) ;
}
2017-03-16 13:48:28 +03:00
if ( ! data . isSettimelimitAvailable ) {
messages . push ( {
msg : t (
'core' ,
2017-11-15 04:53:47 +03: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 13:48:28 +03:00
type : OC . SetupChecks . MESSAGE _TYPE _WARNING
} ) ;
}
2017-12-13 14:36:48 +03:00
if ( ! data . hasFreeTypeSupport ) {
messages . push ( {
msg : t (
'core' ,
2018-01-14 17:58:36 +03:00
'Your PHP does not have FreeType support, resulting in breakage of profile pictures and the settings interface.'
2017-12-13 14:36:48 +03:00
) ,
type : OC . SetupChecks . MESSAGE _TYPE _INFO
} )
}
2018-06-13 12:45:49 +03:00
if ( data . missingIndexes . length > 0 ) {
2018-06-04 17:20:01 +03:00
var listOfMissingIndexes = "" ;
2018-06-13 12:45:49 +03:00
data . missingIndexes . forEach ( function ( element ) {
2018-06-04 17:20:01 +03:00
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
} )
}
2020-11-10 11:34:57 +03:00
if ( data . missingPrimaryKeys . length > 0 ) {
var listOfMissingPrimaryKeys = "" ;
data . missingPrimaryKeys . forEach ( function ( element ) {
listOfMissingPrimaryKeys += "<li>" ;
listOfMissingPrimaryKeys += t ( 'core' , 'Missing primary key on table "{tableName}".' , element ) ;
listOfMissingPrimaryKeys += "</li>" ;
} ) ;
messages . push ( {
msg : t (
'core' ,
'The database is missing some primary keys. Due to the fact that adding primary keys on big tables could take some time they were not added automatically. By running "occ db:add-missing-primary-keys" those missing primary keys could be added manually while the instance keeps running.'
) + "<ul>" + listOfMissingPrimaryKeys + "</ul>" ,
type : OC . SetupChecks . MESSAGE _TYPE _INFO
} )
}
2020-03-11 14:29:52 +03:00
if ( data . missingColumns . length > 0 ) {
var listOfMissingColumns = "" ;
data . missingColumns . forEach ( function ( element ) {
listOfMissingColumns += "<li>" ;
listOfMissingColumns += t ( 'core' , 'Missing optional column "{columnName}" in table "{tableName}".' , element ) ;
listOfMissingColumns += "</li>" ;
} ) ;
messages . push ( {
msg : t (
'core' ,
'The database is missing some optional columns. Due to the fact that adding columns on big tables could take some time they were not added automatically when they can be optional. By running "occ db:add-missing-columns" those missing columns could be added manually while the instance keeps running. Once the columns are added some features might improve responsiveness or usability.'
) + "<ul>" + listOfMissingColumns + "</ul>" ,
type : OC . SetupChecks . MESSAGE _TYPE _INFO
} )
}
2018-12-04 19:05:52 +03:00
if ( data . recommendedPHPModules . length > 0 ) {
var listOfRecommendedPHPModules = "" ;
data . recommendedPHPModules . forEach ( function ( element ) {
listOfRecommendedPHPModules += "<li>" + element + "</li>" ;
} ) ;
messages . push ( {
msg : t (
'core' ,
'This instance is missing some recommended PHP modules. For improved performance and better compatibility it is highly recommended to install them.'
) + "<ul><code>" + listOfRecommendedPHPModules + "</code></ul>" ,
type : OC . SetupChecks . MESSAGE _TYPE _INFO
} )
}
2020-10-25 14:47:43 +03:00
if ( data . imageMagickLacksSVGSupport ) {
messages . push ( {
msg : t (
'core' ,
2020-11-03 23:27:52 +03:00
'Module php-imagick in this instance has no SVG support. For better compatibility it is recommended to install it.'
2020-10-25 14:47:43 +03:00
) ,
type : OC . SetupChecks . MESSAGE _TYPE _INFO
} )
}
2018-12-04 20:43:02 +03:00
if ( data . pendingBigIntConversionColumns . length > 0 ) {
var listOfPendingBigIntConversionColumns = "" ;
data . pendingBigIntConversionColumns . forEach ( function ( element ) {
listOfPendingBigIntConversionColumns += "<li>" + element + "</li>" ;
} ) ;
messages . push ( {
2021-03-01 22:09:44 +03:00
msg : t ( 'core' , 'Some columns in the database are missing a conversion to big int. Due to the fact that changing column types on big tables could take some time they were not changed automatically. By running \'occ db:convert-filecache-bigint\' those pending changes could be applied manually. This operation needs to be made while the instance is offline. For further details read {linkstart}the documentation page about this ↗{linkend}.' )
. replace ( '{linkstart}' , '<a target="_blank" rel="noreferrer noopener" class="external" href="' + OC . theme . docPlaceholderUrl . replace ( 'PLACEHOLDER' , 'admin-bigint-conversion' ) + '">' )
. replace ( '{linkend}' , '</a>' ) + "<ul>" + listOfPendingBigIntConversionColumns + "</ul>" ,
2018-12-04 20:43:02 +03:00
type : OC . SetupChecks . MESSAGE _TYPE _INFO
} )
}
2018-06-12 17:16:29 +03:00
if ( data . isSqliteUsed ) {
messages . push ( {
msg : t (
'core' ,
'SQLite is currently being used as the backend database. For larger installations we recommend that you switch to a different database backend.'
) + ' ' + t ( 'core' , 'This is particularly recommended when using the desktop client for file synchronisation.' ) + ' ' +
2021-03-01 22:09:44 +03:00
t ( 'core' , 'To migrate to another database use the command line tool: \'occ db:convert-type\', or see the {linkstart}documentation ↗{linkend}.' )
. replace ( '{linkstart}' , '<a target="_blank" rel="noreferrer noopener" class="external" href="' + data . databaseConversionDocumentation + '">' )
. replace ( '{linkend}' , '</a>' ) ,
2018-06-12 17:16:29 +03:00
type : OC . SetupChecks . MESSAGE _TYPE _WARNING
} )
}
2018-08-04 22:53:50 +03:00
if ( ! data . isMemoryLimitSufficient ) {
2018-08-04 21:39:39 +03:00
messages . push ( {
msg : t (
'core' ,
'The PHP memory limit is below the recommended value of 512MB.'
) ,
2020-12-16 00:51:37 +03:00
type : OC . SetupChecks . MESSAGE _TYPE _ERROR
2018-08-04 21:39:39 +03:00
} )
}
2018-08-09 20:47:55 +03:00
2018-08-20 21:46:11 +03:00
if ( data . appDirsWithDifferentOwner && data . appDirsWithDifferentOwner . length > 0 ) {
2018-08-09 20:47:55 +03:00
var appDirsWithDifferentOwner = data . appDirsWithDifferentOwner . reduce (
function ( appDirsWithDifferentOwner , directory ) {
return appDirsWithDifferentOwner + '<li>' + directory + '</li>' ;
} ,
''
) ;
messages . push ( {
msg : t ( 'core' , 'Some app directories are owned by a different user than the web server one. ' +
'This may be the case if apps have been installed manually. ' +
'Check the permissions of the following app directories:' )
+ '<ul>' + appDirsWithDifferentOwner + '</ul>' ,
type : OC . SetupChecks . MESSAGE _TYPE _WARNING
} ) ;
}
2019-02-27 12:47:57 +03:00
if ( data . isMysqlUsedWithoutUTF8MB4 ) {
messages . push ( {
2021-03-01 22:09:44 +03:00
msg : t ( 'core' , 'MySQL is used as database but does not support 4-byte characters. To be able to handle 4-byte characters (like emojis) without issues in filenames or comments for example it is recommended to enable the 4-byte support in MySQL. For further details read {linkstart}the documentation page about this ↗{linkend}.' )
. replace ( '{linkstart}' , '<a target="_blank" rel="noreferrer noopener" class="external" href="' + OC . theme . docPlaceholderUrl . replace ( 'PLACEHOLDER' , 'admin-mysql-utf8mb4' ) + '">' )
. replace ( '{linkend}' , '</a>' ) ,
2019-02-27 12:47:57 +03:00
type : OC . SetupChecks . MESSAGE _TYPE _WARNING
} )
}
2019-03-08 15:36:11 +03:00
if ( ! data . isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed ) {
messages . push ( {
msg : t (
'core' ,
2019-03-11 13:00:21 +03:00
'This instance uses an S3 based object store as primary storage. The uploaded files are stored temporarily on the server and thus it is recommended to have 50 GB of free space available in the temp directory of PHP. Check the logs for full details about the path and the available space. To improve this please change the temporary directory in the php.ini or make more space available in that path.'
2019-03-08 15:36:11 +03:00
) ,
2019-10-26 16:12:46 +03:00
type : OC . SetupChecks . MESSAGE _TYPE _WARNING
} )
}
if ( window . location . protocol === 'http:' && data . reverseProxyGeneratedURL . split ( '/' ) [ 0 ] !== 'https:' ) {
messages . push ( {
2021-03-01 22:09:44 +03:00
msg : t ( 'core' , 'You are accessing your instance over a secure connection, however your instance is generating insecure URLs. This most likely means that you are behind a reverse proxy and the overwrite config variables are not set correctly. Please read {linkstart}the documentation page about this ↗{linkend}.' )
. replace ( '{linkstart}' , '<a target="_blank" rel="noreferrer noopener" class="external" href="' + data . reverseProxyDocs + '">' )
. replace ( '{linkend}' , '</a>' ) ,
2019-03-08 15:36:11 +03:00
type : OC . SetupChecks . MESSAGE _TYPE _WARNING
} )
}
2018-08-09 20:47:55 +03:00
2020-07-25 22:53:39 +03:00
OC . SetupChecks . addGenericSetupCheck ( data , 'OCA\\Settings\\SetupChecks\\PhpDefaultCharset' , messages )
OC . SetupChecks . addGenericSetupCheck ( data , 'OCA\\Settings\\SetupChecks\\PhpOutputBuffering' , messages )
2020-08-12 16:16:33 +03:00
OC . SetupChecks . addGenericSetupCheck ( data , 'OCA\\Settings\\SetupChecks\\LegacySSEKeyFormat' , messages )
2020-11-03 02:00:05 +03:00
OC . SetupChecks . addGenericSetupCheck ( data , 'OCA\\Settings\\SetupChecks\\CheckUserCertificates' , messages )
2021-01-03 17:28:31 +03:00
OC . SetupChecks . addGenericSetupCheck ( data , 'OCA\\Settings\\SetupChecks\\SupportedDatabase' , messages )
2020-07-25 22:53:39 +03:00
2014-02-03 15:48:17 +04:00
} else {
2015-07-29 18:40:42 +03:00
messages . push ( {
msg : t ( 'core' , 'Error occurred while checking server setup' ) ,
type : OC . SetupChecks . MESSAGE _TYPE _ERROR
} ) ;
2014-02-03 15:48:17 +04:00
}
deferred . resolve ( messages ) ;
} ;
$ . ajax ( {
type : 'GET' ,
2015-12-10 20:08:40 +03:00
url : OC . generateUrl ( 'settings/ajax/checksetup' ) ,
allowAuthErrors : true
2014-02-03 15:48:17 +04:00
} ) . then ( afterCall , afterCall ) ;
return deferred . promise ( ) ;
2015-01-19 13:56:04 +03:00
} ,
2020-07-25 22:53:39 +03:00
addGenericSetupCheck : function ( data , check , messages ) {
2020-08-12 16:16:33 +03:00
var setupCheck = data [ check ] || { pass : true , description : '' , severity : 'info' , linkToDocumentation : null }
2020-07-25 22:53:39 +03:00
2020-08-07 18:34:03 +03:00
var type = OC . SetupChecks . MESSAGE _TYPE _INFO
2020-07-25 22:53:39 +03:00
if ( setupCheck . severity === 'warning' ) {
type = OC . SetupChecks . MESSAGE _TYPE _WARNING
} else if ( setupCheck . severity === 'error' ) {
type = OC . SetupChecks . MESSAGE _TYPE _ERROR
}
2020-08-12 16:16:33 +03:00
var message = setupCheck . description ;
if ( setupCheck . linkToDocumentation ) {
2021-03-01 22:09:44 +03:00
message += ' ' + t ( 'core' , 'For more details see the {linkstart}documentation ↗{linkend}.' )
. replace ( '{linkstart}' , '<a target="_blank" rel="noreferrer noopener" class="external" href="' + setupCheck . linkToDocumentation + '">' )
. replace ( '{linkend}' , '</a>' ) ;
2020-08-12 16:16:33 +03:00
}
2020-11-03 02:00:05 +03:00
if ( setupCheck . elements ) {
message += '<br><ul>'
setupCheck . elements . forEach ( function ( element ) {
message += '<li>' ;
message += element
message += '</li>' ;
} ) ;
message += '</ul>'
}
2020-08-12 16:16:33 +03:00
2020-07-25 22:53:39 +03:00
if ( ! setupCheck . pass ) {
messages . push ( {
2020-08-12 16:16:33 +03:00
msg : message ,
2020-07-25 22:53:39 +03:00
type : type ,
} )
}
} ,
2015-01-19 13:56:04 +03: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 20:08:40 +03:00
url : OC . generateUrl ( 'heartbeat' ) ,
allowAuthErrors : true
2015-01-19 13:56:04 +03:00
} ) . then ( afterCall , afterCall ) ;
return deferred . promise ( ) ;
} ,
2016-02-01 20:14:10 +03:00
checkDataProtected : function ( ) {
var deferred = $ . Deferred ( ) ;
if ( oc _dataURL === false ) {
return deferred . resolve ( [ ] ) ;
}
var afterCall = function ( xhr ) {
var messages = [ ] ;
2016-12-05 19:09:23 +03: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 20:14:10 +03:00
messages . push ( {
2017-11-15 04:53:47 +03: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 20:14:10 +03:00
type : OC . SetupChecks . MESSAGE _TYPE _ERROR
} ) ;
}
deferred . resolve ( messages ) ;
} ;
$ . ajax ( {
type : 'GET' ,
2016-12-05 19:09:23 +03:00
url : OC . linkTo ( '' , oc _dataURL + '/.ocdata?t=' + ( new Date ( ) ) . getTime ( ) ) ,
2016-06-23 12:54:49 +03:00
complete : afterCall ,
allowAuthErrors : true
2016-02-01 20:14:10 +03:00
} ) ;
return deferred . promise ( ) ;
} ,
2015-01-19 13:56:04 +03: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 21:54:08 +03:00
'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 13:56:04 +03:00
} ;
for ( var header in securityHeaders ) {
2017-05-13 21:54:08 +03:00
var option = securityHeaders [ header ] [ 0 ] ;
if ( ! xhr . getResponseHeader ( header ) || xhr . getResponseHeader ( header ) . toLowerCase ( ) !== option . toLowerCase ( ) ) {
2017-11-15 04:53:47 +03: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 21:54:08 +03:00
if ( xhr . getResponseHeader ( header ) && securityHeaders [ header ] . length > 1 && xhr . getResponseHeader ( header ) . toLowerCase ( ) === securityHeaders [ header ] [ 1 ] . toLowerCase ( ) ) {
2017-11-15 04:53:47 +03: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 21:54:08 +03:00
}
2015-07-29 18:40:42 +03:00
messages . push ( {
2017-05-13 21:54:08 +03:00
msg : msg ,
2015-07-29 18:40:42 +03:00
type : OC . SetupChecks . MESSAGE _TYPE _WARNING
} ) ;
2015-01-19 13:56:04 +03:00
}
}
2018-06-02 22:29:36 +03:00
2018-10-17 16:13:52 +03:00
var xssfields = xhr . getResponseHeader ( 'X-XSS-Protection' ) ? xhr . getResponseHeader ( 'X-XSS-Protection' ) . split ( ';' ) . map ( function ( item ) { return item . trim ( ) ; } ) : [ ] ;
2018-10-17 15:28:51 +03:00
if ( xssfields . length === 0 || xssfields . indexOf ( '1' ) === - 1 || xssfields . indexOf ( 'mode=block' ) === - 1 ) {
messages . push ( {
msg : t ( 'core' , 'The "{header}" HTTP header doesn\'t contain "{expected}". This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.' ,
{
header : 'X-XSS-Protection' ,
expected : '1; mode=block'
} ) ,
type : OC . SetupChecks . MESSAGE _TYPE _WARNING
} ) ;
}
2020-02-27 01:14:38 +03:00
const referrerPolicy = xhr . getResponseHeader ( 'Referrer-Policy' )
if ( referrerPolicy === null || ! /(no-referrer(-when-downgrade)?|strict-origin(-when-cross-origin)?|same-origin)(,|$)/ . test ( referrerPolicy ) ) {
2018-06-02 22:29:36 +03:00
messages . push ( {
2021-03-01 22:09:44 +03:00
msg : t ( 'core' , 'The "{header}" HTTP header is not set to "{val1}", "{val2}", "{val3}", "{val4}" or "{val5}". This can leak referer information. See the {linkstart}W3C Recommendation ↗{linkend}.' ,
2018-06-02 22:29:36 +03:00
{
header : 'Referrer-Policy' ,
val1 : 'no-referrer' ,
val2 : 'no-referrer-when-downgrade' ,
val3 : 'strict-origin' ,
val4 : 'strict-origin-when-cross-origin' ,
2021-03-01 22:09:44 +03:00
val5 : 'same-origin'
} )
. replace ( '{linkstart}' , '<a target="_blank" rel="noreferrer noopener" class="external" href="https://www.w3.org/TR/referrer-policy/">' )
. replace ( '{linkend}' , '</a>' ) ,
2018-06-02 22:29:36 +03:00
type : OC . SetupChecks . MESSAGE _TYPE _INFO
2020-02-27 01:14:38 +03:00
} )
2018-06-02 22:29:36 +03:00
}
2015-01-19 13:56:04 +03:00
} else {
2015-07-29 18:40:42 +03:00
messages . push ( {
msg : t ( 'core' , 'Error occurred while checking server setup' ) ,
type : OC . SetupChecks . MESSAGE _TYPE _ERROR
} ) ;
2015-01-19 13:56:04 +03: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 ) {
2019-05-14 12:14:29 +03:00
var tipsUrl = OC . theme . docPlaceholderUrl . replace ( 'PLACEHOLDER' , 'admin-security' ) ;
2015-01-19 13:56:04 +03: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 11:39:25 +03:00
transportSecurityValidity = transportSecurityValidity . substring ( 8 , firstComma ) ;
2015-01-19 13:56:04 +03:00
} else {
transportSecurityValidity = transportSecurityValidity . substring ( 8 ) ;
}
}
2016-04-13 09:40:49 +03:00
var minimumSeconds = 15552000 ;
2015-06-15 11:39:25 +03:00
if ( isNaN ( transportSecurityValidity ) || transportSecurityValidity <= ( minimumSeconds - 1 ) ) {
2015-07-29 18:40:42 +03:00
messages . push ( {
2021-03-01 22:09:44 +03: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 {linkstart}security tips ↗{linkend}.' , { 'seconds' : minimumSeconds } )
. replace ( '{linkstart}' , '<a target="_blank" rel="noreferrer noopener" class="external" href="' + tipsUrl + '">' )
. replace ( '{linkend}' , '</a>' ) ,
2015-07-29 18:40:42 +03:00
type : OC . SetupChecks . MESSAGE _TYPE _WARNING
} ) ;
2015-01-19 13:56:04 +03:00
}
} else {
2015-07-29 18:40:42 +03:00
messages . push ( {
2021-03-01 22:09:44 +03:00
msg : t ( 'core' , 'Accessing site insecurely via HTTP. You are strongly advised to set up your server to require HTTPS instead, as described in the {linkstart}security tips ↗{linkend}.' )
. replace ( '{linkstart}' , '<a target="_blank" rel="noreferrer noopener" class="external" href="' + tipsUrl + '">' )
. replace ( '{linkend}' , '</a>' ) ,
2015-07-29 18:40:42 +03:00
type : OC . SetupChecks . MESSAGE _TYPE _WARNING
} ) ;
2015-01-19 13:56:04 +03:00
}
} else {
2015-07-29 18:40:42 +03:00
messages . push ( {
msg : t ( 'core' , 'Error occurred while checking server setup' ) ,
type : OC . SetupChecks . MESSAGE _TYPE _ERROR
} ) ;
2015-01-19 13:56:04 +03:00
}
return messages ;
2014-02-03 15:48:17 +04:00
}
} ;
} ) ( ) ;