
Ti sei mai chiesto perché le Pwa richiedono l’https? Beh, io me lo sono chiesto per un po’. Poi ho trovato la risposta nel libro di Dean Hume “Progressive Web Apps”.
Il motivo è legato alla stuttura del service worker:
Remember the analogy of a Service Worker being like an air trafficcontroller? With great power comes great responsibility, and in the case of Service Workers, they could be used for malicious purposes, too. If someone were able to reg-ister a dodgy Service Worker on your web page, they would be able to hijack connec-tions and redirect them to a malicious endpoint. In fact, the bad guys might be able do whatever they wanted with your HTTP requests.
To avoid that, you can only regis-ter Service Workers on web pages that are served over HTTPS. This ensures that the web page hasn’t been tampered with during its journey through the network.
Dean Hume, “Progressive web Apps”
In sostanza, Hume paragona il service worker ad un controllore del traffico aereo (da un grande potere derivano grandi responsabilità). E, nel caso dei service workers, questi poteri potrebbero essere utilizzati anche in modo malevolo.
Se qualcuno fosse in grado di registrare un Service Worker malevolo su una pagina web, sarebbe in grado di dirottare le connessioni e reindirizzarle a un endpoint infetto. Avendo il controllo delle richieste http, chi riesce a controllare il service worker praticamente può fare ciò che vuole con le richieste HTTP.
Per questo motivo, un service worker può essere registrato solo su pagine Web pubblicate su HTTPS: ciò garantisce che la pagina web non sia stata manomessa durante il suo “viaggio” attraverso la rete.