30
OAuth: Where are we going? 1 What is OAuth? OAuth and CSRF Redirection Token Reuse OAuth Grant Types

OAuth: Where are we going?...• Resource Owner or End-User: User and account owner of resource (the end-user) • Resource Server/Service Provider:Server hosting protected resources

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: OAuth: Where are we going?...• Resource Owner or End-User: User and account owner of resource (the end-user) • Resource Server/Service Provider:Server hosting protected resources

OAuth:Wherearewegoing?

1

WhatisOAuth?

OAuthandCSRF

Redirection

TokenReuse

OAuthGrantTypes

Page 2: OAuth: Where are we going?...• Resource Owner or End-User: User and account owner of resource (the end-user) • Resource Server/Service Provider:Server hosting protected resources

OAuthv1andv2

2

"OAuth2.0atthehandofadeveloperwithdeepunderstandingofwebsecuritywilllikelyresult[in]asecureimplementation.However,atthehandsofmostdevelopers ...2.0islikelytoproduceinsecureimplementations."

http://hueniverse.com/2012/07/26/oauth-2-0-and-the-road-to-hell/http://hueniverse.com/2010/09/29/oauth-bearer-tokens-are-a-terrible-idea/

Eran Hammer,OriginalFounderofOAuth

Page 3: OAuth: Where are we going?...• Resource Owner or End-User: User and account owner of resource (the end-user) • Resource Server/Service Provider:Server hosting protected resources

OAuthHistory

• Nov2006:BlaineCookbeginsworkingonOAuthwhileatTwitter• 2007:Ma.gnolia,Googleandothersjointhediscussion• 2007:Eran Hammerjoinsandsoonleadsthespecification• Dec2007:OAuth1.0finaldraft• 2008:GoogleOAuth1.0supportbegins• 2010:TwitterforcesallthirdpartyappstouseOAuth1.0• June2012:Eran ragequits theOAuth2.0bodyaftertheshiftfromcryptotobearertokens• October2012:OAuth2.0frameworkpublished

3

Page 4: OAuth: Where are we going?...• Resource Owner or End-User: User and account owner of resource (the end-user) • Resource Server/Service Provider:Server hosting protected resources

OAuthv1andv2:Whataretheprimarysecuritydifferences?

4

OAuthv2isTransport-DependentMostsecuritydefensesaredelegatedtoHTTPS/TLS

OAuthv1isTransport-IndependentSecurityisnotdelegatedtoHTTPS/TLS

Atypo,animproper TLSconfiguration, orafailuretoproperlyvalidateacertificatecanleadtoaman-in-the-middleattack,compromising allOAuthcommunications.

OAuthv1messagesareeachindividuallycryptographically signed.Ifasinglemessagewithinthecommunication isconstructedorsigned improperly, theentiretransactionwillbeinvalidated.

Page 5: OAuth: Where are we going?...• Resource Owner or End-User: User and account owner of resource (the end-user) • Resource Server/Service Provider:Server hosting protected resources

OAuthv1andv2:SignaturesvsBearerTokens

5

OAuthv2AuthorizesMessageswithBearerTokens

OAuthv1AuthorizesMessageswithDigitalSignatures

BearerTokensdonotprovide internalsecuritymechanisms.Theycanbecopiedorstolen.

Asignedmessageistiedtoit'sorigin. Itcannotbetamperedwithorcopiedtoanothersource.

Page 6: OAuth: Where are we going?...• Resource Owner or End-User: User and account owner of resource (the end-user) • Resource Server/Service Provider:Server hosting protected resources

OAuthv1andv2:Whichshouldyouuse?

6

• GooglemovedawayfromOAuth1.0inApril2012.

• TwitterstillsupportsOAuth1.0.

• It’srarefornewserverimplementationstosupportOAuth1.0.

• PlentyofOAuth2.0“add-on”RFC’stosupportcryptoifneeded.

• Soyea,2.0inalmostallsituationsin2015.

Page 7: OAuth: Where are we going?...• Resource Owner or End-User: User and account owner of resource (the end-user) • Resource Server/Service Provider:Server hosting protected resources

OAuthv1Workflow

7

http://docs.spring.io/spring-social/docs/1.0.0.RC1/reference/html/serviceprovider.html#service-providers-oauth1

Page 8: OAuth: Where are we going?...• Resource Owner or End-User: User and account owner of resource (the end-user) • Resource Server/Service Provider:Server hosting protected resources

OAuthv2Workflow

8

http://docs.spring.io/spring-social/docs/1.0.0.RC1/reference/html/serviceprovider.html#service-providers-oauth2

Page 9: OAuth: Where are we going?...• Resource Owner or End-User: User and account owner of resource (the end-user) • Resource Server/Service Provider:Server hosting protected resources

