https-check.ts 1015 B

12345678910111213141516171819202122232425262728
  1. import type { FrontendTask } from '../types'
  2. import type { ReportStatusType } from '@/api/self_check'
  3. import { ReportStatus } from '@/api/self_check'
  4. /**
  5. * HTTPS Check Task
  6. *
  7. * Checks if the application is accessed via HTTPS protocol
  8. * Warns (not errors) when HTTP is used outside of localhost/127.0.0.1
  9. */
  10. const HttpsCheckTask: FrontendTask = {
  11. key: 'https-check',
  12. name: () => $gettext('HTTPS Protocol'),
  13. description: () => $gettext('Check if HTTPS is enabled. Using HTTP outside localhost is insecure and prevents using Passkeys and clipboard features'),
  14. check: async (): Promise<ReportStatusType> => {
  15. // Get current protocol and hostname
  16. const isSecure = window.location.protocol === 'https:'
  17. const isLocalhost = ['localhost', '127.0.0.1'].includes(window.location.hostname)
  18. // Check result
  19. if (isSecure || isLocalhost) {
  20. return ReportStatus.Success
  21. }
  22. // Return warning for non-localhost HTTP
  23. return ReportStatus.Warning
  24. },
  25. }
  26. export default HttpsCheckTask