Lock in $30 Savings on PRO—Offer Ends Soon! ⏳

User Agent Lockdown - HackPra 2014

User Agent Lockdown - HackPra 2014

Mike West

April 16, 2014
Tweet

More Decks by Mike West

Other Decks in Programming

Transcript

  1. Privileges we should reconsider: 1. Browsers allow content to load

    over unencrypted connections. 2. Browsers accept whatever happens to live at a URL as canonical. 3. Browsers load any and all resources a page requests.
  2. <style> p { color: {{USER_COLOR}}; } </style> <p> Hello {{USER_NAME}},

    view your <a href="{{USER_URL}}">Account</a>. </p> <script> var id = {{USER_ID}}; </script> <!-- DEBUG: {{INFO}} -->
  3. Content-Security-Policy: default-src 'none'; style-src https://mikewestdotorg.hasacdn.net; frame-src https://www.youtube.com https://www.speakerdeck.com; script-src https://mikewestdotorg.hasacdn.net

    https://ssl.google-analytics.com; img-src 'self' https://mikewestdotorg.hasacdn.net https://ssl.google-analytics.com; font-src https://mikewestdotorg.hasacdn.net
  4. Content-Security-Policy: default-src ...; script-src ...; object-src ...; style-src ...; img-src

    ...; media-src ...; frame-src ...; font-src ...; connect-src ...; sandbox ...; report-uri https://example.com/reporter.cgi
  5. Content-Security-Policy-Report-Only: default-src https:; report-uri https://example.com/csp-violations { "csp-report": { "document-uri": "http://example.org/page.html",

    "referrer": "http://evil.example.com/haxor.html", "blocked-uri": "http://evil.example.com/img.png", "violated-directive": "default-src 'self'", "original-policy": "...", "source-file": "http://example.com/script.js", "line-number": 10, "column-number": 11, } }
  6. <!-- index.html --> <script src="clickHandler.js"></script> <button class="clckr">Click me!</button> <a href="#"

    class="clckr">Click me!</a> <!-- clickHandler.js --> function handleClick() { ... } function init() { for (var e in document.querySelectorAll('.clckr')) e.addEventListener('click', handleClick); }
  7. Content-Security-Policy: script-src 'nonce-THIS-IS-A-RANDOM-NONCE'; <button class="clckr">Click me!</button> <a href="#" class="clckr">Click me!</a>

    <script nonce="THIS-IS-A-RANDOM-NONCE"> function handleClick() { ... } function init() { var e; for (e in document.querySelectorAll('.clckr')) e.addEventListener('click', handleClick); } </script>
  8. Content-Security-Policy: script-src 'sha256-kjhhuy...poiIOY-AI'; <button class="clckr">Click me!</button> <a href="#" class="clckr">Click me!</a>

    <script> function handleClick() { ... } function init() { var e; for (e in document.querySelectorAll('.clckr')) e.addEventListener('click', handleClick); } </script>
  9. Thanks for your time! 1. HTTPS all the things. 2.

    Deploy Content Security Policy (mkw.st/r/csp) to mitigate content injection attacks. 3. Follow the progress of Subresource Integrity (mkw.st/r/subint). 4. Ask questions, now, or on Twitter: @mikewest.