OAuthSecurityinProductsisStabilizing(osvdb.org)

9

Page 10: OAuth: Where are we going?...• Resource Owner or End-User: User and account owner of resource (the end-user) • Resource Server/Service Provider:Server hosting protected resources

SampleOAuthWorkflow

• UsingOAuth,youreCommerceservercannowtweetonbehalfoftheuserevenwhentheuserisnotloggedon.Howdoesthishappen?• First,theuserlogsintotheeCommerceserverwithhisaccountandeditshisaccountprofile.• Next,theeCommerceserverredirectstheusertoTwitter.• TheuserlogsontoTwitterandauthorizestheeCommerceservertotweetonherbehalf.• Then,wheneverordersarecompletetheeCommercetweetsalittlenoteabouthowawesometheeCommercecompanyis- evenwhentheuserisnotloggedontotheeCommerceserver.

10

Page 11: OAuth: Where are we going?...• Resource Owner or End-User: User and account owner of resource (the end-user) • Resource Server/Service Provider:Server hosting protected resources

HighLevelConcepts

• OAuthRoles(Resourceowner,resourceserver,clientapp,authorizationserver)• OAuthGrantTypes (authorizationcode, implicit,resourceownerpasswordcredentials,clientcredentials,extensions)• TokenTypes (refreshtoken,accesstoken)• EndpointTypes (resourceserver,authorizationserver,clientregistration,clientauthorization)

11

Page 12: OAuth: Where are we going?...• Resource Owner or End-User: User and account owner of resource (the end-user) • Resource Server/Service Provider:Server hosting protected resources

Terms• ResourceOwnerorEnd-User: Userandaccountownerofresource(theend-user)• ResourceServer/ServiceProvider: Serverhostingprotectedresourcesownedbytheend-user. Acceptsaccesstokensforprotectedresources.• AuthorizationServer/ServiceProvider. Serverissuingaccesstokenstoprovideotherclientsaccesstoprotectedresources.Oftensameserverasresourceserver.Oneauthorizationservermayissueaccesstokenstomany resourceservers.

12

Page 13: OAuth: Where are we going?...• Resource Owner or End-User: User and account owner of resource (the end-user) • Resource Server/Service Provider:Server hosting protected resources

Terms

• Client/Consumer: Applicationrequestingaccesstoprotectedresourceonbehalfofresourceowner(typicalclientsaremobileapplications, webbrowsers, desktopapplicationsorotherwebapplications). DependingontheOAuthworkflow,thebrowsermayuseanaccesstokendirectly(implicitgranttype)orredirecttheusertoanotherwebapplicationthatactsastheclientoftheservice(authorizationcodegranttype).

13

Page 14: OAuth: Where are we going?...• Resource Owner or End-User: User and account owner of resource (the end-user) • Resource Server/Service Provider:Server hosting protected resources

Terms• AccessToken: OAuthtokenusedtodirectlyaccessprotectedresourcesonbehalfofauserorservice.• RefreshToken: Refreshtokens,whengiventotheauthorizationserver,willprovideanewactiveaccesstoken.Refreshtokensthemselvescannotaccessresources. Whileaccesstokensshouldbeshortlived,refreshtokensarelonglivedorsimplyneverexpireuntiltheuserrevokesthem.Refreshtokensalsoprovidemorescalablepatterns.• ClientIdentifier:UniqueIDofeachclientgiventoclientbyauthorizationserver.• BearerToken: "Asecuritytokenwiththepropertythatanypartyinpossessionofthetoken(a"bearer")canusethetokeninanywaythatanyotherpartyinpossessionofitcan.Usingabearertokendoesnotrequireabearertoprovepossessionofcryptographickeymaterial(proof-of-possession)." -https://tools.ietf.org/html/rfc6750#section-1.2

14

Page 15: OAuth: Where are we going?...• Resource Owner or End-User: User and account owner of resource (the end-user) • Resource Server/Service Provider:Server hosting protected resources

AuthorizationServerSecurity

• TLSforeverything(Authenticity,Confidentiality,Integrity)• Authorizationserversshouldnotautomaticallyprocessrepeatauthorizationstopublicclientsunlesstheclientisvalidatedusingapre-registeredredirectURI(Section5.2.3.5).• Authorizationserverscanmitigatetherisksassociatedwithautomaticprocessingbylimitingthescopeofaccesstokensobtainedthroughautomatedapprovals(Section5.1.5.1).• Explainthescope(resourcesandthepermissions)theuserisabouttograntinanunderstandableway(Section5.2.4.2).• Narrowthescopeasmuchaspossible(Section5.1.5.1).• Don'tredirecttoaredirectURIiftheclientidentifierorredirectURIcan'tbeverified(Section5.2.3.5).

15

https://tools.ietf.org/html/rfc6819

