Bypassing CSRF Protections A Double Defeat of the Double-Submit - - PowerPoint PPT Presentation

bypassing csrf protections
SMART_READER_LITE
LIVE PREVIEW

Bypassing CSRF Protections A Double Defeat of the Double-Submit - - PowerPoint PPT Presentation

Bypassing CSRF Protections A Double Defeat of the Double-Submit Cookie Pattern About Me David Johansson (@securitybits) Security consultant since 2007 Helping clients design and build secure software Security training Based in


slide-1
SLIDE 1

Bypassing CSRF Protections

A Double Defeat of the Double-Submit Cookie Pattern

slide-2
SLIDE 2

About Me

  • David Johansson (@securitybits)

– Security consultant since 2007 – Helping clients design and build secure software – Security training – Based in London since 3 years, working for Cigital (now part of Synopsys)

slide-3
SLIDE 3

DOUBLE-SUBMIT COOKIE PATTERN

CSRF Protection

slide-4
SLIDE 4

Cross-site Request Forgery

  • Attacker sends payload via victim’s browser
  • Browser automatically includes user’s identity
slide-5
SLIDE 5

Double-submit Cookie Pattern

  • Simple CSRF protection – no server-side state
slide-6
SLIDE 6

False Assumptions?

Cookies are different! Not really true…

slide-7
SLIDE 7

Cookie Fixation

  • What if attacker can set the CSRF cookie..?
  • Cookie fixation can be done through:

– Exploiting subdomains – Man-in-the-middle HTTP connections

slide-8
SLIDE 8

EXPLOITING SUBDOMAINS

Double-submit Defeat #1:

slide-9
SLIDE 9

Malicious Subdomain

  • Attacker controls https://evil.example.com/
  • Subdomain sets cookie for parent domain
  • Includes specific path
slide-10
SLIDE 10

Malicious Subdomain

  • Attacker now controls cookies sent to

https://www.example.com/submit

  • Attacker’s CSRF cookie sent first due to

longer path

slide-11
SLIDE 11

Vulnerable Subdomain

  • Controlling all subdomains doesn’t mean you’re

safe

  • XSS in any subdomain can be exploited:

<script>document.cookie = “_csrf=a; Path=/submit; domain=example.com”;</script>

  • So you’re using CSP?

– Cookies can still be set through meta-tags ☺

<meta http-equiv="set-cookie" content="_csrf=a; Path=/submit; domain=example.com">

slide-12
SLIDE 12

MAN-IN-THE-MIDDLE ATTACKS

Double-submit Defeat #2:

slide-13
SLIDE 13

Man-in-the-Middle Attacks

  • HTTP origins can set cookies for HTTPS origins
  • Even ‘secure’ cookies can be overwritten from

HTTP responses*

  • Attacker who MiTM any HTTP connection

from victim can:

– Overwrite CSRF cookie – Pre-empt CSRF cookie

*The new ‘Strict Secure Cookie’ specification will prevent this (https://www.chromestatus.com/feature/4506322921848832)

slide-14
SLIDE 14

Overwrite CSRF Cookie

slide-15
SLIDE 15

Pre-empt CSRF Cookie

slide-16
SLIDE 16

Bypassing CSRF Protection

  • After fixating CSRF cookie, attacker can create

successful CSRF payload

slide-17
SLIDE 17

Mitigations

  • Additional defenses to strengthen double-

submit cookie pattern:

– HTTP Strict Transport Security (HSTS) – Cookie Prefixes (“__Host-” is the one you want) – Sign cookie – Bind cookie to user – Use custom HTTP header to send request token

slide-18
SLIDE 18

ANGULAR & CSURF

This is not the token you’re looking for…

slide-19
SLIDE 19

AngularJS CSRF Protection

  • AngularJS $http service has built-in support to

help prevent CSRF*

  • Reads token from cookie (XSRF-TOKEN) and

sets custom HTTP header (X-XSRF-TOKEN)

  • Server needs to implement token validation
  • Can be used as double-submit cookie pattern

if server compares cookie value with HTTP header

*https://blogs.synopsys.com/software-integrity/2017/02/24/angularjs-security-http-service/

slide-20
SLIDE 20

AngularJS & csurf

slide-21
SLIDE 21

Default Value Function

Body and query parameters checked first!

slide-22
SLIDE 22

Exploit Default Value Function

CSRF Defense Bypassed

=

slide-23
SLIDE 23

Specify Custom Value Function

slide-24
SLIDE 24

Summary

  • Double-submit Cookie Pattern based on

partially incorrect assumptions

  • Integrity protection of cookies is very weak
  • Attackers can often force cookies upon other

users

  • Be careful which token you validate against
  • Additional mitigations often required to

strengthen the defense

slide-25
SLIDE 25

Thank You!

Questions?

@securitybits