setupchecks.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  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 {linkstart}documentation ↗{linkend}.', { url: url })
  74. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + docUrl + '">')
  75. .replace('{linkend}', '</a>'),
  76. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  77. });
  78. }
  79. deferred.resolve(messages);
  80. };
  81. $.ajax({
  82. type: verb,
  83. url: url,
  84. complete: afterCall,
  85. allowAuthErrors: true
  86. });
  87. return deferred.promise();
  88. },
  89. /**
  90. * Check whether the .well-known URLs works.
  91. *
  92. * @param url the URL to test
  93. * @param placeholderUrl the placeholder URL - can be found at OC.theme.docPlaceholderUrl
  94. * @param {boolean} runCheck if this is set to false the check is skipped and no error is returned
  95. *
  96. * @return $.Deferred object resolved with an array of error messages
  97. */
  98. checkProviderUrl: function(url, placeholderUrl, runCheck) {
  99. var expectedStatus = [200];
  100. var deferred = $.Deferred();
  101. if(runCheck === false) {
  102. deferred.resolve([]);
  103. return deferred.promise();
  104. }
  105. var afterCall = function(xhr) {
  106. var messages = [];
  107. if (expectedStatus.indexOf(xhr.status) === -1) {
  108. var docUrl = placeholderUrl.replace('PLACEHOLDER', 'admin-nginx');
  109. messages.push({
  110. 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 })
  111. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + docUrl + '">')
  112. .replace('{linkend}', '</a>'),
  113. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  114. });
  115. }
  116. deferred.resolve(messages);
  117. };
  118. $.ajax({
  119. type: 'GET',
  120. url: url,
  121. complete: afterCall,
  122. allowAuthErrors: true
  123. });
  124. return deferred.promise();
  125. },
  126. /**
  127. * Check whether the WOFF2 URLs works.
  128. *
  129. * @param url the URL to test
  130. * @param placeholderUrl the placeholder URL - can be found at OC.theme.docPlaceholderUrl
  131. * @return $.Deferred object resolved with an array of error messages
  132. */
  133. checkWOFF2Loading: function(url, placeholderUrl) {
  134. var deferred = $.Deferred();
  135. var afterCall = function(xhr) {
  136. var messages = [];
  137. if (xhr.status !== 200) {
  138. var docUrl = placeholderUrl.replace('PLACEHOLDER', 'admin-nginx');
  139. messages.push({
  140. 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 })
  141. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + docUrl + '">')
  142. .replace('{linkend}', '</a>'),
  143. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  144. });
  145. }
  146. deferred.resolve(messages);
  147. };
  148. $.ajax({
  149. type: 'GET',
  150. url: url,
  151. complete: afterCall,
  152. allowAuthErrors: true
  153. });
  154. return deferred.promise();
  155. },
  156. /**
  157. * Runs setup checks on the server side
  158. *
  159. * @return $.Deferred object resolved with an array of error messages
  160. */
  161. checkSetup: function() {
  162. var deferred = $.Deferred();
  163. var afterCall = function(data, statusText, xhr) {
  164. var messages = [];
  165. if (xhr.status === 200 && data) {
  166. if (data.suggestedOverwriteCliURL !== '') {
  167. messages.push({
  168. msg: t('core', 'Please make sure to set the "overwrite.cli.url" option in your config.php file to the URL that your users mainly use to access this Nextcloud. Suggestion: "{suggestedOverwriteCliURL}". Otherwise there might be problems with the URL generation via cron. (It is possible though that the suggested URL is not the URL that your users mainly use to access this Nextcloud. Best is to double check this in any case.)', {suggestedOverwriteCliURL: data.suggestedOverwriteCliURL}),
  169. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  170. });
  171. }
  172. if (data.cronErrors.length > 0) {
  173. var listOfCronErrors = "";
  174. data.cronErrors.forEach(function(element){
  175. listOfCronErrors += '<li>';
  176. listOfCronErrors += element.error;
  177. listOfCronErrors += ' ';
  178. listOfCronErrors += element.hint;
  179. listOfCronErrors += '</li>';
  180. });
  181. messages.push({
  182. msg: t('core', 'It was not possible to execute the cron job via CLI. The following technical errors have appeared:') + '<ul>' + listOfCronErrors + '</ul>',
  183. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  184. })
  185. }
  186. if (data.cronInfo.diffInSeconds > 3600) {
  187. messages.push({
  188. msg: t('core', 'Last background job execution ran {relativeTime}. Something seems wrong. {linkstart}Check the background job settings ↗{linkend}.', {relativeTime: data.cronInfo.relativeTime})
  189. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + data.cronInfo.backgroundJobsUrl + '">')
  190. .replace('{linkend}', '</a>'),
  191. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  192. });
  193. }
  194. if (!data.isFairUseOfFreePushService) {
  195. messages.push({
  196. msg: t('core', 'This is the unsupported community build of Nextcloud. Given the size of this instance, performance, reliability and scalability cannot be guaranteed. Push notifications are limited to avoid overloading our free service. Learn more about the benefits of Nextcloud Enterprise at {linkstart}https://nextcloud.com/enterprise{linkend}.')
  197. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="https://nextcloud.com/enterprise">')
  198. .replace('{linkend}', '</a>'),
  199. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  200. });
  201. }
  202. if(data.isUsedTlsLibOutdated) {
  203. messages.push({
  204. msg: data.isUsedTlsLibOutdated,
  205. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  206. });
  207. }
  208. if(!data.isCorrectMemcachedPHPModuleInstalled) {
  209. messages.push({
  210. 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}.')
  211. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="https://code.google.com/p/memcached/wiki/PHPClientComparison">')
  212. .replace('{linkend}', '</a>'),
  213. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  214. });
  215. }
  216. if(!data.hasPassedCodeIntegrityCheck) {
  217. messages.push({
  218. 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})')
  219. .replace('{linkstart1}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + data.codeIntegrityCheckerDocumentation + '">')
  220. .replace('{linkstart2}', '<a href="' + OC.generateUrl('/settings/integrity/failed') + '">')
  221. .replace('{linkstart3}', '<a href="' + OC.generateUrl('/settings/integrity/rescan?requesttoken={requesttoken}', {'requesttoken': OC.requestToken}) + '">')
  222. .replace(/{linkend}/g, '</a>'),
  223. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  224. });
  225. }
  226. if(data.OpcacheSetupRecommendations.length > 0) {
  227. var listOfOPcacheRecommendations = "";
  228. data.OpcacheSetupRecommendations.forEach(function(element){
  229. listOfOPcacheRecommendations += '<li>' + element + '</li>';
  230. });
  231. messages.push({
  232. msg: t('core', 'The PHP OPcache module is not properly configured. See the {linkstart}documentation ↗{linkend} for more information.')
  233. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + OC.theme.docPlaceholderUrl.replace('PLACEHOLDER', 'admin-php-opcache') + '">')
  234. .replace('{linkend}', '</a>') + '<ul>' + listOfOPcacheRecommendations + '</ul>',
  235. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  236. });
  237. }
  238. if(!data.isSettimelimitAvailable) {
  239. messages.push({
  240. msg: t('core', '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.'),
  241. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  242. });
  243. }
  244. if (!data.isImagickEnabled) {
  245. messages.push({
  246. msg: t(
  247. 'core',
  248. 'The PHP module "imagick" is not enabled although the theming app is. For favicon generation to work correctly, you need to install and enable this module.'
  249. ),
  250. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  251. })
  252. }
  253. if (!data.areWebauthnExtensionsEnabled) {
  254. messages.push({
  255. msg: t(
  256. 'core',
  257. 'The PHP modules "gmp" and/or "bcmath" are not enabled. If you use WebAuthn passwordless authentication, these modules are required.'
  258. ),
  259. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  260. })
  261. }
  262. if (data.imageMagickLacksSVGSupport) {
  263. messages.push({
  264. msg: t('core', 'Module php-imagick in this instance has no SVG support. For better compatibility it is recommended to install it.'),
  265. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  266. })
  267. }
  268. if(data.appDirsWithDifferentOwner && data.appDirsWithDifferentOwner.length > 0) {
  269. var appDirsWithDifferentOwner = data.appDirsWithDifferentOwner.reduce(
  270. function(appDirsWithDifferentOwner, directory) {
  271. return appDirsWithDifferentOwner + '<li>' + directory + '</li>';
  272. },
  273. ''
  274. );
  275. messages.push({
  276. msg: t('core', 'Some app directories are owned by a different user than the web server one. ' +
  277. 'This may be the case if apps have been installed manually. ' +
  278. 'Check the permissions of the following app directories:')
  279. + '<ul>' + appDirsWithDifferentOwner + '</ul>',
  280. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  281. });
  282. }
  283. if (data.isMysqlUsedWithoutUTF8MB4) {
  284. messages.push({
  285. 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}.')
  286. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + OC.theme.docPlaceholderUrl.replace('PLACEHOLDER', 'admin-mysql-utf8mb4') + '">')
  287. .replace('{linkend}', '</a>'),
  288. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  289. })
  290. }
  291. if (!data.isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed) {
  292. messages.push({
  293. msg: t('core', '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.'),
  294. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  295. })
  296. }
  297. if (!data.temporaryDirectoryWritable) {
  298. messages.push({
  299. msg: t('core', 'The temporary directory of this instance points to an either non-existing or non-writable directory.'),
  300. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  301. })
  302. }
  303. if (window.location.protocol === 'https:' && data.reverseProxyGeneratedURL.split('/')[0] !== 'https:') {
  304. messages.push({
  305. 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}.')
  306. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + data.reverseProxyDocs + '">')
  307. .replace('{linkend}', '</a>'),
  308. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  309. })
  310. }
  311. if (window.oc_debug) {
  312. messages.push({
  313. msg: t('core', 'This instance is running in debug mode. Only enable this for local development and not in production environments.'),
  314. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  315. })
  316. }
  317. if (Object.keys(data.generic).length > 0) {
  318. Object.keys(data.generic).forEach(function(key){
  319. Object.keys(data.generic[key]).forEach(function(title){
  320. if (data.generic[key][title].severity != 'success') {
  321. data.generic[key][title].pass = false;
  322. OC.SetupChecks.addGenericSetupCheck(data.generic[key], title, messages);
  323. }
  324. });
  325. });
  326. }
  327. } else {
  328. messages.push({
  329. msg: t('core', 'Error occurred while checking server setup'),
  330. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  331. });
  332. }
  333. deferred.resolve(messages);
  334. };
  335. $.ajax({
  336. type: 'GET',
  337. url: OC.generateUrl('settings/ajax/checksetup'),
  338. allowAuthErrors: true
  339. }).then(afterCall, afterCall);
  340. return deferred.promise();
  341. },
  342. addGenericSetupCheck: function(data, check, messages) {
  343. var setupCheck = data[check] || { pass: true, description: '', severity: 'info', linkToDoc: null}
  344. var type = OC.SetupChecks.MESSAGE_TYPE_INFO
  345. if (setupCheck.severity === 'warning') {
  346. type = OC.SetupChecks.MESSAGE_TYPE_WARNING
  347. } else if (setupCheck.severity === 'error') {
  348. type = OC.SetupChecks.MESSAGE_TYPE_ERROR
  349. }
  350. var message = setupCheck.description;
  351. if (setupCheck.linkToDoc) {
  352. message += ' ' + t('core', 'For more details see the {linkstart}documentation ↗{linkend}.')
  353. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + setupCheck.linkToDoc + '">')
  354. .replace('{linkend}', '</a>');
  355. }
  356. if (setupCheck.elements) {
  357. message += '<br><ul>'
  358. setupCheck.elements.forEach(function(element){
  359. message += '<li>';
  360. message += element
  361. message += '</li>';
  362. });
  363. message += '</ul>'
  364. }
  365. if (!setupCheck.pass) {
  366. messages.push({
  367. msg: message,
  368. type: type,
  369. })
  370. }
  371. },
  372. /**
  373. * Runs generic checks on the server side, the difference to dedicated
  374. * methods is that we use the same XHR object for all checks to save
  375. * requests.
  376. *
  377. * @return $.Deferred object resolved with an array of error messages
  378. */
  379. checkGeneric: function() {
  380. var self = this;
  381. var deferred = $.Deferred();
  382. var afterCall = function(data, statusText, xhr) {
  383. var messages = [];
  384. messages = messages.concat(self._checkSecurityHeaders(xhr));
  385. messages = messages.concat(self._checkSSL(xhr));
  386. deferred.resolve(messages);
  387. };
  388. $.ajax({
  389. type: 'GET',
  390. url: OC.generateUrl('heartbeat'),
  391. allowAuthErrors: true
  392. }).then(afterCall, afterCall);
  393. return deferred.promise();
  394. },
  395. checkDataProtected: function() {
  396. var deferred = $.Deferred();
  397. if(oc_dataURL === false){
  398. return deferred.resolve([]);
  399. }
  400. var afterCall = function(xhr) {
  401. var messages = [];
  402. // .ocdata is an empty file in the data directory - if this is readable then the data dir is not protected
  403. if (xhr.status === 200 && xhr.responseText === '') {
  404. messages.push({
  405. 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.'),
  406. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  407. });
  408. }
  409. deferred.resolve(messages);
  410. };
  411. $.ajax({
  412. type: 'GET',
  413. url: OC.linkTo('', oc_dataURL+'/.ocdata?t=' + (new Date()).getTime()),
  414. complete: afterCall,
  415. allowAuthErrors: true
  416. });
  417. return deferred.promise();
  418. },
  419. /**
  420. * Runs check for some generic security headers on the server side
  421. *
  422. * @param {Object} xhr
  423. * @return {Array} Array with error messages
  424. */
  425. _checkSecurityHeaders: function(xhr) {
  426. var messages = [];
  427. if (xhr.status === 200) {
  428. var securityHeaders = {
  429. 'X-Content-Type-Options': ['nosniff'],
  430. 'X-Robots-Tag': ['noindex, nofollow'],
  431. 'X-Frame-Options': ['SAMEORIGIN', 'DENY'],
  432. 'X-Permitted-Cross-Domain-Policies': ['none'],
  433. };
  434. for (var header in securityHeaders) {
  435. var option = securityHeaders[header][0];
  436. if(!xhr.getResponseHeader(header) || xhr.getResponseHeader(header).replace(/, /, ',').toLowerCase() !== option.replace(/, /, ',').toLowerCase()) {
  437. 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});
  438. if(xhr.getResponseHeader(header) && securityHeaders[header].length > 1 && xhr.getResponseHeader(header).toLowerCase() === securityHeaders[header][1].toLowerCase()) {
  439. 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});
  440. }
  441. messages.push({
  442. msg: msg,
  443. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  444. });
  445. }
  446. }
  447. var xssfields = xhr.getResponseHeader('X-XSS-Protection') ? xhr.getResponseHeader('X-XSS-Protection').split(';').map(function(item) { return item.trim(); }) : [];
  448. if (xssfields.length === 0 || xssfields.indexOf('1') === -1 || xssfields.indexOf('mode=block') === -1) {
  449. messages.push({
  450. msg: t('core', 'The "{header}" HTTP header does not contain "{expected}". This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.',
  451. {
  452. header: 'X-XSS-Protection',
  453. expected: '1; mode=block'
  454. }),
  455. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  456. });
  457. }
  458. const referrerPolicy = xhr.getResponseHeader('Referrer-Policy')
  459. if (referrerPolicy === null || !/(no-referrer(-when-downgrade)?|strict-origin(-when-cross-origin)?|same-origin)(,|$)/.test(referrerPolicy)) {
  460. messages.push({
  461. 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}.',
  462. {
  463. header: 'Referrer-Policy',
  464. val1: 'no-referrer',
  465. val2: 'no-referrer-when-downgrade',
  466. val3: 'strict-origin',
  467. val4: 'strict-origin-when-cross-origin',
  468. val5: 'same-origin'
  469. })
  470. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="https://www.w3.org/TR/referrer-policy/">')
  471. .replace('{linkend}', '</a>'),
  472. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  473. })
  474. }
  475. } else {
  476. messages.push({
  477. msg: t('core', 'Error occurred while checking server setup'),
  478. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  479. });
  480. }
  481. return messages;
  482. },
  483. /**
  484. * Runs check for some SSL configuration issues on the server side
  485. *
  486. * @param {Object} xhr
  487. * @return {Array} Array with error messages
  488. */
  489. _checkSSL: function(xhr) {
  490. var messages = [];
  491. if (xhr.status === 200) {
  492. var tipsUrl = OC.theme.docPlaceholderUrl.replace('PLACEHOLDER', 'admin-security');
  493. if(OC.getProtocol() === 'https') {
  494. // Extract the value of 'Strict-Transport-Security'
  495. var transportSecurityValidity = xhr.getResponseHeader('Strict-Transport-Security');
  496. if(transportSecurityValidity !== null && transportSecurityValidity.length > 8) {
  497. var firstComma = transportSecurityValidity.indexOf(";");
  498. if(firstComma !== -1) {
  499. transportSecurityValidity = transportSecurityValidity.substring(8, firstComma);
  500. } else {
  501. transportSecurityValidity = transportSecurityValidity.substring(8);
  502. }
  503. }
  504. var minimumSeconds = 15552000;
  505. if(isNaN(transportSecurityValidity) || transportSecurityValidity <= (minimumSeconds - 1)) {
  506. messages.push({
  507. 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})
  508. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + tipsUrl + '">')
  509. .replace('{linkend}', '</a>'),
  510. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  511. });
  512. }
  513. } else if (!/(?:^(?:localhost|127\.0\.0\.1|::1)|\.onion)$/.exec(window.location.hostname)) {
  514. messages.push({
  515. 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}. Without it some important web functionality like "copy to clipboard" or "service workers" will not work!')
  516. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + tipsUrl + '">')
  517. .replace('{linkend}', '</a>'),
  518. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  519. });
  520. }
  521. } else {
  522. messages.push({
  523. msg: t('core', 'Error occurred while checking server setup'),
  524. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  525. });
  526. }
  527. return messages;
  528. }
  529. };
  530. })();