Page 16: OAuth: Where are we going?...• Resource Owner or End-User: User and account owner of resource (the end-user) • Resource Server/Service Provider:Server hosting protected resources

OAuth2.0GrantTypes

• Youcanhidelonglivedtokenstokenfromtheuser(authorizationcodegrant)• Youcanonlyactivateashort-livedtokeninthebrowserwhentheuseriscurrentlyloggedon(implicitgrant)• Youcangrantandexposealong-livedtokensdirectlytotheuserviaatrustedclient(passwordgrant).• Youcangrantandexposealong-livedtokendirectlytootherservicesthatneedtoaccessdatanotassociatedwithaspecificuser(clientcredentialsgrant)

16

Page 17: OAuth: Where are we going?...• Resource Owner or End-User: User and account owner of resource (the end-user) • Resource Server/Service Provider:Server hosting protected resources

OAuth2.0AuthorizationCodeGrant

17

OAuth2.0AuthorizationCodeGrant

Page 18: OAuth: Where are we going?...• Resource Owner or End-User: User and account owner of resource (the end-user) • Resource Server/Service Provider:Server hosting protected resources

OAuth2.0AuthorizationCodeGrant

18

• TheUser(ResourceOwner)CredentialsareneverexposedtoClient

• TheUser(ResourceOwner)neverhasaccesstoactualaccesstoken

• TheClientapplicationcanusetheaccesstokenevenwhentheresourceownerisnotpresent

• AuthorizationCodeRefreshTokensareoftenlonglivedorpermanentuntiltheUser(ResourceOwner)revokesthisaccessthroughtheClientUI.

Page 19: OAuth: Where are we going?...• Resource Owner or End-User: User and account owner of resource (the end-user) • Resource Server/Service Provider:Server hosting protected resources

AuthorizationCodeVariables• Theclientstartsthe"authorizationcode"workflowbyredirectingtheusertotheauthorizationserverwiththerightrequestdata.Thisinitialclientrequestincludes:• response_type :thisisrequiredby"authorizationcode"granttypeandshouldcontainthevalue"code"• client_id:thisistheclientidentifierassignedtotheclientatclientregistrationtime.Thisisuniqueforeveryclientforauthorizationcodegrants.• scope:levelofaccessrequested,domainspecific• redirectionURI:Wheretheauthorizationserverredirectstheuserafteraccessisgrantedordenied

19

Page 20: OAuth: Where are we going?...• Resource Owner or End-User: User and account owner of resource (the end-user) • Resource Server/Service Provider:Server hosting protected resources

AuthorizationCodeGrantSecurity

• 4.4.1.1Threat:EavesdroppingorLeakingAuthorization"codes"(Referrerheaderleakage,logs,openredirect,browserhistory)• UseTLS,requirestrongauthenticationbetweenclientandserver,expirationtimeforaccesstokens,onlyallowoneusepertoken,considerrevokingclientsendinglotsofbadcodes,reducescopeoftokens,flushbrowsercache

• 4.4.1.2Threat:ObtainingAuthorization"codes"fromAuthorizationServerDatabase• ParameterizeyourF#$KINGQUERIES,storeaccesstokenswithaone-waymethodology,gooddatabasesecurity

• 4.4.1.3Threat:OnlineGuessingofAuthorization"codes"• Highentropytokens,strongclientauthentication,shortexpirationtime

• 4.4.1.5Threat:Authorization"code"Phishing• StandardPhishingdefense.Goodluck!Onephishandgameover.

20

https://tools.ietf.org/html/rfc6819#section-4.4.1

Page 21: OAuth: Where are we going?...• Resource Owner or End-User: User and account owner of resource (the end-user) • Resource Server/Service Provider:Server hosting protected resources

CSRFAttacksagainstOAuthPart11. Attacker assumesthatVictimiscurrentlyloggedinat

Consumer sitehttps://consumer-site.example/ (TheOAuthClient Application)

2. Attacker goesthroughregistrationandloginworkflowatConsumerSite https://consumer-site.example/login andusesthataccounttotriggeraOauth

workflowwiththeProviderService(TheOAuthauthorization/resourceserver)

1. ConsumerSiteredirectsattackertoProviderSite logininterface.ThisiscalledtheAuthorizationRequest.https://provider-site.example/login

2. Attacker successfullylogsinwithProviderSite3. Provider SiterespondswithredirectURLwhichcontainsthe

authorizationcodeinthecode parameter.thisiscalledtheAuthorizationGrant.http://consumer-

site.example/auth?code=1a2s3d4f5g6h

21

Page 22: OAuth: Where are we going?...• Resource Owner or End-User: User and account owner of resource (the end-user) • Resource Server/Service Provider:Server hosting protected resources

CSRFAttacksagainstOAuthPart23. InsteadofvisitingorredirectingtotheAuthorizationGrant

