Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Increasing web apps security with the power of http headers

Slide 4

Slide 4 text

Agenda HTTP Strict Transport Security (HSTS) HTTP Public Key Pinning (HPKP) Content Security Policy (CSP)

Slide 5

Slide 5 text

HSTS ● The browser strictly upgrades the connection to HTTPS protocol ● Avoid MITM attacks that try intercept the initial HTTP request ● SSLStripping attacks

Slide 6

Slide 6 text

SSLStrip

Slide 7

Slide 7 text

HSTS

Slide 8

Slide 8 text

HSTS server { listen 443 ssl; add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; # This 'location' block inherits the STS header location / { root /usr/share/nginx/html; } }

Slide 9

Slide 9 text

HSTS Directives ● max-age tells user-agent how long to cache the STS setting in seconds ● includeSubDomains tells user-agent to include any subdomains

Slide 10

Slide 10 text

chrome://net-internals/#hsts

Slide 11

Slide 11 text

http://caniuse.com/#feat=stricttransportsecurity

Slide 12

Slide 12 text

HTTPS Everywhere plugin ● Redirects users to HTTPS version of the site ● https://www.eff.org/https-everywhere ● Available for Chrome,Firefox,Opera

Slide 13

Slide 13 text

HPKP ● Certificate Pinning is a security mechanism which allows HTTPS websites to resist impersonation by attackers using mis-issued or otherwise fraudulent certificates ● The HTTPS web server serves a list of public key hashes, and on subsequent connections clients expect that server to use one or more of those public keys in its certificate chain.

Slide 14

Slide 14 text

HPKP ● Minimize MITM attacks by pinning certificate ● The pin is saved by the browser in the first request and in next requests this pin is used to verify the public key ● In this way we can check that the certificate has not been altered

Slide 15

Slide 15 text

HPKP add_header Public-Key-Pins: 'pin-sha256="vDGd5BIsPtpEDVrOzMypcp9CjSQ8QIiIQq6i Rg59UOg="; pin-sha256="Mfyz5Zy4hGa1yrs93hMGGPo57r42fM+mttvE mHuXIdI="; max-age=60; includeSubdomains;

Slide 16

Slide 16 text

HPKP ● Decide which certificate's public keys you will pin ● Create SHA-256 hashes for the public keys ● Set your site to send a header with the pins ● Visit your site multiple times to verify that you are not blocked ● Check chrome://net-internals/#hsts and query your domain to verify that the pins are stored ● Verify dynamic_pkp_observed and dynamic_spki_hashes

Slide 17

Slide 17 text

HPKP

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

HPKP ● PinPatrol firefox plugin ● Check HSTS and HPKP headers

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

CSP ● Helps to detect and mitigate data injection attacks such as XSS ● Prevent XSS, clickjacking, code injection attacks

Slide 22

Slide 22 text

CSP ● Load everything from the same origin ● 'self' --> Content of this type can only be loaded from the same origin ● add_header Content-Security-Policy "default-src 'self';";

Slide 23

Slide 23 text

CSP Source expressions

Slide 24

Slide 24 text

https://csp-evaluator.withgoogle.com/

Slide 25

Slide 25 text

http://cspisawesome.com/

Slide 26

Slide 26 text

Conclusions ● HSTS assures that the browser won’t open unencrypted HTTP requests to your domain ● HPKP assures that nobody can exchange your certificate as a man-in-the-middle.

Slide 27

Slide 27 text

More headers ● X-XSS-Protection:Enables Web Browser’s self XSS (Cross-site-scripting) attack protection mechanism ● X-Frame-Options:Provides protection against Clickjacking / UI Redress attacks. ● X-Content-Type-Options:Used to prevent MIME content-sniffing attacks.

Slide 28

Slide 28 text

• curl --head

Slide 29

Slide 29 text

● Helmet module

Slide 30

Slide 30 text

References ● https://securityheaders.io ● https://www.ssllabs.com/ssltest ● https://www.chromium.org/hsts ● https://hstspreload.org ● https://www.owasp.org/index.php/HTTP_St rict_Transport_Security_Cheat_Sheet

Slide 31

Slide 31 text

PinPatrol firefox plugin

Slide 32

Slide 32 text

• https://observatory.mozilla.org/

Slide 33

Slide 33 text

• https://report-uri.io

Slide 34

Slide 34 text

Thank you! @jmortegac jmortega.github.io about.me/jmortegac