Slide 1

Slide 1 text

OAUTH: WHEN THINGS
 GO WRONG AARON PARECKI @aaronpk aaronpk.com

Slide 2

Slide 2 text

@aaronpk oauth.net

Slide 3

Slide 3 text

@aaronpk

Slide 4

Slide 4 text

@aaronpk

Slide 5

Slide 5 text

developer.okta.com

Slide 6

Slide 6 text

@aaronpk Disclaimer: This presentation does not necessarily reflect
 the views of my employer. The examples given here are not meant to 
 pick on any one company in particular.

Slide 7

Slide 7 text

@aaronpk WHAT IS OAUTH? AND WHY DOES IT MATTER?

Slide 8

Slide 8 text

@aaronpk THE PASSWORD ANTI-PATTERN

Slide 9

Slide 9 text

@aaronpk THE PASSWORD ANTI-PATTERN facebook.com ~2010

Slide 10

Slide 10 text

@aaronpk

Slide 11

Slide 11 text

@aaronpk the app can't just get access to the user's data directly

Slide 12

Slide 12 text

@aaronpk the app isn't allowed to ask for the user's password and use it

Slide 13

Slide 13 text

@aaronpk so... how can I let an app access my data without giving it my password?

Slide 14

Slide 14 text

@aaronpk Connect with Google https://yelp.com/

Slide 15

Slide 15 text

@aaronpk the app needs to ask the user for an access token
 which it can use with the API password

Slide 16

Slide 16 text

@aaronpk POST /resource/1/update HTTP/1.1 Authorization: Bearer RsT5OjbzRn430zqMLgV3Ia Host: api.authorization-server.com description=Hello+World

Slide 17

Slide 17 text

@aaronpk A HOTEL KEY CARD, FOR APPS

Slide 18

Slide 18 text

@aaronpk HOW OAUTH WORKS

Slide 19

Slide 19 text

@aaronpk ROLES IN OAUTH OAuth Server (Authorization Server) aka the token factory API (Resource Server) The Application (Client) The User's Device (User Agent)

Slide 20

Slide 20 text

OAuth Server (Authorization Server) API (Resource Server) The Best App Ever User: I’d like to use this great app App: Please go to the authorization server to grant me access User: I’d like to log in to “The Best App Ever”, it wants to access my photos AS: Here is a temporary code the app can use App: Here is the temporary code, and my secret, please give me a token User: Here is the temporary code, please use this to get a token AS: Here is an access token! App: Please let me access this user’s data with this access token!

Slide 21

Slide 21 text

Front Channel Back Channel https://accounts.google.com/?... Passing data via the browser's address bar The user, or malicious software, can modify the requests and responses Sent from server to server Code is run on a server, not on the user's computer, so requests cannot be tampered with

Slide 22

Slide 22 text

Back Channel Benefits ‣ The application knows it's talking to the right server ‣ Connection from app to server can't be tampered with ‣ Response from the server can be trusted because it came back in the same connection

Slide 23

Slide 23 text

OAuth Server OAuth Client Passing Data via the Back Channel

Slide 24

Slide 24 text

OAuth Server OAuth Client access token! Passing Data via the Front Channel

Slide 25

Slide 25 text

Front Channel Benefits https://accounts.google.com/?... ‣ The user being involved enables them to give consent ‣ Doesn't require the receiver to have a publicly routable IP
 (e.g. can work on a phone)

Slide 26

Slide 26 text

@aaronpk ▸ The sender has no guarantee the receiver will get the data
 e.g. if the redirect is intercepted ▸ The data is written to the browser history
 which may be synced to "the cloud" or other devices Any data received via the front channel must be verified before it is used! FRONT-CHANNEL RISKS

Slide 27

Slide 27 text

@aaronpk WHAT CAN GO WRONG?

Slide 28

Slide 28 text

@aaronpk ▸ Lots! ▸ Stolen API Keys ▸ Stolen Access Tokens ▸ Redirect URL Interception ▸ Phishing ▸ ... and more WHAT CAN GO WRONG WITH OAUTH?

Slide 29

Slide 29 text

@aaronpk WHAT CAN GO WRONG WITH OAUTH? ▸ RFC 6749 Section 10 ▸ RFC 8252 Section 8 ▸ RFC 6819 ▸ draft-ietf-oauth-security-topics

