You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

734 lines
32 KiB

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.
10 years ago
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.
10 years ago
  1. /*
  2. * Copyright (c) 2014
  3. *
  4. * This file is licensed under the Affero General Public License version 3
  5. * or later.
  6. *
  7. * See the COPYING-README file.
  8. *
  9. */
  10. (function() {
  11. OC.SetupChecks = {
  12. /* Message types */
  13. MESSAGE_TYPE_INFO:0,
  14. MESSAGE_TYPE_WARNING:1,
  15. MESSAGE_TYPE_ERROR:2,
  16. /**
  17. * Check whether the WebDAV connection works.
  18. *
  19. * @return $.Deferred object resolved with an array of error messages
  20. */
  21. checkWebDAV: function() {
  22. var deferred = $.Deferred();
  23. var afterCall = function(xhr) {
  24. var messages = [];
  25. if (xhr.status !== 207 && xhr.status !== 401) {
  26. messages.push({
  27. msg: t('core', 'Your web server is not yet properly set up to allow file synchronization, because the WebDAV interface seems to be broken.'),
  28. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  29. });
  30. }
  31. deferred.resolve(messages);
  32. };
  33. $.ajax({
  34. type: 'PROPFIND',
  35. url: OC.linkToRemoteBase('webdav'),
  36. data: '<?xml version="1.0"?>' +
  37. '<d:propfind xmlns:d="DAV:">' +
  38. '<d:prop><d:resourcetype/></d:prop>' +
  39. '</d:propfind>',
  40. contentType: 'application/xml; charset=utf-8',
  41. complete: afterCall,
  42. allowAuthErrors: true
  43. });
  44. return deferred.promise();
  45. },
  46. /**
  47. * Check whether the .well-known URLs works.
  48. *
  49. * @param url the URL to test
  50. * @param placeholderUrl the placeholder URL - can be found at OC.theme.docPlaceholderUrl
  51. * @param {boolean} runCheck if this is set to false the check is skipped and no error is returned
  52. * @param {int|int[]} expectedStatus the expected HTTP status to be returned by the URL, 207 by default
  53. * @return $.Deferred object resolved with an array of error messages
  54. */
  55. checkWellKnownUrl: function(verb, url, placeholderUrl, runCheck, expectedStatus, checkCustomHeader) {
  56. if (expectedStatus === undefined) {
  57. expectedStatus = [207];
  58. }
  59. if (!Array.isArray(expectedStatus)) {
  60. expectedStatus = [expectedStatus];
  61. }
  62. var deferred = $.Deferred();
  63. if(runCheck === false) {
  64. deferred.resolve([]);
  65. return deferred.promise();
  66. }
  67. var afterCall = function(xhr) {
  68. var messages = [];
  69. var customWellKnown = xhr.getResponseHeader('X-NEXTCLOUD-WELL-KNOWN')
  70. if (expectedStatus.indexOf(xhr.status) === -1 || (checkCustomHeader && !customWellKnown)) {
  71. var docUrl = placeholderUrl.replace('PLACEHOLDER', 'admin-setup-well-known-URL');
  72. messages.push({
  73. 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 }),
  74. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  75. });
  76. }
  77. deferred.resolve(messages);
  78. };
  79. $.ajax({
  80. type: verb,
  81. url: url,
  82. complete: afterCall,
  83. allowAuthErrors: true
  84. });
  85. return deferred.promise();
  86. },
  87. /**
  88. * Check whether the .well-known URLs works.
  89. *
  90. * @param url the URL to test
  91. * @param placeholderUrl the placeholder URL - can be found at OC.theme.docPlaceholderUrl
  92. * @param {boolean} runCheck if this is set to false the check is skipped and no error is returned
  93. *
  94. * @return $.Deferred object resolved with an array of error messages
  95. */
  96. checkProviderUrl: function(url, placeholderUrl, runCheck) {
  97. var expectedStatus = [200];
  98. var deferred = $.Deferred();
  99. if(runCheck === false) {
  100. deferred.resolve([]);
  101. return deferred.promise();
  102. }
  103. var afterCall = function(xhr) {
  104. var messages = [];
  105. if (expectedStatus.indexOf(xhr.status) === -1) {
  106. var docUrl = placeholderUrl.replace('PLACEHOLDER', 'admin-nginx');
  107. messages.push({
  108. 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 <a target="_blank" rel="noreferrer noopener" href="{docLink}">documentation page</a>. On Nginx those are typically the lines starting with "location ~" that need an update.', { docLink: docUrl, url: url }),
  109. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  110. });
  111. }
  112. deferred.resolve(messages);
  113. };
  114. $.ajax({
  115. type: 'GET',
  116. url: url,
  117. complete: afterCall,
  118. allowAuthErrors: true
  119. });
  120. return deferred.promise();
  121. },
  122. /**
  123. * Check whether the WOFF2 URLs works.
  124. *
  125. * @param url the URL to test
  126. * @param placeholderUrl the placeholder URL - can be found at OC.theme.docPlaceholderUrl
  127. * @return $.Deferred object resolved with an array of error messages
  128. */
  129. checkWOFF2Loading: function(url, placeholderUrl) {
  130. var deferred = $.Deferred();
  131. var afterCall = function(xhr) {
  132. var messages = [];
  133. if (xhr.status !== 200) {
  134. var docUrl = placeholderUrl.replace('PLACEHOLDER', 'admin-nginx');
  135. messages.push({
  136. 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 <a target="_blank" rel="noreferrer noopener" href="{docLink}">documentation</a>.', { docLink: docUrl, url: url }),
  137. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  138. });
  139. }
  140. deferred.resolve(messages);
  141. };
  142. $.ajax({
  143. type: 'GET',
  144. url: url,
  145. complete: afterCall,
  146. allowAuthErrors: true
  147. });
  148. return deferred.promise();
  149. },
  150. /**
  151. * Runs setup checks on the server side
  152. *
  153. * @return $.Deferred object resolved with an array of error messages
  154. */
  155. checkSetup: function() {
  156. var deferred = $.Deferred();
  157. var afterCall = function(data, statusText, xhr) {
  158. var messages = [];
  159. if (xhr.status === 200 && data) {
  160. if (!data.isGetenvServerWorking) {
  161. messages.push({
  162. 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.') + ' ' +
  163. t(
  164. 'core',
  165. 'Please check the <a target="_blank" rel="noreferrer noopener" href="{docLink}">installation documentation ↗</a> for PHP configuration notes and the PHP configuration of your server, especially when using php-fpm.',
  166. {
  167. docLink: OC.theme.docPlaceholderUrl.replace('PLACEHOLDER', 'admin-php-fpm')
  168. }
  169. ),
  170. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  171. });
  172. }
  173. if (data.isReadOnlyConfig) {
  174. messages.push({
  175. 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.'),
  176. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  177. });
  178. }
  179. if (!data.hasValidTransactionIsolationLevel) {
  180. messages.push({
  181. 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.'),
  182. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  183. });
  184. }
  185. if(!data.hasFileinfoInstalled) {
  186. messages.push({
  187. 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.'),
  188. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  189. });
  190. }
  191. if(!data.hasWorkingFileLocking) {
  192. messages.push({
  193. 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 <a target="_blank" rel="noreferrer noopener" href="{docLink}">documentation ↗</a> for more information.', {docLink: OC.theme.docPlaceholderUrl.replace('PLACEHOLDER', 'admin-transactional-locking')}),
  194. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  195. });
  196. }
  197. if (data.suggestedOverwriteCliURL !== '') {
  198. messages.push({
  199. 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}),
  200. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  201. });
  202. }
  203. if (!data.isDefaultPhoneRegionSet) {
  204. messages.push({
  205. 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.')
  206. .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">')
  207. .replace('{linkend}', '</a>'),
  208. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  209. });
  210. }
  211. if (data.cronErrors.length > 0) {
  212. var listOfCronErrors = "";
  213. data.cronErrors.forEach(function(element){
  214. listOfCronErrors += "<li>";
  215. listOfCronErrors += element.error;
  216. listOfCronErrors += ' ';
  217. listOfCronErrors += element.hint;
  218. listOfCronErrors += "</li>";
  219. });
  220. messages.push({
  221. msg: t(
  222. 'core',
  223. 'It was not possible to execute the cron job via CLI. The following technical errors have appeared:'
  224. ) + "<ul>" + listOfCronErrors + "</ul>",
  225. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  226. })
  227. }
  228. if (data.cronInfo.diffInSeconds > 3600) {
  229. messages.push({
  230. msg: t('core', 'Last background job execution ran {relativeTime}. Something seems wrong.', {relativeTime: data.cronInfo.relativeTime}) +
  231. ' <a href="' + data.cronInfo.backgroundJobsUrl + '">' + t('core', 'Check the background job settings') + '</a>',
  232. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  233. });
  234. }
  235. if (data.serverHasInternetConnectionProblems) {
  236. messages.push({
  237. 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.'),
  238. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  239. });
  240. }
  241. if(!data.isMemcacheConfigured) {
  242. messages.push({
  243. 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}),
  244. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  245. });
  246. }
  247. if(!data.isRandomnessSecure) {
  248. messages.push({
  249. 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 <a target="_blank" rel="noreferrer noopener" href="{docLink}">documentation</a>.', {docLink: data.securityDocs}),
  250. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  251. });
  252. }
  253. if(data.isUsedTlsLibOutdated) {
  254. messages.push({
  255. msg: data.isUsedTlsLibOutdated,
  256. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  257. });
  258. }
  259. if (data.phpSupported && data.phpSupported.eol) {
  260. messages.push({
  261. 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' }),
  262. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  263. })
  264. }
  265. if (data.phpSupported && data.phpSupported.version.substr(0, 3) === '7.2') {
  266. messages.push({
  267. msg: t('core', 'Nextcloud 20 is the last release supporting PHP 7.2. Nextcloud 21 requires at least PHP 7.3.'),
  268. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  269. })
  270. }
  271. if(!data.forwardedForHeadersWorking) {
  272. messages.push({
  273. 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}),
  274. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  275. });
  276. }
  277. if(!data.isCorrectMemcachedPHPModuleInstalled) {
  278. messages.push({
  279. 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'}),
  280. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  281. });
  282. }
  283. if(!data.hasPassedCodeIntegrityCheck) {
  284. messages.push({
  285. msg: t(
  286. 'core',
  287. '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>)',
  288. {
  289. docLink: data.codeIntegrityCheckerDocumentation,
  290. codeIntegrityDownloadEndpoint: OC.generateUrl('/settings/integrity/failed'),
  291. rescanEndpoint: OC.generateUrl('/settings/integrity/rescan?requesttoken={requesttoken}', {'requesttoken': OC.requestToken})
  292. }
  293. ),
  294. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  295. });
  296. }
  297. if(!data.hasOpcacheLoaded) {
  298. messages.push({
  299. msg: t(
  300. 'core',
  301. 'The PHP OPcache module is not loaded. <a target="_blank" rel="noreferrer noopener" href="{docLink}">For better performance it is recommended</a> to load it into your PHP installation.',
  302. {
  303. docLink: data.phpOpcacheDocumentation,
  304. }
  305. ),
  306. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  307. });
  308. } else if(!data.isOpcacheProperlySetup) {
  309. messages.push({
  310. msg: t(
  311. 'core',
  312. '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>:',
  313. {
  314. docLink: data.phpOpcacheDocumentation,
  315. }
  316. ) + "<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>",
  317. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  318. });
  319. }
  320. if(!data.isSettimelimitAvailable) {
  321. messages.push({
  322. msg: t(
  323. 'core',
  324. '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.'),
  325. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  326. });
  327. }
  328. if (!data.hasFreeTypeSupport) {
  329. messages.push({
  330. msg: t(
  331. 'core',
  332. 'Your PHP does not have FreeType support, resulting in breakage of profile pictures and the settings interface.'
  333. ),
  334. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  335. })
  336. }
  337. if (data.missingIndexes.length > 0) {
  338. var listOfMissingIndexes = "";
  339. data.missingIndexes.forEach(function(element){
  340. listOfMissingIndexes += "<li>";
  341. listOfMissingIndexes += t('core', 'Missing index "{indexName}" in table "{tableName}".', element);
  342. listOfMissingIndexes += "</li>";
  343. });
  344. messages.push({
  345. msg: t(
  346. 'core',
  347. '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.'
  348. ) + "<ul>" + listOfMissingIndexes + "</ul>",
  349. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  350. })
  351. }
  352. if (data.missingPrimaryKeys.length > 0) {
  353. var listOfMissingPrimaryKeys = "";
  354. data.missingPrimaryKeys.forEach(function(element){
  355. listOfMissingPrimaryKeys += "<li>";
  356. listOfMissingPrimaryKeys += t('core', 'Missing primary key on table "{tableName}".', element);
  357. listOfMissingPrimaryKeys += "</li>";
  358. });
  359. messages.push({
  360. msg: t(
  361. 'core',
  362. '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.'
  363. ) + "<ul>" + listOfMissingPrimaryKeys + "</ul>",
  364. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  365. })
  366. }
  367. if (data.missingColumns.length > 0) {
  368. var listOfMissingColumns = "";
  369. data.missingColumns.forEach(function(element){
  370. listOfMissingColumns += "<li>";
  371. listOfMissingColumns += t('core', 'Missing optional column "{columnName}" in table "{tableName}".', element);
  372. listOfMissingColumns += "</li>";
  373. });
  374. messages.push({
  375. msg: t(
  376. 'core',
  377. '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.'
  378. ) + "<ul>" + listOfMissingColumns + "</ul>",
  379. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  380. })
  381. }
  382. if (data.recommendedPHPModules.length > 0) {
  383. var listOfRecommendedPHPModules = "";
  384. data.recommendedPHPModules.forEach(function(element){
  385. listOfRecommendedPHPModules += "<li>" + element + "</li>";
  386. });
  387. messages.push({
  388. msg: t(
  389. 'core',
  390. 'This instance is missing some recommended PHP modules. For improved performance and better compatibility it is highly recommended to install them.'
  391. ) + "<ul><code>" + listOfRecommendedPHPModules + "</code></ul>",
  392. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  393. })
  394. }
  395. if (data.imageMagickLacksSVGSupport) {
  396. messages.push({
  397. msg: t(
  398. 'core',
  399. 'Module php-imagick in this instance has no SVG support. For better compatibility it is recommended to install it.'
  400. ),
  401. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  402. })
  403. }
  404. if (data.pendingBigIntConversionColumns.length > 0) {
  405. var listOfPendingBigIntConversionColumns = "";
  406. data.pendingBigIntConversionColumns.forEach(function(element){
  407. listOfPendingBigIntConversionColumns += "<li>" + element + "</li>";
  408. });
  409. messages.push({
  410. msg: t(
  411. 'core',
  412. '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 <a target="_blank" rel="noreferrer noopener" href="{docLink}">the documentation page about this</a>.',
  413. {
  414. docLink: OC.theme.docPlaceholderUrl.replace('PLACEHOLDER', 'admin-bigint-conversion'),
  415. }
  416. ) + "<ul>" + listOfPendingBigIntConversionColumns + "</ul>",
  417. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  418. })
  419. }
  420. if (data.isSqliteUsed) {
  421. messages.push({
  422. msg: t(
  423. 'core',
  424. 'SQLite is currently being used as the backend database. For larger installations we recommend that you switch to a different database backend.'
  425. ) + ' ' + t('core', 'This is particularly recommended when using the desktop client for file synchronisation.') + ' ' +
  426. t(
  427. 'core',
  428. 'To migrate to another database use the command line tool: \'occ db:convert-type\', or see the <a target="_blank" rel="noreferrer noopener" href="{docLink}">documentation ↗</a>.',
  429. {
  430. docLink: data.databaseConversionDocumentation,
  431. }
  432. ),
  433. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  434. })
  435. }
  436. if (!data.isMemoryLimitSufficient) {
  437. messages.push({
  438. msg: t(
  439. 'core',
  440. 'The PHP memory limit is below the recommended value of 512MB.'
  441. ),
  442. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  443. })
  444. }
  445. if(data.appDirsWithDifferentOwner && data.appDirsWithDifferentOwner.length > 0) {
  446. var appDirsWithDifferentOwner = data.appDirsWithDifferentOwner.reduce(
  447. function(appDirsWithDifferentOwner, directory) {
  448. return appDirsWithDifferentOwner + '<li>' + directory + '</li>';
  449. },
  450. ''
  451. );
  452. messages.push({
  453. msg: t('core', 'Some app directories are owned by a different user than the web server one. ' +
  454. 'This may be the case if apps have been installed manually. ' +
  455. 'Check the permissions of the following app directories:')
  456. + '<ul>' + appDirsWithDifferentOwner + '</ul>',
  457. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  458. });
  459. }
  460. if (data.isMysqlUsedWithoutUTF8MB4) {
  461. messages.push({
  462. msg: t(
  463. 'core',
  464. '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 <a target="_blank" rel="noreferrer noopener" href="{docLink}">the documentation page about this</a>.',
  465. {
  466. docLink: OC.theme.docPlaceholderUrl.replace('PLACEHOLDER', 'admin-mysql-utf8mb4'),
  467. }
  468. ),
  469. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  470. })
  471. }
  472. if (!data.isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed) {
  473. messages.push({
  474. msg: t(
  475. 'core',
  476. '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.'
  477. ),
  478. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  479. })
  480. }
  481. if (window.location.protocol === 'http:' && data.reverseProxyGeneratedURL.split('/')[0] !== 'https:') {
  482. messages.push({
  483. msg: t(
  484. 'core',
  485. '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 <a target="_blank" rel="noreferrer noopener" href="{docLink}">the documentation page about this</a>.',
  486. {
  487. docLink: data.reverseProxyDocs
  488. }
  489. ),
  490. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  491. })
  492. }
  493. OC.SetupChecks.addGenericSetupCheck(data, 'OCA\\Settings\\SetupChecks\\PhpDefaultCharset', messages)
  494. OC.SetupChecks.addGenericSetupCheck(data, 'OCA\\Settings\\SetupChecks\\PhpOutputBuffering', messages)
  495. OC.SetupChecks.addGenericSetupCheck(data, 'OCA\\Settings\\SetupChecks\\LegacySSEKeyFormat', messages)
  496. OC.SetupChecks.addGenericSetupCheck(data, 'OCA\\Settings\\SetupChecks\\CheckUserCertificates', messages)
  497. OC.SetupChecks.addGenericSetupCheck(data, 'OCA\\Settings\\SetupChecks\\SupportedDatabase', messages)
  498. } else {
  499. messages.push({
  500. msg: t('core', 'Error occurred while checking server setup'),
  501. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  502. });
  503. }
  504. deferred.resolve(messages);
  505. };
  506. $.ajax({
  507. type: 'GET',
  508. url: OC.generateUrl('settings/ajax/checksetup'),
  509. allowAuthErrors: true
  510. }).then(afterCall, afterCall);
  511. return deferred.promise();
  512. },
  513. addGenericSetupCheck: function(data, check, messages) {
  514. var setupCheck = data[check] || { pass: true, description: '', severity: 'info', linkToDocumentation: null}
  515. var type = OC.SetupChecks.MESSAGE_TYPE_INFO
  516. if (setupCheck.severity === 'warning') {
  517. type = OC.SetupChecks.MESSAGE_TYPE_WARNING
  518. } else if (setupCheck.severity === 'error') {
  519. type = OC.SetupChecks.MESSAGE_TYPE_ERROR
  520. }
  521. var message = setupCheck.description;
  522. if (setupCheck.linkToDocumentation) {
  523. message += ' ' + t('core', 'For more details see the <a target="_blank" rel="noreferrer noopener" href="{docLink}">documentation</a>.', {docLink: setupCheck.linkToDocumentation});
  524. }
  525. if (setupCheck.elements) {
  526. message += '<br><ul>'
  527. setupCheck.elements.forEach(function(element){
  528. message += '<li>';
  529. message += element
  530. message += '</li>';
  531. });
  532. message += '</ul>'
  533. }
  534. if (!setupCheck.pass) {
  535. messages.push({
  536. msg: message,
  537. type: type,
  538. })
  539. }
  540. },
  541. /**
  542. * Runs generic checks on the server side, the difference to dedicated
  543. * methods is that we use the same XHR object for all checks to save
  544. * requests.
  545. *
  546. * @return $.Deferred object resolved with an array of error messages
  547. */
  548. checkGeneric: function() {
  549. var self = this;
  550. var deferred = $.Deferred();
  551. var afterCall = function(data, statusText, xhr) {
  552. var messages = [];
  553. messages = messages.concat(self._checkSecurityHeaders(xhr));
  554. messages = messages.concat(self._checkSSL(xhr));
  555. deferred.resolve(messages);
  556. };
  557. $.ajax({
  558. type: 'GET',
  559. url: OC.generateUrl('heartbeat'),
  560. allowAuthErrors: true
  561. }).then(afterCall, afterCall);
  562. return deferred.promise();
  563. },
  564. checkDataProtected: function() {
  565. var deferred = $.Deferred();
  566. if(oc_dataURL === false){
  567. return deferred.resolve([]);
  568. }
  569. var afterCall = function(xhr) {
  570. var messages = [];
  571. // .ocdata is an empty file in the data directory - if this is readable then the data dir is not protected
  572. if (xhr.status === 200 && xhr.responseText === '') {
  573. messages.push({
  574. 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.'),
  575. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  576. });
  577. }
  578. deferred.resolve(messages);
  579. };
  580. $.ajax({
  581. type: 'GET',
  582. url: OC.linkTo('', oc_dataURL+'/.ocdata?t=' + (new Date()).getTime()),
  583. complete: afterCall,
  584. allowAuthErrors: true
  585. });
  586. return deferred.promise();
  587. },
  588. /**
  589. * Runs check for some generic security headers on the server side
  590. *
  591. * @param {Object} xhr
  592. * @return {Array} Array with error messages
  593. */
  594. _checkSecurityHeaders: function(xhr) {
  595. var messages = [];
  596. if (xhr.status === 200) {
  597. var securityHeaders = {
  598. 'X-Content-Type-Options': ['nosniff'],
  599. 'X-Robots-Tag': ['none'],
  600. 'X-Frame-Options': ['SAMEORIGIN', 'DENY'],
  601. 'X-Download-Options': ['noopen'],
  602. 'X-Permitted-Cross-Domain-Policies': ['none'],
  603. };
  604. for (var header in securityHeaders) {
  605. var option = securityHeaders[header][0];
  606. if(!xhr.getResponseHeader(header) || xhr.getResponseHeader(header).toLowerCase() !== option.toLowerCase()) {
  607. 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});
  608. if(xhr.getResponseHeader(header) && securityHeaders[header].length > 1 && xhr.getResponseHeader(header).toLowerCase() === securityHeaders[header][1].toLowerCase()) {
  609. 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});
  610. }
  611. messages.push({
  612. msg: msg,
  613. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  614. });
  615. }
  616. }
  617. var xssfields = xhr.getResponseHeader('X-XSS-Protection') ? xhr.getResponseHeader('X-XSS-Protection').split(';').map(function(item) { return item.trim(); }) : [];
  618. if (xssfields.length === 0 || xssfields.indexOf('1') === -1 || xssfields.indexOf('mode=block') === -1) {
  619. messages.push({
  620. 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.',
  621. {
  622. header: 'X-XSS-Protection',
  623. expected: '1; mode=block'
  624. }),
  625. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  626. });
  627. }
  628. const referrerPolicy = xhr.getResponseHeader('Referrer-Policy')
  629. if (referrerPolicy === null || !/(no-referrer(-when-downgrade)?|strict-origin(-when-cross-origin)?|same-origin)(,|$)/.test(referrerPolicy)) {
  630. messages.push({
  631. msg: t('core', 'The "{header}" HTTP header is not set to "{val1}", "{val2}", "{val3}", "{val4}" or "{val5}". This can leak referer information. See the <a target="_blank" rel="noreferrer noopener" href="{link}">W3C Recommendation ↗</a>.',
  632. {
  633. header: 'Referrer-Policy',
  634. val1: 'no-referrer',
  635. val2: 'no-referrer-when-downgrade',
  636. val3: 'strict-origin',
  637. val4: 'strict-origin-when-cross-origin',
  638. val5: 'same-origin',
  639. link: 'https://www.w3.org/TR/referrer-policy/'
  640. }),
  641. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  642. })
  643. }
  644. } else {
  645. messages.push({
  646. msg: t('core', 'Error occurred while checking server setup'),
  647. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  648. });
  649. }
  650. return messages;
  651. },
  652. /**
  653. * Runs check for some SSL configuration issues on the server side
  654. *
  655. * @param {Object} xhr
  656. * @return {Array} Array with error messages
  657. */
  658. _checkSSL: function(xhr) {
  659. var messages = [];
  660. if (xhr.status === 200) {
  661. var tipsUrl = OC.theme.docPlaceholderUrl.replace('PLACEHOLDER', 'admin-security');
  662. if(OC.getProtocol() === 'https') {
  663. // Extract the value of 'Strict-Transport-Security'
  664. var transportSecurityValidity = xhr.getResponseHeader('Strict-Transport-Security');
  665. if(transportSecurityValidity !== null && transportSecurityValidity.length > 8) {
  666. var firstComma = transportSecurityValidity.indexOf(";");
  667. if(firstComma !== -1) {
  668. transportSecurityValidity = transportSecurityValidity.substring(8, firstComma);
  669. } else {
  670. transportSecurityValidity = transportSecurityValidity.substring(8);
  671. }
  672. }
  673. var minimumSeconds = 15552000;
  674. if(isNaN(transportSecurityValidity) || transportSecurityValidity <= (minimumSeconds - 1)) {
  675. messages.push({
  676. 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}),
  677. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  678. });
  679. }
  680. } else {
  681. messages.push({
  682. 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 <a href="{docUrl}">security tips ↗</a>.', {docUrl: tipsUrl}),
  683. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  684. });
  685. }
  686. } else {
  687. messages.push({
  688. msg: t('core', 'Error occurred while checking server setup'),
  689. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  690. });
  691. }
  692. return messages;
  693. }
  694. };
  695. })();