Slide 1

Slide 1 text

Frontend Security Mike West https://mikewest.org G+: mkw.st/+ Twitter: @mikewest Video/Transcript: https://mkw.st/r/fec13

Slide 2

Slide 2 text

http://www.html5rocks.com/en/tutorials/security/content-security-policy/ https://mkw.st/r/csp

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

XSS is scary.

Slide 5

Slide 5 text

scheme://host:port

Slide 6

Slide 6 text

beAwesome(); beEvil();

Slide 7

Slide 7 text

beAwesome();

Hello, beEvil(); !

Slide 8

Slide 8 text

p { color: {{USER_COLOR}}; }

Hello {{USER_NAME}}, view your Account.

var id = {{USER_ID}};

Slide 9

Slide 9 text

https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet goo.gl/XE0aW

Slide 10

Slide 10 text

[][(![]+[])[+[[+[]]]]+([][[]]+[])[+[[!+[]+!+[]+!+[]+!+[]+!+[]]]]+(![]+[])[+[[!+[]+!+[]]]]+(!![]+[]) [+[[+[]]]]+(!![]+[])[+[[!+[]+!+[]+!+[]]]]+(!![]+[])[+[[+!+[]]]]][([][(![]+[])[+[[+[]]]]+([][[]]+[]) [+[[!+[]+!+[]+!+[]+!+[]+!+[]]]]+(![]+[])[+[[!+[]+!+[]]]]+(!![]+[])[+[[+[]]]]+(!![]+[])[+[[!+[]+!+[] +!+[]]]]+(!![]+[])[+[[+!+[]]]]]+[])[+[[!+[]+!+[]+!+[]]]]+([][(![]+[])[+[[+[]]]]+([][[]]+[])[+[[!+[] +!+[]+!+[]+!+[]+!+[]]]]+(![]+[])[+[[!+[]+!+[]]]]+(!![]+[])[+[[+[]]]]+(!![]+[])[+[[!+[]+!+[]+!+[]]]] +(!![]+[])[+[[+!+[]]]]]+[])[+[[!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]]]+([][[]]+[])[+[[+!+[]]]]+(![]+[])[+ [[!+[]+!+[]+!+[]]]]+(!![]+[])[+[[+[]]]]+(!![]+[])[+[[+!+[]]]]+([][[]]+[])[+[[+[]]]]+([][(![]+[])[+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[])[+[[+[]]]]+([][(![]+[])[+[[+[]]]]+([][[]]+[])[+[[!+[]+!+ []+!+[]+!+[]+!+[]]]]+(![]+[])[+[[!+[]+!+[]]]]+(!![]+[])[+[[+[]]]]+(!![]+[])[+[[!+[]+!+[]+!+[]]]]+ (!![]+[])[+[[+!+[]]]]]+[])[+[[+!+[]]]+[[!+[]+!+[]+!+[]+!+[]+!+[]]]]+[+!+[]]+([][(![]+[])[+[[+[]]]]+ ([][[]]+[])[+[[!+[]+!+[]+!+[]+!+[]+!+[]]]]+(![]+[])[+[[!+[]+!+[]]]]+(!![]+[])[+[[+[]]]]+(!![]+[])[+ [[!+[]+!+[]+!+[]]]]+(!![]+[])[+[[+!+[]]]]]+[])[+[[+!+[]]]+[[!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]]])() alert(1);

Slide 12

Slide 12 text

"I discount the probability of perfection." -Alex Russell

Slide 13

Slide 13 text

"We are all idiots with deadlines." -Mike West

Slide 14

Slide 14 text

http://traumwerk.stanford.edu/philolog/2009/10/homers_odyssey_in_art_sirens_f.html

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

http://w3.org/TR/CSP11

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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, } }

Slide 20

Slide 20 text

function handleClick() { ... } Click me! Click me!

Slide 21

Slide 21 text

Click me! Click me! function handleClick() { ... } function init() { for (var e in document.querySelectorAll('.clickr')) e.addEventListener('click', handleClick); }

Slide 22

Slide 22 text

http://www.html5rocks.com/en/tutorials/security/content-security-policy/ https://mkw.st/r/csp

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

$ curl -I http://mkw.st/ HTTP/1.1 301 Moved Permanently Server: nginx/1.5.0 Date: Tue, 27 Aug 2013 19:36:15 GMT Content-Type: text/html Content-Length: 184 Connection: keep-alive Keep-Alive: timeout=20 Location: https://mkw.st/

Slide 27

Slide 27 text

$ curl -I https://mkw.st/ HTTP/1.1 200 OK Server: nginx/1.5.0 Date: Tue, 27 Aug 2013 19:42:31 GMT ... Strict-Transport-Security: max-age=2592000; includeSubDomains ...

Slide 28

Slide 28 text

Set-Cookie: ...; secure; HttpOnly

Slide 29

Slide 29 text

Public-Key-Pins: max-age=2592000; pin-sha1="4n972H…60yw4uqe/baXc="

Slide 30

Slide 30 text

http://www.html5rocks.com/en/tutorials/security/transport-layer-security/ goo.gl/0aMqHM

Slide 31

Slide 31 text

Slide 32

Slide 32 text

Slide 33

Slide 33 text

Slide 34

Slide 34 text

http://www.html5rocks.com/en/tutorials/security/sandboxed-iframes/ goo.gl/WJjv10

Slide 35

Slide 35 text

https://mkw.st/r/fec13 Danke! Mike West https://mikewest.org G+: mkw.st/+ Twitter: @mikewest Video/Transcript: https://mkw.st/r/fec13