setupchecks.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  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.isSettimelimitAvailable) {
  227. messages.push({
  228. 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.'),
  229. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  230. });
  231. }
  232. if (!data.areWebauthnExtensionsEnabled) {
  233. messages.push({
  234. msg: t(
  235. 'core',
  236. 'The PHP modules "gmp" and/or "bcmath" are not enabled. If you use WebAuthn passwordless authentication, these modules are required.'
  237. ),
  238. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  239. })
  240. }
  241. if (data.isMysqlUsedWithoutUTF8MB4) {
  242. messages.push({
  243. 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}.')
  244. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + OC.theme.docPlaceholderUrl.replace('PLACEHOLDER', 'admin-mysql-utf8mb4') + '">')
  245. .replace('{linkend}', '</a>'),
  246. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  247. })
  248. }
  249. if (!data.isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed) {
  250. messages.push({
  251. 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.'),
  252. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  253. })
  254. }
  255. if (!data.temporaryDirectoryWritable) {
  256. messages.push({
  257. msg: t('core', 'The temporary directory of this instance points to an either non-existing or non-writable directory.'),
  258. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  259. })
  260. }
  261. if (window.location.protocol === 'https:' && data.reverseProxyGeneratedURL.split('/')[0] !== 'https:') {
  262. messages.push({
  263. 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}.')
  264. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + data.reverseProxyDocs + '">')
  265. .replace('{linkend}', '</a>'),
  266. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  267. })
  268. }
  269. if (window.oc_debug) {
  270. messages.push({
  271. msg: t('core', 'This instance is running in debug mode. Only enable this for local development and not in production environments.'),
  272. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  273. })
  274. }
  275. if (Object.keys(data.generic).length > 0) {
  276. Object.keys(data.generic).forEach(function(key){
  277. Object.keys(data.generic[key]).forEach(function(title){
  278. if (data.generic[key][title].severity != 'success') {
  279. data.generic[key][title].pass = false;
  280. OC.SetupChecks.addGenericSetupCheck(data.generic[key], title, messages);
  281. }
  282. });
  283. });
  284. }
  285. } else {
  286. messages.push({
  287. msg: t('core', 'Error occurred while checking server setup'),
  288. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  289. });
  290. }
  291. deferred.resolve(messages);
  292. };
  293. $.ajax({
  294. type: 'GET',
  295. url: OC.generateUrl('settings/ajax/checksetup'),
  296. allowAuthErrors: true
  297. }).then(afterCall, afterCall);
  298. return deferred.promise();
  299. },
  300. /**
  301. * @param message The message string containing placeholders.
  302. * @param parameters An object with keys as placeholders and values as their replacements.
  303. *
  304. * @return The message with placeholders replaced by values.
  305. */
  306. richToParsed: function (message, parameters) {
  307. for (var [placeholder, parameter] of Object.entries(parameters)) {
  308. var replacement;
  309. if (parameter.type === 'user') {
  310. replacement = '@' + parameter.name;
  311. } else if (parameter.type === 'file') {
  312. replacement = parameter.path || parameter.name;
  313. } else {
  314. replacement = parameter.name;
  315. }
  316. message = message.replace('{' + placeholder + '}', replacement);
  317. }
  318. return message;
  319. },
  320. addGenericSetupCheck: function(data, check, messages) {
  321. var setupCheck = data[check] || { pass: true, description: '', severity: 'info', linkToDoc: null}
  322. var type = OC.SetupChecks.MESSAGE_TYPE_INFO
  323. if (setupCheck.severity === 'warning') {
  324. type = OC.SetupChecks.MESSAGE_TYPE_WARNING
  325. } else if (setupCheck.severity === 'error') {
  326. type = OC.SetupChecks.MESSAGE_TYPE_ERROR
  327. }
  328. var message = setupCheck.description;
  329. if (setupCheck.descriptionParameters) {
  330. message = this.richToParsed(message, setupCheck.descriptionParameters);
  331. }
  332. if (setupCheck.linkToDoc) {
  333. message += ' ' + t('core', 'For more details see the {linkstart}documentation ↗{linkend}.')
  334. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + setupCheck.linkToDoc + '">')
  335. .replace('{linkend}', '</a>');
  336. }
  337. if (setupCheck.elements) {
  338. message += '<br><ul>'
  339. setupCheck.elements.forEach(function(element){
  340. message += '<li>';
  341. message += element
  342. message += '</li>';
  343. });
  344. message += '</ul>'
  345. }
  346. if (!setupCheck.pass) {
  347. messages.push({
  348. msg: message,
  349. type: type,
  350. })
  351. }
  352. },
  353. /**
  354. * Runs generic checks on the server side, the difference to dedicated
  355. * methods is that we use the same XHR object for all checks to save
  356. * requests.
  357. *
  358. * @return $.Deferred object resolved with an array of error messages
  359. */
  360. checkGeneric: function() {
  361. var self = this;
  362. var deferred = $.Deferred();
  363. var afterCall = function(data, statusText, xhr) {
  364. var messages = [];
  365. messages = messages.concat(self._checkSecurityHeaders(xhr));
  366. messages = messages.concat(self._checkSSL(xhr));
  367. deferred.resolve(messages);
  368. };
  369. $.ajax({
  370. type: 'GET',
  371. url: OC.generateUrl('heartbeat'),
  372. allowAuthErrors: true
  373. }).then(afterCall, afterCall);
  374. return deferred.promise();
  375. },
  376. checkDataProtected: function() {
  377. var deferred = $.Deferred();
  378. if(oc_dataURL === false){
  379. return deferred.resolve([]);
  380. }
  381. var afterCall = function(xhr) {
  382. var messages = [];
  383. // .ocdata is an empty file in the data directory - if this is readable then the data dir is not protected
  384. if (xhr.status === 200 && xhr.responseText === '') {
  385. messages.push({
  386. 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.'),
  387. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  388. });
  389. }
  390. deferred.resolve(messages);
  391. };
  392. $.ajax({
  393. type: 'GET',
  394. url: OC.linkTo('', oc_dataURL+'/.ocdata?t=' + (new Date()).getTime()),
  395. complete: afterCall,
  396. allowAuthErrors: true
  397. });
  398. return deferred.promise();
  399. },
  400. /**
  401. * Runs check for some generic security headers on the server side
  402. *
  403. * @param {Object} xhr
  404. * @return {Array} Array with error messages
  405. */
  406. _checkSecurityHeaders: function(xhr) {
  407. var messages = [];
  408. if (xhr.status === 200) {
  409. var securityHeaders = {
  410. 'X-Content-Type-Options': ['nosniff'],
  411. 'X-Robots-Tag': ['noindex, nofollow'],
  412. 'X-Frame-Options': ['SAMEORIGIN', 'DENY'],
  413. 'X-Permitted-Cross-Domain-Policies': ['none'],
  414. };
  415. for (var header in securityHeaders) {
  416. var option = securityHeaders[header][0];
  417. if(!xhr.getResponseHeader(header) || xhr.getResponseHeader(header).replace(/, /, ',').toLowerCase() !== option.replace(/, /, ',').toLowerCase()) {
  418. 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});
  419. if(xhr.getResponseHeader(header) && securityHeaders[header].length > 1 && xhr.getResponseHeader(header).toLowerCase() === securityHeaders[header][1].toLowerCase()) {
  420. 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});
  421. }
  422. messages.push({
  423. msg: msg,
  424. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  425. });
  426. }
  427. }
  428. var xssfields = xhr.getResponseHeader('X-XSS-Protection') ? xhr.getResponseHeader('X-XSS-Protection').split(';').map(function(item) { return item.trim(); }) : [];
  429. if (xssfields.length === 0 || xssfields.indexOf('1') === -1 || xssfields.indexOf('mode=block') === -1) {
  430. messages.push({
  431. 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.',
  432. {
  433. header: 'X-XSS-Protection',
  434. expected: '1; mode=block'
  435. }),
  436. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  437. });
  438. }
  439. const referrerPolicy = xhr.getResponseHeader('Referrer-Policy')
  440. if (referrerPolicy === null || !/(no-referrer(-when-downgrade)?|strict-origin(-when-cross-origin)?|same-origin)(,|$)/.test(referrerPolicy)) {
  441. messages.push({
  442. 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}.',
  443. {
  444. header: 'Referrer-Policy',
  445. val1: 'no-referrer',
  446. val2: 'no-referrer-when-downgrade',
  447. val3: 'strict-origin',
  448. val4: 'strict-origin-when-cross-origin',
  449. val5: 'same-origin'
  450. })
  451. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="https://www.w3.org/TR/referrer-policy/">')
  452. .replace('{linkend}', '</a>'),
  453. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  454. })
  455. }
  456. } else {
  457. messages.push({
  458. msg: t('core', 'Error occurred while checking server setup'),
  459. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  460. });
  461. }
  462. return messages;
  463. },
  464. /**
  465. * Runs check for some SSL configuration issues on the server side
  466. *
  467. * @param {Object} xhr
  468. * @return {Array} Array with error messages
  469. */
  470. _checkSSL: function(xhr) {
  471. var messages = [];
  472. if (xhr.status === 200) {
  473. var tipsUrl = OC.theme.docPlaceholderUrl.replace('PLACEHOLDER', 'admin-security');
  474. if(OC.getProtocol() === 'https') {
  475. // Extract the value of 'Strict-Transport-Security'
  476. var transportSecurityValidity = xhr.getResponseHeader('Strict-Transport-Security');
  477. if(transportSecurityValidity !== null && transportSecurityValidity.length > 8) {
  478. var firstComma = transportSecurityValidity.indexOf(";");
  479. if(firstComma !== -1) {
  480. transportSecurityValidity = transportSecurityValidity.substring(8, firstComma);
  481. } else {
  482. transportSecurityValidity = transportSecurityValidity.substring(8);
  483. }
  484. }
  485. var minimumSeconds = 15552000;
  486. if(isNaN(transportSecurityValidity) || transportSecurityValidity <= (minimumSeconds - 1)) {
  487. messages.push({
  488. 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})
  489. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + tipsUrl + '">')
  490. .replace('{linkend}', '</a>'),
  491. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  492. });
  493. }
  494. } else if (!/(?:^(?:localhost|127\.0\.0\.1|::1)|\.onion)$/.exec(window.location.hostname)) {
  495. messages.push({
  496. 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!')
  497. .replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + tipsUrl + '">')
  498. .replace('{linkend}', '</a>'),
  499. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  500. });
  501. }
  502. } else {
  503. messages.push({
  504. msg: t('core', 'Error occurred while checking server setup'),
  505. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  506. });
  507. }
  508. return messages;
  509. }
  510. };
  511. })();