redirectURL,Attacker copiestheURLandplacesareferencetoitinanimagetagonawebpage(<img src="http://consumer-site.example/auth?code=1a2s3d4f5g6h"/>)(https://evil-page.example/)

4. Attacker getsVictimtovisithttps://evil-page.example/.1. ThisinturngetsVictim torequesttheAuthorizationGrant

URL(http://consumer-site.example/auth?code=1a2s34f5g6h)

2. ByvisitingtheAuthorizationGrantURL,theVictim hasnowauthorizedtheAttacker tohavefullauthorizedaccesstoVictim's accountonConsumer Site (https://consumer-site.example/).

22

Page 23: OAuth: Where are we going?...• Resource Owner or End-User: User and account owner of resource (the end-user) • Resource Server/Service Provider:Server hosting protected resources

OAuth2andavoidingCSRF

23

1 Consumer generatesuniquerandomstatevalue,andstoresitinserversidesessionvariable.JSONWebTokensaregoodforstatevalues.

2 Consumer sends"state"parameterwithAuthorizationRequest

3 Onsuccessfulauthorization,Provider Site includes"state"parameterinAuthorizationGrantredirectURI

4WhenVictim visitsredirectURI,the"state"parameteriscomparedagainstthe"state"parameterstoredinserversidesessionvariable.

Usethe"state"parameter!ItisessentiallyaCSRFtoken

Page 24: OAuth: Where are we going?...• Resource Owner or End-User: User and account owner of resource (the end-user) • Resource Server/Service Provider:Server hosting protected resources

OAuth2AuthorizationCodeFlowOpenRedirector:Attack1. VictimgoesthroughloginworkflowatConsumerSite

(https://consumer-site.example/login)usingProviderSiteforauthorization.

2. Attacker constructsanAuthorizationRequestURLforProviderSite1. redirect_uri issettohttps://evil-site.example/

3. Attacker eitherembedsevilURLinanimagetagorconstructsaclickablelinkatConsumerSite.

4. WhentheevilURLisloaded,theproviderwill302redirectbacktoredirect_uri sinceuser wasalreadyloggedin.

5. Whentheredirectoccurs,theevilsitecanreadtheHTTPReferrertogettheAuthorizationCode.

6. UsingthisAuthorizationCode,Attackercanloginasuser

Page 25: OAuth: Where are we going?...• Resource Owner or End-User: User and account owner of resource (the end-user) • Resource Server/Service Provider:Server hosting protected resources

OAuth2AuthorizationCodeFlowOpenRedirector:Remediation

1. Whitelistredirect_uri!2. ThereisnoneedforaProvidertorequiretheredirect_uri param!

Page 26: OAuth: Where are we going?...• Resource Owner or End-User: User and account owner of resource (the end-user) • Resource Server/Service Provider:Server hosting protected resources

OAuth2ImplicitFlowAccessTokenReuse:Attack1. VictimauthorizeswithEvilConsumer Site forProviderSite usingaccess_token2. AcmeWidgetsConsumerSiteusesImplicitFlowforauthentication.3. AttackerauthenticatesasVictimwiththeEvilConsumerSiteaccess_token using

https://acme-widgets.example/callback#access_token=access_token

"OneTokentoRuleThemAll"

Page 27: OAuth: Where are we going?...• Resource Owner or End-User: User and account owner of resource (the end-user) • Resource Server/Service Provider:Server hosting protected resources

OAuth2ImplicitFlowAccessTokenReuse:Remediation

1. OAuthshouldbeusedforauthorization,notauthentication!2. Validatethataccess_token belongstoyourclient_id viaproviderAPI

Page 28: OAuth: Where are we going?...• Resource Owner or End-User: User and account owner of resource (the end-user) • Resource Server/Service Provider:Server hosting protected resources

OAuth2.0:Summary

28

1. Holycrapthisiscrazy2. IttakesmassiveeffortstobuildsecureOAuth2solutions3. Thecorestandardbarelyaddressessecurity4. MajorproviderswithPHD'stospareareoveralldoinga

reasonablejobofbuildsecuresolutions5. Clientsareatriskbecausetheyarelikelytobuildless

securityimplementationsthanproviders6. Buckleup,readthethreatmodelseveraltimesandfollow

it'smanymanymanyrecommendations

Page 29: OAuth: Where are we going?...• Resource Owner or End-User: User and account owner of resource (the end-user) • Resource Server/Service Provider:Server hosting protected resources

OAuth:Summary

29

WhatisOAuth?

OAuthandCSRF

Redirection

TokenReuse

OAuthGrantTypes

Page 30: OAuth: Where are we going?...• Resource Owner or End-User: User and account owner of resource (the end-user) • Resource Server/Service Provider:Server hosting protected resources

ThankYou!

[email protected]