Slide 30

Slide 30 text

@aaronpk TWITTER STOLEN API KEYS

Slide 31

Slide 31 text

@aaronpk 2013

Slide 32

Slide 32 text

@aaronpk

Slide 33

Slide 33 text

@aaronpk ANYONE CAN 
 IMPERSONATE 
 THE TWITTER APPS

Slide 34

Slide 34 text

@aaronpk DON'T PUT SECRETS
 IN NATIVE APPS! https://developer.okta.com/blog/2019/01/22/oauth-api-keys-arent-safe-in-mobile-apps

Slide 35

Slide 35 text

@aaronpk PKCE PROOF-KEY FOR CODE EXCHANGE RFC 7636 (pronounced "pixie")

Slide 36

Slide 36 text

@aaronpk PKCE PKCE Authorization Code Flow

Slide 37

Slide 37 text

OAuth Server (Authorization Server) API (Resource Server) The Best App Ever User: I’d like to use this great app App: Please go to the authorization server to grant me access, take this hash with you User: I’d like to log in to this app, here's the hashed secret it gave me AS: Here is a temporary code the app can use App: Here's the code, and the plaintext secret, please give me a token User: Here is the temporary code, please use this to get a token AS: Let me verify the hash of that secret... ok here is an access token! App: Please let me access this user’s data with this access token! App: Hang on while I generate a new secret and hash it

Slide 38

Slide 38 text

@aaronpk AppAuth.io iOS / Android / JavaScript

Slide 39

Slide 39 text

@aaronpk FACEBOOK STOLEN ACCESS TOKENS improperly issued

Slide 40

Slide 40 text

@aaronpk 2018

Slide 41

Slide 41 text

@aaronpk https://newsroom.fb.com/news/2018/09/security-update/ The vulnerability was the result of the interaction of three distinct bugs:

Slide 42

Slide 42 text

@aaronpk https://newsroom.fb.com/news/2018/09/security-update/ The vulnerability was the result of the interaction of three distinct bugs:

Slide 43

Slide 43 text

@aaronpk https://newsroom.fb.com/news/2018/09/security-update/ The vulnerability was the result of the interaction of three distinct bugs: ??!

Slide 44

Slide 44 text

@aaronpk By using the "View As" feature to see what your profile looks like to someone else, you would end up with an access token belonging to that user, which had the permissions of the Facebook mobile app.

Slide 45

Slide 45 text

@aaronpk Treat components of your application
 the same way you'd treat third-party applications

Slide 46

Slide 46 text

@aaronpk JWT ALG=NONE photo by flickr.com/quidox

Slide 47

Slide 47 text

@aaronpk 2015

Slide 48

Slide 48 text

An Example JWT eyJraWQiOiJvQ1JjR3RxVDhRV2tJR0MyVXpmcEZUczVqSkdnM00zSTNOMHgtZDJhSFNNIiwiYW xnIjoiUlMyNTYifQ.eyJ2ZXIiOjEsImp0aSI6IkFULkp3eVRTcTlqNDU0bDNTNmRTM1VTV1hMV VpwekdKdWNSd1ZEbFZCNWNIc3cuVVM1V1NGYVFiQllUMC9GM2tjMG8vK1ZUY3VZZzdwVnZqZXZ TT3hkUHhCMD0iLCJpc3MiOiJodHRwczovL2Rldi0zOTYzNDMub2t0YXByZXZpZXcuY29tL29hd XRoMi9kZWZhdWx0IiwiYXVkIjoiYXBpOi8vZGVmYXVsdCIsImlhdCI6MTU0MzgwMzAyNSwiZXh wIjoxNTQzODA2NjI1LCJjaWQiOiIwb2FoenBwM3RjcEZyZmNXSTBoNyIsInVpZCI6IjAwdWkwZ mpraWV5TDQ2bWEwMGg3Iiwic2NwIjpbIm9mZmxpbmVfYWNjZXNzIiwicGhvdG8iXSwic3ViIjo iaW5xdWlzaXRpdmUtYWxiYXRyb3NzQGV4YW1wbGUuY29tIn0.ncVkzcc6qrFJSXE3-5UsRu_kH vbwIMKYL3PFaMwReYTquPAcOQ8t93xF0bxbS8wrP0udCDvk6eYq4VbjoFdD59Yy6ltz0OKQl3- g8uFg2RwqTBMOKR0mYtQH0RCr9ORhSsmKolaDDt4TcRX78ZOAyhZ_Qg_UcEoHM4uZikpzBJYpY KbCCfbx-6FzYyHuvevSFzURISYpSHv3nbzirkEzKbOv7eZlg1cCYBdUoGuVBskyHxfMxFpoKQU 3mwIFdlQJR8LZ8hA_5ZdYjjMeSXfjnhlP2rppJiHy1NreGXXcUsUA74V2t_keY44deTrnPgoFO Se9IchWqcj6sDMDutC4ag

