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

CSP a Powerful Security Steroid

Jxck
February 09, 2017

CSP a Powerful Security Steroid

Chrome Tech Night #9 @2016/2/9

Jxck

February 09, 2017
Tweet

More Decks by Jxck

Other Decks in Technology

Transcript

  1. 6

  2. 7 Policy of Security for Content • This content is

    allowed to ◦ exec inline script ? ◦ load assets from origin xxx ? ◦ embend iframe ? ◦ mixed content ? ◦ etc
  3. 8 How to apply CSP • via Header • via

    Meta Tag Content-Security-Policy: $policy <meta http-equiv=”Content-Security-Policy” content=”$policy” >
  4. 9 CSP directives • fetch directive • document directive •

    navigation directive • reporting directive
  5. 10 fetch directives • default-src • child-src • connect-src •

    font-src • frame-src • img-src • manifest-src • media-src • object-src • script-src • style-src • worker-src whitelist of allowed orign fallback to default-src ex) img-src; http://jxck.io default-src; ‘self’
  6. 11 document directives • base-uri ◦ allowed url for <base>

    • plugin-types ◦ allowed media type for <embed> / <object> • sandbox ◦ behave like sandbox iframe • disown-opener ◦ behave like noopener
  7. 12 navigation directives • form-action ◦ allowed action for <form>

    • frame-ancestors ◦ allowed origin for embed this docment • navigation-to ◦ allowed origin to move (a, form, window.location etc)
  8. 13 reporting directives • report-uri ◦ deprecated ◦ only for

    fallback of report-to • report-to ◦ url to send violation report
  9. 14 CSP keywords • ‘self’ ◦ only from Same Origin

    • ‘none’ ◦ from everywhere • ‘unsafe-inline’ ◦ allow <script> / <style> • ‘unsafe-eval’ ◦ allow `eval()` in JS • ‘strict-dynamic’ ◦ specify nonce of script • ‘unsafe-hashed-attributes’ ◦ specify a hash of inline script
  10. 15 Most Powerful Policy • can I have… ◦ jquery

    from cdn ? :No ◦ google anlytics ? :No ◦ youtube? :No ◦ iframe… :NO! ◦ inline.. :Never !! Content-Security-Policy: default-src ‘self’
  11. No more Escape Input ? • only checking a Policy

    , not Attack ◦ in policy has a hole, It may have incident ◦ no implement of CSP on old browser • do Security thing, and adding CSP for cover ◦ if security hall exists, block the attack 17
  12. report-uri 20 • Send Report as JSON to URI Content-Security-Policy:

    default-src ‘self’; report-uri https://report-server/... { "csp-report": { "document-uri": “...”, "referrer": “...”, "blocked-uri": “...”, "violated-directive": “...”, "original-policy": “...”, } }
  13. Report doesn’t tells me about attack • you can know

    WHAT happened ◦ document uri ◦ violated policy • you can’t know WHY happened ◦ attack ? or not ? • you can’t know WHAT result to USER ◦ ad image not displayed ? ◦ can’t read the article ? 21
  14. Too strict to deploy immediate • Hard to make sure

    your policy right ◦ crowring with browser on staging • Real World Problems ◦ every user use each browser with variaus setting • Deploy in production immediately ? ◦ bad experience for user ? ◦ it’s wose than blocking attack ? 23
  15. CSP-Report-Only • only sending report ◦ find out WHAT happened

    only • rolling out to remove report-only ◦ after finish testing policy ◦ but I think it’s optional ◦ finding what happened is enought for integration 24
  16. blog.jxck.io 26 • basically static contents only ◦ no <input>

    ◦ no Dynamic Generated ◦ no CDN • potentially no XSS ◦ violation by Non XSS Attack ◦ or attack not expected
  17. Current Settings 27 content-security-policy-report-only: default-src 'self' https://jxck.io https://*.jxck.io https://www.google-analytics.co m

    ; child-src https://blog.jxck.io https://www.youtube.com ; connect-src wss://ws.jxck.io ; report-uri https://jxck.report-uri.io/...
  18. 29 CSP Report case#1 • append script via bookmarklet (maybe)

    { "csp-report": { "document-uri": "https://blog.jxck.io/entries/...", "referrer": "https://blog.jxck.io/", "violated-directive": "script-src", "effective-directive": "script-src", "original-policy": "default-src 'self' https://jxck.io...", "disposition": "report", "blocked-uri": "https://code.jquery.com/jquery-3.0.0.min.js", "line-number": 1, "column-number": 108, "status-code": 0 } }
  19. 30 CSP Report case#2 • browser-extension { "csp-report": { "document-uri":

    "https://blog.jxck.io/entries/...", "violated-directive": "default-src 'self' https://jxck.io ...", "effective-directive": "img-src", "original-policy": "default-src 'self' https://jxck.io ...", "blocked-uri": "ms-browser-extension", "status-code": 0 } }
  20. 31 CSP Report case#3 • inline style in Chrome .txt,

    .md, .xml { "csp-report": { "document-uri": "https://jxck.io/humans.txt", "referrer": "", "violated-directive": "style-src", "effective-directive": "style-src", "original-policy":"default-src 'self' https://*.jxck.io...", "disposition":"report", "blocked-uri":"inline", "line-number":1, "status-code":0 } } Image
  21. 33 CSP Report case#4 • inline style in FF view-source://

    { "csp-report": { "blocked-uri": "self", "document-uri": "view-source", "original-policy": "...", "script-sample": "-moz-tab-size: 4", "source-file": "view-source:https://blog.jxck.io/entries/...", "violated-directive": "default-src view-source:// ..." } } Image
  22. 35 CSP Report case#5 • about://blank { "csp-report": { "document-uri":

    "about://blank", "violated-directive": "default-src 'self' https://jxck.io...", "effective-directive": "img-src", "original-policy": "default-src 'self' https://jxck.io…", "blocked-uri": "data", "status-code": 0 } }
  23. 38 Steroid (powerful but…) • Blog for Engineer ◦ bookmarklets,

    extentions, localproxy etc ◦ user nomary arrange contents by themself • Almost all seems Not Attack ◦ really need to block them ? ◦ safe ? incombenience ? • Protected / Clippled ◦ depends for contents ◦ Github / Twitter etc
  24. Finding Mixed Contents 40 • Mixed Contents ◦ HTTP subresource

    in HTTPS ◦ can’t ensure falsify by MITM ◦ no green URL bar • Active ◦ Possible to modify outer DOM (script, iframe etc) ◦ Blocked • Passive ◦ Impossible to modify outer DOM (img, video, audio etc) ◦ Error but not blocked
  25. HTTPS Everywhere vs Mixed Contents 41 • case of Mixed

    Contents ◦ Consumer Generated Media ◦ Ad ◦ Legacy Hard Coded URL • if Mixed ◦ insecure url bar ◦ broken contents ◦ invisible Ad
  26. Upgrade-Insecure-Request 42 • fetch http:// url as https:// ◦ 404

    if not supported ◦ never mixed contents • avoid mixed only one header ◦ no modify contents ◦ find mixed by 404 in server access.log Content-Security-Policy: Upgrade-Insecure-Requests
  27. Block-All-Mixed-Contents 43 • block if Passive mixed contents ◦ broken

    contents if mixed ◦ never mixed contents • with CSP Report ◦ Report-Only doesn’t broke contents ◦ finding mixed by csp reoprt Content-Security-Policy: Block-All-Mixed-Contents
  28. 45 report-uri.io • not recommended (in production) ◦ bad UI

    ◦ bad response at sending Report ◦ can’t see data before half year ◦ can’t see HTTP header ◦ can’t export your data • do yourself ◦ simple POST endpoint for JSON ◦ kibana, grafana, big query etc ◦ Google Analytics support are welcome :)
  29. HTTP Public Key Pinning 47 • pin a hash of

    public key ◦ avoide CA incident • hard to deploy ◦ backup pin Public-Key-Pins: pin-sha256=”#{hash-of-public-key}”