Slide 49

Slide 49 text

Attacking a JWT { "typ": "JWT", "alg": "RS256" } { "ver": 1, "jti": "AT.JwyTSq9j454l3S6dS3USWXLUZpzGJucRwVDlVB5cHsw.US5WSFaQbBYT0/F3kc0o/+VTcuYg7pVvjevSOxdPxB0=", "iss": "https://dev-396343.oktapreview.com/oauth2/default", "aud": "api://default", "iat": 1543803025, "exp": 1543806625, "cid": "0oahzpp3tcpFrfcWI0h7", "uid": "00ui0fjkieyL46ma00h7", "scp": [ "offline_access", "photo" ], "sub": "inquisitive-albatross@example.com" } header claims signature

Slide 50

Slide 50 text

Attacking a JWT { "typ": "JWT", "alg": "none" } { "ver": 1, "jti": "AT.JwyTSq9j454l3S6dS3USWXLUZpzGJucRwVDlVB5cHsw.US5WSFaQbBYT0/F3kc0o/+VTcuYg7pVvjevSOxdPxB0=", "iss": "https://dev-396343.oktapreview.com/oauth2/default", "aud": "api://default", "iat": 1543803025, "exp": 1543806625, "cid": "0oahzpp3tcpFrfcWI0h7", "uid": "00ui0fjkieyL46ma00h7", "scp": [ "offline_access", "photo" ], "sub": "inquisitive-albatross@example.com" } header claims

Slide 51

Slide 51 text

Attacking a JWT { "typ": "JWT", "alg": "HS256" } { "ver": 1, "jti": "AT.JwyTSq9j454l3S6dS3USWXLUZpzGJucRwVDlVB5cHsw.US5WSFaQbBYT0/F3kc0o/+VTcuYg7pVvjevSOxdPxB0=", "iss": "https://dev-396343.oktapreview.com/oauth2/default", "aud": "api://default", "iat": 1543803025, "exp": 1543806625, "cid": "0oahzpp3tcpFrfcWI0h7", "uid": "00ui0fjkieyL46ma00h7", "scp": [ "offline_access", "photo" ], "sub": "inquisitive-albatross@example.com" } header claims signature

Slide 52

Slide 52 text

@aaronpk Never let the JWT header
 determine your verification mechanism

Slide 53

Slide 53 text

@aaronpk Thankfully most JWT libraries
 fixed this in 2015-2016

Slide 54

Slide 54 text

@aaronpk GOOGLE OAUTH PHISHING

Slide 55

Slide 55 text

@aaronpk 2017

Slide 56

Slide 56 text

https://accounts.google.com/oauth/authorize?response_type

Slide 57

Slide 57 text

https://arstechnica.com/information-technology/2017/05/dont-trust-oauth-why-the-google-docs-worm-was-so-convincing/

Slide 58

Slide 58 text

https://accounts.google.com/oauth/authorize?response_type

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

Prompting the User for Authorization Consent • Provide clear and straightforward information • Provide enough detail so the user knows what the application can access • Don't provide too much detail that they are overwhelmed and just click "ok"

Slide 62

Slide 62 text

No content

Slide 63

Slide 63 text

No content

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

No content

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

Authorization Interface

Slide 72

Slide 72 text

Authorization Interface Identify your service Identify the third-party app List the scopes the app is requesting Identify the developer name Show which user is logged in Allow/Cancel buttons

Slide 73

Slide 73 text

@aaronpk oauth.net/security oauth2simplified.com

Slide 74

Slide 74 text

@aaronpk aaronpk.com