idnits 2.17.1 draft-ietf-oauth-security-topics-11.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- == There are 5 instances of lines with non-ascii characters in the document. == The page length should not exceed 58 lines per page, but there was 1 longer page, the longest (page 1) being 1772 lines Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- ** There are 5 instances of too long lines in the document, the longest one being 17 characters in excess of 72. ** The document seems to lack a both a reference to RFC 2119 and the recommended RFC 2119 boilerplate, even if it appears to use RFC 2119 keywords. RFC 2119 keyword, line 160: '...rization servers MUST utilize exact ma...' RFC 2119 keyword, line 166: '... Clients SHOULD avoid forwarding the...' RFC 2119 keyword, line 173: '... Clients MUST prevent CSRF and ensur...' RFC 2119 keyword, line 175: '...curely bound to the user agent, SHOULD...' RFC 2119 keyword, line 178: '...-up attacks, clients MUST only process...' (34 more instances...) Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year == Using lowercase 'not' together with uppercase 'MUST', 'SHALL', 'SHOULD', or 'RECOMMENDED' is not an accepted usage according to RFC 2119. Please use uppercase 'NOT' together with RFC 2119 keywords (if that is what you mean). Found 'SHOULD not' in this paragraph: The page rendered as a result of the OAuth authorization response and the authorization endpoint SHOULD not include third-party resources or links to external sites. == Using lowercase 'not' together with uppercase 'MUST', 'SHALL', 'SHOULD', or 'RECOMMENDED' is not an accepted usage according to RFC 2119. Please use uppercase 'NOT' together with RFC 2119 keywords (if that is what you mean). Found 'MUST not' in this paragraph: AS which redirect a request that potentially contains user credentials therefore MUST not use the HTTP 307 status code for redirection. If an HTTP redirection (and not, for example, JavaScript) is used for such a request, AS SHOULD use HTTP status code 303 "See Other". -- The document date (28 December 2018) is 1946 days in the past. Is this intentional? -- Found something which looks like a code comment -- if you have code sections in the document, please surround them with '' and '' lines. Checking references for intended status: Best Current Practice ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) == Unused Reference: 'I-D.ietf-tokbind-https' is defined on line 1540, but no explicit reference was found in the text ** Downref: Normative reference to an Experimental draft: draft-bradley-oauth-jwt-encoded-state (ref. 'I-D.bradley-oauth-jwt-encoded-state') == Outdated reference: A later version (-34) exists of draft-ietf-oauth-jwsreq-17 == Outdated reference: A later version (-17) exists of draft-ietf-oauth-mtls-12 == Outdated reference: A later version (-07) exists of draft-ietf-oauth-pop-key-distribution-04 == Outdated reference: A later version (-08) exists of draft-ietf-oauth-resource-indicators-01 == Outdated reference: A later version (-05) exists of draft-sakimura-oauth-jpop-04 -- Possible downref: Non-RFC (?) normative reference: ref. 'OpenID' ** Obsolete normative reference: RFC 2616 (Obsoleted by RFC 7230, RFC 7231, RFC 7232, RFC 7233, RFC 7234, RFC 7235) ** Downref: Normative reference to an Informational RFC: RFC 6819 ** Obsolete normative reference: RFC 7231 (Obsoleted by RFC 9110) Summary: 6 errors (**), 0 flaws (~~), 11 warnings (==), 3 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 Web Authorization Protocol T. Lodderstedt 3 Internet-Draft yes.com 4 Intended status: Best Current Practice J. Bradley 5 Expires: 1 July 2019 Yubico 6 A. Labunets 7 Facebook 8 D. Fett 9 yes.com 10 28 December 2018 12 OAuth 2.0 Security Best Current Practice 13 draft-ietf-oauth-security-topics-11 15 Abstract 17 This document describes best current security practice for OAuth 2.0. 18 It updates and extends the OAuth 2.0 Security Threat Model to 19 incorporate practical experiences gathered since OAuth 2.0 was 20 published and covers new threats relevant due to the broader 21 application of OAuth 2.0. 23 Status of This Memo 25 This Internet-Draft is submitted in full conformance with the 26 provisions of BCP 78 and BCP 79. 28 Internet-Drafts are working documents of the Internet Engineering 29 Task Force (IETF). Note that other groups may also distribute 30 working documents as Internet-Drafts. The list of current Internet- 31 Drafts is at https://datatracker.ietf.org/drafts/current/. 33 Internet-Drafts are draft documents valid for a maximum of six months 34 and may be updated, replaced, or obsoleted by other documents at any 35 time. It is inappropriate to use Internet-Drafts as reference 36 material or to cite them other than as "work in progress." 38 This Internet-Draft will expire on 1 July 2019. 40 Copyright Notice 42 Copyright (c) 2018 IETF Trust and the persons identified as the 43 document authors. All rights reserved. 45 This document is subject to BCP 78 and the IETF Trust's Legal 46 Provisions Relating to IETF Documents (http://trustee.ietf.org/ 47 license-info) in effect on the date of publication of this document. 48 Please review these documents carefully, as they describe your rights 49 and restrictions with respect to this document. Code Components 50 extracted from this document must include Simplified BSD License text 51 as described in Section 4.e of the Trust Legal Provisions and are 52 provided without warranty as described in the Simplified BSD License. 54 Table of Contents 56 1. Introduction 57 2. Recommendations 58 2.1. Protecting Redirect-Based Flows 59 2.1.1. Authorization Code Grant 60 2.1.2. Implicit Grant 61 2.2. Token Replay Prevention 62 2.3. Access Token Privilege Restriction 63 3. Attacks and Mitigations 64 3.1. Insufficient Redirect URI Validation 65 3.1.1. Attacks on Authorization Code Grant 66 3.1.2. Attacks on Implicit Grant 67 3.1.3. Proposed Countermeasures 68 3.2. Credential Leakage via Referrer Headers 69 3.2.1. Leakage from the OAuth client 70 3.2.2. Leakage from the Authorization Server 71 3.2.3. Consequences 72 3.2.4. Proposed Countermeasures 73 3.3. Attacks through the Browser History 74 3.3.1. Code in Browser History 75 3.3.2. Access Token in Browser History 76 3.4. Mix-Up 77 3.4.1. Attack Description 78 3.4.2. Countermeasures 79 3.5. Authorization Code Injection 80 3.5.1. Proposed Countermeasures 81 3.6. Access Token Injection 82 3.6.1. Proposed Countermeasures 83 3.7. Cross Site Request Forgery 84 3.7.1. Proposed Countermeasures 85 3.8. Access Token Leakage at the Resource Server 86 3.8.1. Access Token Phishing by Counterfeit 87 Resource Server 88 3.8.2. Compromised Resource Server 89 3.9. Open Redirection 90 3.9.1. Authorization Server as Open Redirector 91 3.9.2. Clients as Open Redirector 92 3.10. 307 Redirect 93 3.11. TLS Terminating Reverse Proxies 94 3.12. Refresh Token Protection 95 4. Acknowledgements 96 5. IANA Considerations 97 6. Security Considerations 98 7. Normative References 99 Appendix A. Document History 100 Authors' Addresses 102 1. Introduction 104 It's been a while since OAuth has been published in [RFC6749] and 105 [RFC6750]. Since publication, OAuth 2.0 has gotten massive traction 106 in the market and became the standard for API protection and, as 107 foundation of OpenID Connect [OpenID], identity providing. While 108 OAuth was used in a variety of scenarios and different kinds of 109 deployments, the following challenges could be observed: 111 * OAuth implementations are being attacked through known 112 implementation weaknesses and anti-patterns (CSRF, referrer 113 header). Although most of these threats are discussed in the 114 OAuth 2.0 Threat Model and Security Considerations [RFC6819], 115 continued exploitation demonstrates there may be a need for more 116 specific recommendations or that the existing mitigations are too 117 difficult to deploy. 119 * Technology has changed, e.g., the way browsers treat fragments in 120 some situations, which may change the implicit grant's underlying 121 security model. 123 * OAuth is used in much more dynamic setups than originally 124 anticipated, creating new challenges with respect to security. 125 Those challenges go beyond the original scope of [RFC6749], 126 [RFC6749], and [RFC6819]. 128 OAuth initially assumed a static relationship between client, 129 authorization server and resource servers. The URLs of AS and RS 130 were known to the client at deployment time and built an anchor for 131 the trust relationship among those parties. The validation whether 132 the client talks to a legitimate server was based on TLS server 133 authentication (see [RFC6819], Section 4.5.4). With the increasing 134 adoption of OAuth, this simple model dissolved and, in several 135 scenarios, was replaced by a dynamic establishment of the 136 relationship between clients on one side and the authorization and 137 resource servers of a particular deployment on the other side. This 138 way the same client could be used to access services of different 139 providers (in case of standard APIs, such as e-Mail or OpenID 140 Connect) or serves as a frontend to a particular tenant in a multi- 141 tenancy. Extensions of OAuth, such as [RFC7591] and [RFC8414] were 142 developed in order to support the usage of OAuth in dynamic 143 scenarios. As a challenge to the community, such usage scenarios 144 open up new attack angles, which are discussed in this document. 146 The remainder of the document is organized as follows: The next 147 section summarizes the most important recommendations of the OAuth 148 working group for every OAuth implementor. Afterwards, a detailed 149 analysis of the threats and implementation issues which can be found 150 in the wild today is given along with a discussion of potential 151 countermeasures. 153 2. Recommendations 155 This section describes the set of security mechanisms the OAuth 156 working group recommendeds to OAuth implementers. 158 2.1. Protecting Redirect-Based Flows 160 Authorization servers MUST utilize exact matching of client redirect 161 URIs against pre-registered URIs. This measure contributes to the 162 prevention of leakage of authorization codes and access tokens 163 (depending on the grant type). It also helps to detect mix-up 164 attacks. 166 Clients SHOULD avoid forwarding the user's browser to a URI obtained 167 from a query parameter since such a function could be utilized to 168 exfiltrate authorization codes and access tokens. If there is a 169 strong need for this kind of redirects, clients are advised to 170 implement appropriate countermeasures against open redirection, e.g., 171 as described by the OWASP [owasp]. 173 Clients MUST prevent CSRF and ensure that each authorization response 174 is only accepted once. One-time use CSRF tokens carried in the 175 "state" parameter, which are securely bound to the user agent, SHOULD 176 be used for that purpose. 178 In order to prevent mix-up attacks, clients MUST only process 179 redirect responses of the OAuth authorization server they send the 180 respective request to and from the same user agent this authorization 181 request was initiated with. Clients MUST memorize which 182 authorization server they sent an authorization request to and bind 183 this information to the user agent and ensure any sub-sequent 184 messages are sent to the same authorization server. Clients SHOULD 185 use AS-specific redirect URIs as a means to identify the AS a 186 particular response came from. 188 Note: [I-D.bradley-oauth-jwt-encoded-state] gives advice on how to 189 implement CSRF prevention and AS matching using signed JWTs in the 190 "state" parameter. 192 2.1.1. Authorization Code Grant 194 Clients utilizing the authorization grant type MUST use PKCE 195 [RFC7636] in order to (with the help of the authorization server) 196 detect and prevent attempts to inject (replay) authorization codes 197 into the authorization response. The PKCE challenges must be 198 transaction-specific and securely bound to the user agent in which 199 the transaction was started. OpenID Connect clients MAY use the 200 "nonce" parameter of the OpenID Connect authentication request as 201 specified in [OpenID] in conjunction with the corresponding ID Token 202 claim for the same purpose. 204 Note: although PKCE so far was recommended as a mechanism to protect 205 native apps, this advice applies to all kinds of OAuth clients, 206 including web applications. 208 Authorization servers MUST bind authorization codes to a certain 209 client and authenticate it using an appropriate mechanism (e.g. 210 client credentials or PKCE). 212 Authorization servers SHOULD furthermore consider the recommendations 213 given in [RFC6819], Section 4.4.1.1, on authorization code replay 214 prevention. 216 2.1.2. Implicit Grant 218 The implicit grant (response type "token") and other response types 219 causing the authorization server to issue access tokens in the 220 authorization response are vulnerable to access token leakage and 221 access token replay as described in Section 3.1, Section 3.2, 222 Section 3.3, and Section 3.6. 224 Moreover, no viable mechanism exists to cryptographically bind access 225 tokens issued in the authorization response to a certain client as it 226 is recommended in Section 2.2. This makes replay detection for such 227 access tokens at resource servers impossible. 229 In order to avoid these issues, clients SHOULD NOT use the implicit 230 grant (response type "token") or any other response type issuing 231 access tokens in the authorization response, such as "token id_token" 232 and "code token id_token", unless the issued access tokens are 233 sender-constrained and access token injection in the authorization 234 response is prevented. 236 A sender constrained access token scopes the applicability of an 237 access token to a certain sender. This sender is obliged to 238 demonstrate knowledge of a certain secret as prerequisite for the 239 acceptance of that token at the recipient (e.g., a resource server). 241 Clients SHOULD instead use the response type "code" (aka 242 authorization code grant type) as specified in Section 2.1.1 or any 243 other response type that causes the authorization server to issue 244 access tokens in the token response. This allows the authorization 245 server to detect replay attempts and generally reduces the attack 246 surface since access tokens are not exposed in URLs. It also allows 247 the authorization server to sender-constrain the issued tokens. 249 2.2. Token Replay Prevention 251 Authorization servers SHOULD use TLS-based methods for sender 252 constrained access tokens as described in Section 3.8.1.2, such as 253 token binding [I-D.ietf-oauth-token-binding] or Mutual TLS for OAuth 254 2.0 [I-D.ietf-oauth-mtls] in order to prevent token replay. It is 255 also recommended to use end-to-end TLS whenever possible. 257 2.3. Access Token Privilege Restriction 259 The privileges associated with an access token SHOULD be restricted 260 to the minimum required for the particular application or use case. 261 This prevents clients from exceeding the privileges authorized by the 262 resource owner. It also prevents users from exceeding their 263 privileges authorized by the respective security policy. Privilege 264 restrictions also limit the impact of token leakage although more 265 effective counter-measures are described in Section 2.2. 267 In particular, access tokens SHOULD be restricted to certain resource 268 servers, preferably to a single resource server. To put this into 269 effect, the authorization server associates the access token with 270 certain resource servers and every resource server is obliged to 271 verify for every request, whether the access token sent with that 272 request was meant to be used for that particular resource server. If 273 not, the resource server MUST refuse to serve the respective request. 274 Clients and authorization servers MAY utilize the parameters "scope" 275 or "resource" as specified in [RFC6749] and [I-D.ietf-oauth-resource- 276 indicators], respectively, to determine the resource server they want 277 to access. 279 Additionally, access tokens SHOULD be restricted to certain resources 280 and actions on resource servers or resources. To put this into 281 effect, the authorization server associates the access token with the 282 respective resource and actions and every resource server is obliged 283 to verify for every request, whether the access token sent with that 284 request was meant to be used for that particular action on the 285 particular resource. If not, the resource server must refuse to 286 serve the respective request. Clients and authorization servers MAY 287 utilize the parameter "scope" as specified in [RFC6749] to determine 288 those resources and/or actions. 290 3. Attacks and Mitigations 292 This section gives a detailed description of attacks on OAuth 293 implementations, along with potential countermeasures. This section 294 complements and enhances the description given in [RFC6819]. 296 3.1. Insufficient Redirect URI Validation 298 Some authorization servers allow clients to register redirect URI 299 patterns instead of complete redirect URIs. In those cases, the 300 authorization server, at runtime, matches the actual redirect URI 301 parameter value at the authorization endpoint against this pattern. 302 This approach allows clients to encode transaction state into 303 additional redirect URI parameters or to register just a single 304 pattern for multiple redirect URIs. As a downside, it turned out to 305 be more complex to implement and error prone to manage than exact 306 redirect URI matching. Several successful attacks have been observed 307 in the wild, which utilized flaws in the pattern matching 308 implementation or concrete configurations. Such a flaw effectively 309 breaks client identification or authentication (depending on grant 310 and client type) and allows the attacker to obtain an authorization 311 code or access token, either: 313 * by directly sending the user agent to a URI under the attackers 314 control or 316 * by exposing the OAuth credentials to an attacker by utilizing an 317 open redirector at the client in conjunction with the way user 318 agents handle URL fragments. 320 3.1.1. Attacks on Authorization Code Grant 322 For a public client using the grant type code, an attack would look 323 as follows: 325 Let's assume the redirect URL pattern "https://_.somesite.example/_" 326 had been registered for the client "s6BhdRkqt3". This pattern allows 327 redirect URIs pointing to any host residing in the domain 328 somesite.example. So if an attacker manages to establish a host or 329 subdomain in somesite.example he can impersonate the legitimate 330 client. Assume the attacker sets up the host 331 "evil.somesite.example". 333 1. The attacker needs to trick the user into opening a tampered URL 334 in his browser, which launches a page under the attacker's 335 control, say "https://www.evil.example" 336 (https://www.evil.example"). 338 This URL initiates an authorization request with the client id of 339 a legitimate client to the authorization endpoint. This is the 340 example authorization request (line breaks are for display 341 purposes only): 343 GET /authorize?response_type=code&client_id=s6BhdRkqt3&state=xyz 344 &redirect_uri=https%3A%2F%2Fevil.somesite.example%2Fcb HTTP/1.1 345 Host: server.somesite.example 347 2. The authorization server validates the redirect URI in order to 348 identify the client. Since the pattern allows arbitrary domains 349 host names in "somesite.example", the authorization request is 350 processed under the legitimate client's identity. This includes 351 the way the request for user consent is presented to the user. 352 If auto-approval is allowed (which is not recommended for public 353 clients according to [RFC6749]), the attack can be performed even 354 easier. 356 If the user does not recognize the attack, the code is issued and 357 directly sent to the attacker's client. 359 Since the attacker impersonated a public client, it can directly 360 exchange the code for tokens at the respective token endpoint. 362 Note: This attack will not directly work for confidential clients, 363 since the code exchange requires authentication with the legitimate 364 client's secret. The attacker will need to impersonate or utilize 365 the legitimate client to redeem the code (e.g., by performing a code 366 injection attack). This kind of injections is covered in 367 Section 3.5. 369 3.1.2. Attacks on Implicit Grant 371 The attack described above works for the implicit grant as well. If 372 the attacker is able to send the authorization response to a URI 373 under his control, he will directly get access to the fragment 374 carrying the access token. 376 Additionally, implicit clients can be subject to a further kind of 377 attacks. It utilizes the fact that user agents re-attach fragments 378 to the destination URL of a redirect if the location header does not 379 contain a fragment (see [RFC7231], Section 9.5). The attack 380 described here combines this behavior with the client as an open 381 redirector in order to get access to access tokens. This allows 382 circumvention even of strict redirect URI patterns (but not strict 383 URL matching!). 385 Assume the pattern for client "s6BhdRkqt3" is 386 "https://client.somesite.example/cb?*", i.e., any parameter is 387 allowed for redirects to "https://client.somesite.example/cb". 388 Unfortunately, the client exposes an open redirector. This endpoint 389 supports a parameter "redirect_to" which takes a target URL and will 390 send the browser to this URL using an HTTP Location header redirect 391 303. 393 1. Same as above, the attacker needs to trick the user into opening 394 a tampered URL in his browser, which launches a page under the 395 attacker's control, say "https://www.evil.example". 397 2. The URL initiates an authorization request, which is very similar 398 to the attack on the code flow. As differences, it utilizes the 399 open redirector by encoding 400 "redirect_to=https://client.evil.example" into the redirect URI 401 and it uses the response type "token" (line breaks are for 402 display purposes only): 404 GET /authorize?response_type=token&client_id=s6BhdRkqt3&state=xyz 405 &redirect_uri=https%3A%2F%2Fclient.somesite.example%2Fcb%26redirect_to 406 %253Dhttps%253A%252F%252Fclient.evil.example%252Fcb HTTP/1.1 407 Host: server.somesite.example 409 3. Since the redirect URI matches the registered pattern, the 410 authorization server allows the request and sends the resulting 411 access token with a 303 redirect (some response parameters are 412 omitted for better readability) 414 HTTP/1.1 303 See Other 415 Location: https://client.somesite.example/cb? 416 redirect_to%3Dhttps%3A%2F%2Fclient.evil.example%2Fcb 417 #access_token=2YotnFZFEjr1zCsicMWpAA&... 419 4. At example.com, the request arrives at the open redirector. It 420 will read the redirect parameter and will issue an HTTP 303 421 Location header redirect to the URL "https://client.evil.example/ 422 cb". 424 HTTP/1.1 303 See Other 425 Location: https://client.evil.example/cb 427 5. Since the redirector at client.somesite.example does not include 428 a fragment in the Location header, the user agent will re-attach 429 the original fragment 430 "#access_token=2YotnFZFEjr1zCsicMWpAA&..." to the URL and 431 will navigate to the following URL: 433 https://client.evil.example/cb#access_token=2YotnFZFEjr1zCsicMWpAA&... 435 6. The attacker's page at client.evil.example can access the 436 fragment and obtain the access token. 438 3.1.3. Proposed Countermeasures 440 The complexity of implementing and managing pattern matching 441 correctly obviously causes security issues. This document therefore 442 proposes to simplify the required logic and configuration by using 443 exact redirect URI matching only. This means the authorization 444 server must compare the two URIs using simple string comparison as 445 defined in [RFC3986], Section 6.2.1.. 447 Additional recommendations: 449 * Servers on which callbacks are hosted must not expose open 450 redirectors (see (#Open.Redirection)). 452 * Clients MAY drop fragments via intermediary URLs with "fix 453 fragments" (see [fb_fragments]) to prevent the user agent from 454 appending any unintended fragments. 456 * Clients SHOULD use the authorization code response type instead of 457 response types causing access token issuance at the authorization 458 endpoint. This offers countermeasures against reuse of leaked 459 credentials through the exchange process with the authorization 460 server and token replay through certificate binding of the access 461 tokens. 463 As an alternative to exact redirect URI matching, the AS could also 464 authenticate clients, e.g., using [I-D.ietf-oauth-jwsreq]. 466 3.2. Credential Leakage via Referrer Headers 468 Authorization codes or values of "state" can unintentionally be 469 disclosed to attackers through the referrer header, by leaking either 470 from a client's web site or from an AS's web site. Note: even if 471 specified otherwise in [RFC2616], section 14.36, the same may happen 472 to access tokens conveyed in URI fragments due to browser 473 implementation issues as illustrated by Chromium Issue 168213 474 [bug.chromium]. 476 3.2.1. Leakage from the OAuth client 478 This requires that the client, as a result of a successful 479 authorization request, renders a page that 481 * contains links to other pages under the attacker's control (ads, 482 faq, ...) and a user clicks on such a link, or 484 * includes third-party content (iframes, images, etc.) for example 485 if the page contains user-generated content (blog). 487 As soon as the browser navigates to the attacker's page or loads the 488 third-party content, the attacker receives the authorization response 489 URL and can extract "code", "access token", or "state". 491 3.2.2. Leakage from the Authorization Server 493 In a similar way, an attacker can learn "state" if the authorization 494 endpoint at the authorization server contains links or third-party 495 content as above. 497 3.2.3. Consequences 499 An attacker that learns a valid code or access token through a 500 referrer header can perform the attacks as described in 501 Section 3.1.1, Section 3.5, and Section 3.6. If the attacker learns 502 "state", the CSRF protection achieved by using "state" is lost, 503 resulting in CSRF attacks as described in [RFC6819], 504 Section 4.4.1.8.. 506 3.2.4. Proposed Countermeasures 508 The page rendered as a result of the OAuth authorization response and 509 the authorization endpoint SHOULD not include third-party resources 510 or links to external sites. 512 The following measures further reduce the chances of a successful 513 attack: 515 * Bind authorization code to a confidential client or PKCE 516 challenge. In this case, the attacker lacks the secret to request 517 the code exchange. 519 * Authorization codes SHOULD be invalidated by the AS after their 520 first use at the token endpoint. For example, if an AS 521 invalidated the code after the legitimate client redeemed it, the 522 attacker would fail exchanging this code later. (This does not 523 mitigate the attack if the attacker manages to exchange the code 524 for a token before the legitimate client does so.) 526 * The "state" value SHOULD be invalidated by the client after its 527 first use at the redirection endpoint. If this is implemented, 528 and an attacker receives a token through the referrer header from 529 the client's web site, the "state" was already used, invalidated 530 by the client and cannot be used again by the attacker. (This 531 does not help if the state leaks from 532 the AS's web site, since then the state has not been used at the redirection 534 endpoint at the client yet.) 536 * Suppress the referrer header by adding the attribute 537 "rel="noreferrer"" to HTML links or by applying an appropriate 538 Referrer Policy [webappsec-referrer-policy] to the document 539 (either as part of the "referrer" meta attribute or by setting a 540 Referrer-Policy header). 542 * Use authorization code instead of response types causing access 543 token issuance from the authorization endpoint. This provides 544 countermeasures against leakage on the OAuth protocol level 545 through the code exchange process with the authorization server. 547 * Additionally, one might use the form post response mode instead of 548 redirect for authorization response (see [oauth-v2-form-post- 549 response-mode]). 551 3.3. Attacks through the Browser History 553 Authorization codes and access tokens can end up in the browser's 554 history of visited URLs, enabling the attacks described in the 555 following. 557 3.3.1. Code in Browser History 559 When a browser navigates to "client.example/ 560 redirection_endpoint?code=abcd" as a result of a redirect from a 561 provider's authorization endpoint, the URL including the 562 authorization code may end up in the browser's history. An attacker 563 with access to the device could obtain the code and try to replay it. 565 Proposed countermeasures: 567 * Authorization code replay prevention as described in [RFC6819], 568 Section 4.4.1.1, and Section 3.5 570 * Use form post response mode instead of redirect for authorization 571 response (see [oauth-v2-form-post-response-mode]) 573 3.3.2. Access Token in Browser History 575 An access token may end up in the browser history if a a client or 576 just a web site, which already has a token, deliberately navigates to 577 a page like "provider.com/get_user_profile?access_token=abcdef.". 578 Actually [RFC6750] discourages this practice and asks to transfer 579 tokens via a header, but in practice web sites often just pass access 580 token in query parameters. 582 In case of implicit grant, a URL like "client.example/ 583 redirection_endpoint#access_token=abcdef" may also end up in the 584 browser history as a result of a redirect from a provider's 585 authorization endpoint. 587 Proposed countermeasures: 589 * Replace implicit flow with postmessage communication or the 590 authorization code grant 592 * Never pass access tokens in URL query parameters 594 3.4. Mix-Up 596 Mix-up is an attack on scenarios where an OAuth client interacts with 597 multiple authorization servers, as is usually the case when dynamic 598 registration is used. The goal of the attack is to obtain an 599 authorization code or an access token by tricking the client into 600 sending those credentials to the attacker instead of using them at 601 the respective endpoint at the authorization/resource server. 603 3.4.1. Attack Description 605 For a detailed attack description, refer to [arXiv.1601.01229] and 606 [I-D.ietf-oauth-mix-up-mitigation]. The description here closely 607 follows [arXiv.1601.01229], with variants of the attack outlined 608 below. 610 Preconditions: For the attack to work, we assume that 612 * the implicit or authorization code grant are used with multiple AS 613 of which one is considered "honest" (H-AS) and one is operated by 614 the attacker (A-AS), 616 * the client stores the AS chosen by the user in a session bound to 617 the user's browser and uses the same redirection endpoint URI for 618 each AS, and 620 * the attacker can manipulate the first request/response pair from a 621 user's browser to the client (in which the user selects a certain 622 AS and is then redirected by the client to that AS). 624 Some of the attack variants described below require different 625 preconditions. 627 In the following, we assume that the client is registered with H-AS 628 (URI: "https://honest.as.example" (https://honest.as.example"), 629 client id: 7ZGZldHQ) and with A-AS (URI: "https://attacker.example" 630 (https://attacker.example"), client id: 666RVZJTA). 632 Attack on the authorization code grant: 634 1. The user selects to start the grant using H-AS (e.g., by clicking 635 on a button at the client's website). 637 2. The attacker intercepts this request and changes the user's 638 selection to "A-AS". 640 3. The client stores in the user's session that the user selected 641 "A-AS" and redirects the user to A-AS's authorization endpoint by 642 sending the following response: 644 HTTP/1.1 303 See Other 645 Location: https://attacker.example/authorize?response_type=code&client_id=666RVZJTA 647 4. Now the attacker intercepts this response and changes the 648 redirection such that the user is being redirected to H-AS. The 649 attacker also replaces the client id of the client at A-AS with 650 the client's id at H-AS, resulting in the following response 651 being sent to the browser: 653 HTTP/1.1 303 See Other 654 Location: https://honest.as.example/authorize?response_type=code&client_id=7ZGZldHQ 656 5. Now, the user authorizes the client to access her resources at 657 H-AS. H-AS issues a code and sends it (via the browser) back to 658 the client. 660 6. Since the client still assumes that the code was issued by A-AS, 661 it will try to redeem the code at A-AS's token endpoint. 663 7. The attacker therefore obtains code and can either exchange the 664 code for an access token (for public clients) or perform a code 665 injection attack as described in Section 3.5. 667 Variants: 669 * *Implicit Grant*: In the implicit grant, the attacker receives an 670 access token instead of the code; the rest of the attack works as 671 above. 673 * *Mix-Up Without Interception*: A variant of the above attack works 674 even if the first request/response pair cannot be intercepted (for 675 example, because TLS is used to protect these messages): Here, we 676 assume that the user wants to start the grant using A-AS (and not 677 H-AS). After the client redirected the user to the authorization 678 endpoint at A-AS, the attacker immediately redirects the user to 679 H-AS (changing the client id "7ZGZldHQ"). (A vigilant user might 680 at this point detect that she intended to use A-AS instead of 681 H-AS.) The attack now proceeds exactly as in step of the 683 attack description above. 686 * *Per-AS Redirect URIs*: If clients use different redirect URIs for 687 different ASs, do not store the selected AS in the user's session, 688 and ASs do not check the redirect URIs properly, attackers can 689 mount an attack called "Cross-Social Network Request Forgery". 690 Refer to [oauth_security_jcs_14] for details. 692 * *OpenID Connect*: There are several variants that can be used to 693 attack OpenID Connect. They are described in detail in 694 [arXiv.1704.08539], Appendix A, and [arXiv.1508.04324v2], 695 Section 6 ("Malicious Endpoints Attacks"). 697 3.4.2. Countermeasures 699 In scenarios where an OAuth client interacts with multiple 700 authorization servers, clients MUST prevent mix-up attacks. 702 Potential countermeasures: 704 * Configure authorization servers to return an AS identitifier 705 ("iss") and the "client_id" for which a code or token was issued 706 in the authorization response. This enables clients to compare 707 this data to their own client id and the "iss" identifier of the 708 AS it believed it sent the user agent to. This mitigation is 709 discussed in detail in [I-D.ietf-oauth-mix-up-mitigation]. In 710 OpenID Connect, if an ID token is returned in the authorization 711 response, it carries client id and issuer. It can be used for 712 this mitigation. 714 * As it can be seen in the preconditions of the attacks above, 715 clients can prevent mix-up attack by (1) using AS-specific 716 redirect URIs with exact redirect URI matching, (2) storing, for 717 each authorization request, the intended AS, and (3) comparing the 718 intended AS with the actual redirect URI where the authorization 719 response was received. 721 3.5. Authorization Code Injection 723 In such an attack, the adversary attempts to inject a stolen 724 authorization code into a legitimate client on a device under his 725 control. In the simplest case, the attacker would want to use the 726 code in his own client. But there are situations where this might 727 not be possible or intended. Examples are: 729 * The attacker wants to access certain functions in this particular 730 client. As an example, the attacker wants to impersonate his 731 victim in a certain app or on a certain web site. 733 * The code is bound to a particular confidential client and the 734 attacker is unable to obtain the required client credentials to 735 redeem the code himself. 737 * The authorization or resource servers are limited to certain 738 networks, the attackers is unable to access directly. 740 How does an attack look like? 742 1. The attacker obtains an authorization code by performing any of 743 the attacks described above. 745 2. It performs a regular OAuth authorization process with the 746 legitimate client on his device. 748 3. The attacker injects the stolen authorization code in the 749 response of the authorization server to the legitimate client. 751 4. The client sends the code to the authorization server's token 752 endpoint, along with client id, client secret and actual 753 "redirect_uri". 755 5. The authorization server checks the client secret, whether the 756 code was issued to the particular client and whether the actual 757 redirect URI matches the "redirect_uri" parameter (see 758 [RFC6749]). 760 6. If all checks succeed, the authorization server issues access and 761 other tokens to the client, so now the attacker is able to 762 impersonate the legitimate user. 764 Obviously, the check in step (5.) will fail, if the code was issued 765 to another client id, e.g., a client set up by the attacker. The 766 check will also fail if the authorization code was already redeemed 767 by the legitimate user and was one-time use only. 769 An attempt to inject a code obtained via a malware pretending to be 770 the legitimate client should also be detected, if the authorization 771 server stored the complete redirect URI used in the authorization 772 request and compares it with the redirect_uri parameter. 774 [RFC6749], Section 4.1.3, requires the AS to "... ensure that the 775 "redirect_uri" parameter is present if the "redirect_uri" parameter 776 was included in the initial authorization request as described in 777 Section 4.1.1, and if included ensure that their values are 778 identical.". In the attack scenario described above, the legitimate 779 client would use the correct redirect URI it always uses for 780 authorization requests. But this URI would not match the tampered 781 redirect URI used by the attacker (otherwise, the redirect would not 782 land at the attackers page). So the authorization server would 783 detect the attack and refuse to exchange the code. 785 Note: this check could also detect attempt to inject a code, which 786 had been obtained from another instance of the same client on another 787 device, if certain conditions are fulfilled: 789 * the redirect URI itself needs to contain a nonce or another kind 790 of one-time use, secret data and 792 * the client has bound this data to this particular instance. 794 But this approach conflicts with the idea to enforce exact redirect 795 URI matching at the authorization endpoint. Moreover, it has been 796 observed that providers very often ignore the redirect_uri check 797 requirement at this stage, maybe because it doesn't seem to be 798 security-critical from reading the spec. 800 Other providers just pattern match the redirect_uri parameter against 801 the registered redirect URI pattern. This saves the authorization 802 server from storing the link between the actual redirect URI and the 803 respective authorization code for every transaction. But this kind 804 of check obviously does not fulfill the intent of the spec, since the 805 tampered redirect URI is not considered. So any attempt to inject a 806 code obtained using the "client_id" of a legitimate client or by 807 utilizing the legitimate client on another device won't be detected 808 in the respective deployments. 810 It is also assumed that the requirements defined in [RFC6749], 811 Section 4.1.3, increase client implementation complexity as clients 812 need to memorize or re-construct the correct redirect URI for the 813 call to the tokens endpoint. 815 This document therefore recommends to instead bind every 816 authorization code to a certain client instance on a certain device 817 (or in a certain user agent) in the context of a certain transaction. 819 3.5.1. Proposed Countermeasures 821 There are multiple technical solutions to achieve this goal: 823 * *Nonce*: OpenID Connect's existing "nonce" parameter could be used 824 for this purpose. The nonce value is one-time use and created by 825 the client. The client is supposed to bind it to the user agent 826 session and sends it with the initial request to the OpenId 827 Provider (OP). The OP associates the nonce to the authorization 828 code and attests this binding in the ID token, which is issued as 829 part of the code exchange at the token endpoint. If an attacker 830 injected an authorization code in the authorization response, the 831 nonce value in the client session and the nonce value in the ID 832 token will not match and the attack is detected. The assumption 833 is that an attacker cannot get hold of the user agent state on the 834 victims device, where he has stolen the respective authorization 835 code. The main advantage of this option is that Nonce is an 836 existing feature used in the wild. On the other hand, leveraging 837 Nonce by the broader OAuth community would require AS and client 838 to adopt ID Tokens. 840 * *Code-bound State*: The "state" parameter as specified in 841 [RFC6749] could be used similarly to what is described above. 842 This would require to add a further parameter "state" to the code 843 exchange token endpoint request. The authorization server would 844 then compare the "state" value it associated with the code and the 845 "state" value in the parameter. If those values do not match, it 846 is considered an attack and the request fails. The advantage of 847 this approach would be to utilize an existing OAuth parameter. 848 But it would also mean to re-interpret the purpose of "state" and 849 to extend the token endpoint request. 851 * *PKCE*: The PKCE parameter "challenge" along with the 852 corresponding "verifier" as specified in [RFC7636] could be used 853 in the same way as "nonce" or "state". In contrast to its 854 original intention, the verifier check would fail although the 855 client uses its correct verifier but the code is associated with a 856 challenge, which does not match. PKCE is a deployed OAuth 857 feature, even though it is used today to secure native apps, only. 859 * *Token Binding*: Token binding [I-D.ietf-oauth-token-binding] 860 could also be used. In this case, the code would need to be bound 861 to two legs, between user agent and AS and the user agent and the 862 client. This requires further data (extension to response) to 863 manifest binding id for particular code. Token binding is 864 promising as a secure and convenient mechanism (due to its browser 865 integration). As a challenge, it requires broad browser support 866 and use with native apps is still under discussion. 868 * *per instance client id/secret*: One could use per instance 869 "client_id" and secrets and bind the code to the respective 870 "client_id". Unfortunately, this does not fit into the web 871 application programming model (would need to use per user client 872 ids). 874 PKCE seems to be the most obvious solution for OAuth clients as it 875 available and effectively used today for similar purposes for OAuth 876 native apps whereas "nonce" is appropriate for OpenId Connect 877 clients. 879 Note on pre-warmed secrets: An attacker can circumvent the 880 countermeasures described above if he is able to create or capture 881 the respective secret or code_challenge on a device under his 882 control, which is then used in the victim's authorization request. 884 Exact redirect URI matching of authorization requests can prevent the 885 attacker from using the pre-warmed secret in the faked authorization 886 transaction on the victim's device. 888 Unfortunately, it does not work for all kinds of OAuth clients. It 889 is effective for web and JS apps and for native apps with claimed 890 URLs. Attacks on native apps using custom schemes or redirect URIs 891 on localhost cannot be prevented this way, except if the AS enforces 892 one-time use for PKCE verifier or "nonce" values. 894 3.6. Access Token Injection 896 In such an attack, the adversary attempts to inject a stolen access 897 token into a legitimate client on a device under his control. This 898 will typically happen if the attacker wants to utilize a leaked 899 access token to impersonate a user in a certain client. 901 To conduct the attack, the adversary starts an OAuth flow with the 902 client and modifies the authorization response by replacing the 903 access token issued by the authorization server or directly makes up 904 an authorization server response including the leaked access token. 905 Since the response includes the state value generated by the client 906 for this particular transaction, the client does not treat the 907 response as a CSRF and will use the access token injected by the 908 attacker. 910 3.6.1. Proposed Countermeasures 912 There is no way to detect such an injection attack on the OAuth 913 protocol level, since the token is issued without any binding to the 914 transaction or the particular user agent. 916 The recommendation is therefore to use the authorization code grant 917 type instead of relying on response types issuing acess tokens at the 918 authorization endpoint. Code injection can be detected using one of 919 the countermeasures discussed in Section 3.5. 921 3.7. Cross Site Request Forgery 923 An attacker might attempt to inject a request to the redirect URI of 924 the legitimate client on the victim's device, e.g., to cause the 925 client to access resources under the attacker's control. 927 3.7.1. Proposed Countermeasures 929 Standard CSRF defenses should be used to protect the redirection 930 endpoint, for example: 932 * *CSRF Tokens*: Use of CSRF tokens which are bound to the user 933 agent and passed in the "state" parameter to the authorization 934 server. 936 * *Origin Header*: The Origin header can be used to detect and 937 prevent CSRF attacks. Since this feature, at the time of writing, 938 is not consistently supported by all browsers, CSRF tokens should 939 be used in addition to Origin header checking. 941 For more details see [owasp_csrf]. 943 3.8. Access Token Leakage at the Resource Server 945 Access tokens can leak from a resource server under certain 946 circumstances. 948 3.8.1. Access Token Phishing by Counterfeit Resource Server 950 An attacker may setup his own resource server and trick a client into 951 sending access tokens to it, which are valid for other resource 952 servers. If the client sends a valid access token to this 953 counterfeit resource server, the attacker in turn may use that token 954 to access other services on behalf of the resource owner. 956 This attack assumes the client is not bound to a certain resource 957 server (and the respective URL) at development time, but client 958 instances are configured with an resource server's URL at runtime. 959 This kind of late binding is typical in situations where the client 960 uses a standard API, e.g., for e-Mail, calendar, health, or banking 961 and is configured by an user or administrator for the standard-based 962 service, this particular user or company uses. 964 There are several potential mitigation strategies, which will be 965 discussed in the following sections. 967 3.8.1.1. Metadata 969 An authorization server could provide the client with additional 970 information about the location where it is safe to use its access 971 tokens. 973 In the simplest form, this would require the AS to publish a list of 974 its known resource servers, illustrated in the following example 975 using a metadata parameter "resource_servers": 977 HTTP/1.1 200 OK Content-Type: application/json 979 { 980 "issuer":"https://server.somesite.example", 981 "authorization_endpoint": 982 "https://server.somesite.example/authorize", 983 “resource_servers”:[ 984 “email.somesite.example”, 985 ”storage.somesite.example”, 986 ”video.somesite.example”] 987 ... 988 } 990 The AS could also return the URL(s) an access token is good for in 991 the token response, illustrated by the example return parameter 992 "access_token_resource_server": 994 HTTP/1.1 200 OK 995 Content-Type: application/json;charset=UTF-8 996 Cache-Control: no-store 997 Pragma: no-cache 999 { 1000 "access_token":"2YotnFZFEjr1zCsicMWpAA", 1001 “access_token_resource_server”: 1002 "https://hostedresource.somesite.example/path1", 1003 ... 1004 } 1006 This mitigation strategy would rely on the client to enforce the 1007 security policy and to only send access tokens to legitimate 1008 destinations. Results of OAuth related security research (see for 1009 example [#@!oauth_security_ubc] and [#!oauth_security_cmu]) indicate 1010 a large portion of client implementations do not or fail to properly 1011 implement security controls, like "state" checks. So relying on 1012 clients to prevent access token phishing is likely to fail as well. 1013 Moreover given the ratio of clients to authorization and resource 1014 servers, it is considered the more viable approach to move as much as 1015 possible security-related logic to those entities. Clearly, the 1016 client has to contribute to the overall security. But there are 1017 alternative countermeasures, as described in the next sections, which 1018 provide a better balance between the involved parties. 1020 3.8.1.2. Sender Constrained Access Tokens 1022 As the name suggests, sender constrained access token scope the 1023 applicability of an access token to a certain sender. This sender is 1024 obliged to demonstrate knowledge of a certain secret as prerequisite 1025 for the acceptance of that token at a resource server. 1027 A typical flow looks like this: 1029 1. The authorization server associates data with the access token 1030 which binds this particular token to a certain client. The 1031 binding can utilize the client identity, but in most cases the AS 1032 utilizes key material (or data derived from the key material) 1033 known to the client. 1035 2. This key material must be distributed somehow. Either the key 1036 material already exists before the AS creates the binding or the 1037 AS creates ephemeral keys. The way pre-existing key material is 1038 distributed varies among the different approaches. For example, 1039 X.509 Certificates can be used in which case the distribution 1040 happens explicitly during the enrollment process. Or the key 1041 material is created and distributed at the TLS layer, in which 1042 case it might automatically happens during the setup of a TLS 1043 connection. 1045 3. The RS must implement the actual proof of possession check. This 1046 is typically done on the application level, it may utilize 1047 capabilities of the transport layer (e.g., TLS). Note: replay 1048 prevention is required as well! 1050 There exists several proposals to demonstrate the proof of possession 1051 in the scope of the OAuth working group: 1053 * [I-D.ietf-oauth-token-binding]: In this approach, an access tokens 1054 is, via the so-called token binding id, bound to key material 1055 representing a long term association between a client and a 1056 certain TLS host. Negotiation of the key material and proof of 1057 possession in the context of a TLS handshake is taken care of by 1058 the TLS stack. The client needs to determine the token binding id 1059 of the target resource server and pass this data to the access 1060 token request. The authorization server than associates the 1061 access token with this id. The resource server checks on every 1062 invocation that the token binding id of the active TLS connection 1063 and the token binding id of associated with the access token 1064 match. Since all crypto-related functions are covered by the TLS 1065 stack, this approach is very client developer friendly. As a 1066 prerequisite, token binding as described in [I-D.ietf-tokbind- 1067 https] (including federated token bindings) must be supported on 1068 all ends (client, authorization server, resource server). 1070 * [I-D.ietf-oauth-mtls]: The approach as specified in this document 1071 allow use of mutual TLS for both client authentication and sender 1072 constraint access tokens. For the purpose of sender constraint 1073 access tokens, the client is identified towards the resource 1074 server by the fingerprint of its public key. During processing of 1075 an access token request, the authorization server obtains the 1076 client's public key from the TLS stack and associates its 1077 fingerprint with the respective access tokens. The resource 1078 server in the same way obtains the public key from the TLS stack 1079 and compares its fingerprint with the fingerprint associated with 1080 the access token. 1082 * [I-D.ietf-oauth-signed-http-request] specifies an approach to sign 1083 HTTP requests. It utilizes [I-D.ietf-oauth-pop-key-distribution] 1084 and represents the elements of the signature in a JSON object. 1085 The signature is built using JWS. The mechanism has built-in 1086 support for signing of HTTP method, query parameters and headers. 1087 It also incorporates a timestamp as basis for replay prevention. 1089 * [I-D.sakimura-oauth-jpop]: this draft describes different ways to 1090 constrain access token usage, namely TLS or request signing. 1091 Note: Since the authors of this draft contributed the TLS-related 1092 proposal to [I-D.ietf-oauth-mtls], this document only considers 1093 the request signing part. For request signing, the draft utilizes 1094 [I-D.ietf-oauth-pop-key-distribution] and [RFC7800]. The 1095 signature data is represented in a JWT and JWS is used for 1096 signing. Replay prevention is provided by building the signature 1097 over a server-provided nonce, client-provided nonce and a nonce 1098 counter. 1100 [I-D.ietf-oauth-mtls] and [I-D.ietf-oauth-token-binding] are built on 1101 top of TLS and this way continue the successful OAuth 2.0 philosophy 1102 to leverage TLS to secure OAuth wherever possible. Both mechanisms 1103 allow prevention of access token leakage in a fairly client developer 1104 friendly way. 1106 There are some differences between both approaches: To start with, in 1107 [I-D.ietf-oauth-token-binding] all key material is automatically 1108 managed by the TLS stack whereas [I-D.ietf-oauth-mtls] requires the 1109 developer to create and maintain the key pairs and respective 1110 certificates. Use of self-signed certificates, which is supported by 1111 the draft, significantly reduce the complexity of this task. 1112 Furthermore, [I-D.ietf-oauth-token-binding] allows to use different 1113 key pairs for different resource servers, which is a privacy benefit. 1114 On the other hand, [I-D.ietf-oauth-mtls] only requires widely 1115 deployed TLS features, which means it might be easier to adopt in the 1116 short term. 1118 Application level signing approaches, like [I-D.ietf-oauth-signed- 1119 http-request] and [I-D.sakimura-oauth-jpop] have been debated for a 1120 long time in the OAuth working group without a clear outcome. 1122 As one advantage, application-level signing allows for end-to-end 1123 protection including non-repudiation even if the TLS connection is 1124 terminated between client and resource server. But deployment 1125 experiences have revealed challenges regarding robustness (e.g., 1126 reproduction of the signature base string including correct URL) as 1127 well as state management (e.g., replay prevention). 1129 This document therefore recommends implementors to consider one of 1130 TLS-based approaches wherever possible. 1132 3.8.1.3. Audience Restricted Access Tokens 1134 An audience restriction essentially restricts the resource server a 1135 particular access token can be used at. The authorization server 1136 associates the access token with a certain resource server and every 1137 resource server is obliged to verify for every request, whether the 1138 access token sent with that request was meant to be used at the 1139 particular resource server. If not, the resource server must refuse 1140 to serve the respective request. In the general case, audience 1141 restrictions limit the impact of a token leakage. In the case of a 1142 counterfeit resource server, it may (as described see below) also 1143 prevent abuse of the phished access token at the legitimate resource 1144 server. 1146 The audience can basically be expressed using logical names or 1147 physical addresses (like URLs). In order to prevent phishing, it is 1148 necessary to use the actual URL the client will send requests to. In 1149 the phishing case, this URL will point to the counterfeit resource 1150 server. If the attacker tries to use the access token at the 1151 legitimate resource server (which has a different URL), the resource 1152 server will detect the mismatch (wrong audience) and refuse to serve 1153 the request. 1155 In deployments where the authorization server knows the URLs of all 1156 resource servers, the authorization server may just refuse to issue 1157 access tokens for unknown resource server URLs. 1159 The client needs to tell the authorization server, at which URL it 1160 will use the access token it is requesting. It could use the 1161 mechanism proposed [I-D.ietf-oauth-resource-indicators] or encode the 1162 information in the scope value. 1164 Instead of the URL, it is also possible to utilize the fingerprint of 1165 the resource server's X.509 certificate as audience value. This 1166 variant would also allow to detect an attempt to spoof the legit 1167 resource server's URL by using a valid TLS certificate obtained from 1168 a different CA. It might also be considered a privacy benefit to 1169 hide the resource server URL from the authorization server. 1171 Audience restriction seems easy to use since it does not require any 1172 crypto on the client side. But since every access token is bound to 1173 a certain resource server, the client also needs to obtain different 1174 RS-specific access tokens, if it wants to access several resource 1175 services. [I-D.ietf-oauth-token-binding] has the same property, 1176 since different token binding ids must be associated with the access 1177 token. [I-D.ietf-oauth-mtls] on the other hand allows a client to 1178 use the access token at multiple resource servers. 1180 It shall be noted that audience restrictions, or generally speaking 1181 an indication by the client to the authorization server where it 1182 wants to use the access token, has additional benefits beyond the 1183 scope of token leakage prevention. It allows the authorization 1184 server to create different access token whose format and content is 1185 specifically minted for the respective server. This has huge 1186 functional and privacy advantages in deployments using structured 1187 access tokens. 1189 3.8.2. Compromised Resource Server 1191 An attacker may compromise a resource server in order to get access 1192 to its resources and other resources of the respective deployment. 1193 Such a compromise may range from partial access to the system, e.g., 1194 its logfiles, to full control of the respective server. 1196 If the attacker was able to take over full control including shell 1197 access it will be able to circumvent all controls in place and access 1198 resources without access control. It will also get access to access 1199 tokens, which are sent to the compromised system and which 1200 potentially are valid for access to other resource servers as well. 1201 Even if the attacker "only" is able to access logfiles or databases 1202 of the server system, it may get access to valid access tokens. 1204 Preventing server breaches by way of hardening and monitoring server 1205 systems is considered a standard operational procedure and therefore 1206 out of scope of this document. This section will focus on the impact 1207 of such breaches on OAuth-related parts of the ecosystem, which is 1208 the replay of captured access tokens on the compromised resource 1209 server and other resource servers of the respective deployment. 1211 The following measures should be taken into account by implementors 1212 in order to cope with access token replay: 1214 * The resource server must treat access tokens like any other 1215 credentials. It is considered good practice to not log them and 1216 not to store them in plain text. 1218 * Sender constraint access tokens as described in Section 3.8.1.2 1219 will prevent the attacker from replaying the access tokens on 1220 other resource servers. Depending on the severity of the 1221 penetration, it will also prevent replay on the compromised 1222 system. 1224 * Audience restriction as described in Section 3.8.1.3 may be used 1225 to prevent replay of captured access tokens on other resource 1226 servers. 1228 3.9. Open Redirection 1230 The following attacks can occur when an AS or client has an open 1231 redirector, i.e., a URL which causes an HTTP redirect to an attacker- 1232 controlled web site. 1234 3.9.1. Authorization Server as Open Redirector 1236 Attackers could try to utilize a user's trust in the authorization 1237 server (and its URL in particular) for performing phishing attacks. 1239 [RFC6749], Section 4.1.2.1, already prevents open redirects by 1240 stating the AS MUST NOT automatically redirect the user agent in case 1241 of an invalid combination of client_id and redirect_uri. 1243 However, as described in [I-D.ietf-oauth-closing-redirectors], an 1244 attacker could also utilize a correctly registered redirect URI to 1245 perform phishing attacks. It could for example register a client via 1246 dynamic client [RFC7591] registration and intentionally send an 1247 erroneous authorization request, e.g., by using an invalid scope 1248 value, to cause the AS to automatically redirect the user agent to 1249 its phishing site. 1251 The AS MUST take precautions to prevent this threat. Based on its 1252 risk assessment the AS needs to decide whether it can trust the 1253 redirect URI or not and SHOULD only automatically redirect the user 1254 agent, if it trusts the redirect URI. If not, it MAY inform the user 1255 that it is about to redirect her to the another site and rely on the 1256 user to decide or MAY just inform the user about the error. 1258 3.9.2. Clients as Open Redirector 1260 Client MUST NOT expose URLs which could be utilized as open 1261 redirector. Attackers may use an open redirector to produce URLs 1262 which appear to point to the client, which might trick users to trust 1263 the URL and follow it in her browser. Another abuse case is to 1264 produce URLs pointing to the client and utilize them to impersonate a 1265 client with an authorization server. 1267 In order to prevent open redirection, clients should only expose such 1268 a function, if the target URLs are whitelisted or if the origin of a 1269 request can be authenticated. 1271 3.10. 307 Redirect 1273 At the authorization endpoint, a typical protocol flow is that the AS 1274 prompts the user to enter her credentials in a form that is then 1275 submitted (using the HTTP POST method) back to the authorization 1276 server. The AS checks the credentials and, if successful, redirects 1277 the user agent to the client's redirection endpoint. 1279 In [RFC6749], the HTTP status code 302 is used for this purpose, but 1280 "any other method available via the user-agent to accomplish this 1281 redirection is allowed". However, when the status code 307 is used 1282 for redirection, the user agent will send the form data (user 1283 credentials) via HTTP POST to the client since this status code does 1284 not require the user agent to rewrite the POST request to a GET 1285 request (and thereby dropping the form data in the POST request 1286 body). If the relying party is malicious, it can use the credentials 1287 to impersonate the user at the AS. 1289 In the HTTP standard [RFC6749], only the status code 303 1290 unambigiously enforces rewriting the HTTP POST request to an HTTP GET 1291 request. For all other status codes, including the popular 302, user 1292 agents can opt not to rewrite POST to GET requests and therefore to 1293 reveal the user credentials to the client. (In practice, however, 1294 most user agents will only show this behaviour for 307 redirects.) 1296 AS which redirect a request that potentially contains user 1297 credentials therefore MUST not use the HTTP 307 status code for 1298 redirection. If an HTTP redirection (and not, for example, 1299 JavaScript) is used for such a request, AS SHOULD use HTTP status 1300 code 303 "See Other". 1302 3.11. TLS Terminating Reverse Proxies 1304 A common deployment architecture for HTTP applications is to have the 1305 application server sitting behind a reverse proxy, which terminates 1306 the TLS connection and dispatches the incoming requests to the 1307 respective application server nodes. 1309 This section highlights some attack angles of this deployment 1310 architecture, which are relevant to OAuth, and give recommendations 1311 for security controls. 1313 In some situations, the reverse proxy needs to pass security-related 1314 data to the upstream application servers for further processing. 1315 Examples include the IP address of the request originator, token 1316 binding ids and authenticated TLS client certificates. 1318 If the reverse proxy would pass through any header sent from the 1319 outside, an attacker could try to directly send the faked header 1320 values through the proxy to the application server in order to 1321 circumvent security controls that way. For example, it is standard 1322 practice of reverse proxies to accept "forwarded_for" headers and 1323 just add the origin of the inbound request (making it a list). 1324 Depending on the logic performed in the application server, the 1325 attacker could simply add a whitelisted IP address to the header and 1326 render a IP whitelist useless. A reverse proxy must therefore 1327 sanitize any inbound requests to ensure the authenticity and 1328 integrity of all header values relevant for the security of the 1329 application servers. 1331 If an attacker would be able to get access to the internal network 1332 between proxy and application server, it could also try to circumvent 1333 security controls in place. It is therefore important to ensure the 1334 authenticity of the communicating entities. Furthermore, the 1335 communication link between reverse proxy and application server must 1336 therefore be protected against tapping and injection (including 1337 replay prevention). 1339 3.12. Refresh Token Protection 1341 Refresh tokens are a convenient and UX-friendly way to obtain new 1342 access tokens after the expiration of older access tokens. Refresh 1343 tokens also add to the security of OAuth since they allow the 1344 authorization server to issue access tokens with a short lifetime and 1345 reduced scope thus reducing the potential impact of access token 1346 leakage. 1348 Refresh tokens themself are an attractive target for attackers since 1349 they represent the overall grant a resource owner delegated to a 1350 certain client. If an attacker is able to exfiltrate and 1351 successfully replay a refresh token, it will be able to mint access 1352 tokens and use them to access resource servers on behalf of the 1353 resource server. 1355 [RFC6749] already provides robust base protection by requiring 1357 * confidentiality of the refresh tokens in transit and storage, 1359 * the transmission of refresh tokens over TLS-protected connections 1360 between authorization server and client, 1362 * the authorization server to maintain and check the binding of a 1363 refresh token to a certain client_id, 1365 * authentication of this client_id during token refresh, if 1366 possible, and 1368 * that refresh tokens cannot be generated, modified, or guessed. 1370 [RFC6749] also lays the foundation for further (implementation 1371 specific) security measures, such as refresh token expiration and 1372 revocation as well as refresh token rotation by defining respective 1373 error codes and response behavior. 1375 This draft gives recommendations beyond the scope of [RFC6749] and 1376 clarifications. 1378 Authorization servers MUST determine based on their risk assessment 1379 whether to issue refresh tokens to a certain client. If the 1380 authorization server decides not to issue refresh tokens, the client 1381 may refresh access tokens by utilizing other grant types, such as the 1382 authorization code grant type. In such a case, the authorization 1383 server may utilize cookies and persistents grants to optimize the 1384 user experience. 1386 If refresh tokens are issued, those refresh tokens MUST be bound to 1387 the scope and resource servers as consented by the resource owner. 1388 This is to prevent privilege escalation by the legit client and 1389 reduce the impact of refresh tokens leakage. 1391 Authorization server MUST utilize one of the methods listed below to 1392 detect refresh token replay for public clients: 1394 * Sender constrained refresh tokens: the authorization server 1395 cryptographically binds the refresh token to a certain client 1396 instance by utilizing [I-D.ietf-oauth-token-binding] or [I-D.ietf- 1397 oauth-mtls]. 1399 * Refresh token rotation: the authorization issues a new refresh 1400 token with every access token refresh response. The previous 1401 refresh token is invalidated but information about the 1402 relationship is retained by the authorization server. If a 1403 refresh token is compromised and subsequently used by both the 1404 attacker and the legitimate client, one of them will present an 1405 invalidated refresh token, which will inform the authorization 1406 server of the breach. The authorization server cannot determine 1407 which party submitted the invalid refresh token, but it can revoke 1408 the active refresh token. This stops the attack at the cost of 1409 forcing the legit client to obtain a fresh authorization grant. 1411 Implementation note: refresh tokens belonging to the same grant 1412 may share a common id. If any of those refresh tokens is used at 1413 the authorization server, the authorization server uses this 1414 common id to look up the currently active refresh token and can 1415 revoke it. 1417 Authorization servers may revoke refresh tokens automatically in case 1418 of a security event, such as: 1420 * password change 1422 * logout at the authorization server 1424 Refresh tokens SHOULD expire if the client has been inactive for some 1425 time,i.e. the refresh token has not been used to obtain fresh access 1426 tokens for some time. The expiration time is at the discretion of 1427 the authorization server. It might be a global value or determined 1428 based on the client policy or the grant associated with the refresh 1429 token (and its sensitivity). 1431 4. Acknowledgements 1433 We would like to thank Jim Manico, Phil Hunt, Nat Sakimura, Christian 1434 Mainka, Doug McDorman, Johan Peeters, Joseph Heenan, Brock Allen, 1435 Vittorio Bertocci, David Waite, Nov Matake, Tomek Stojecki, Dominick 1436 Baier, Neil Madden, William Dennis, Dick Hardt, Petteri Stenius, 1437 Annabelle Richard Backman, Aaron Parecki, George Fletscher, and Brian 1438 Campbell for their valuable feedback. 1440 5. IANA Considerations 1442 This draft includes no request to IANA. 1444 6. Security Considerations 1446 All relevant security considerations have been given in the 1447 functional specification. 1449 7. Normative References 1451 [arXiv.1508.04324v2] 1452 Schwenk, J., "On the security of modern Single Sign-On 1453 Protocols: Second-Order Vulnerabilities in OpenID 1454 Connect", 7 January 2016. 1456 [arXiv.1601.01229] 1457 Schmitz, G., "A Comprehensive Formal Security Analysis of 1458 OAuth 2.0", 6 January 2016. 1460 [arXiv.1704.08539] 1461 Schmitz, G., "The Web SSO Standard OpenID Connect: In- 1462 Depth Formal Security Analysis and Security Guidelines", 1463 27 April 2017. 1465 [bug.chromium] 1466 "Referer header includes URL fragment when opening link 1467 using New Tab", December 2018. 1469 [fb_fragments] 1470 "Facebook Developer Blog", December 2018. 1472 [I-D.bradley-oauth-jwt-encoded-state] 1473 Bradley, J., Lodderstedt, T., and H. Zandbelt, "Encoding 1474 claims in the OAuth 2 state parameter using a JWT", draft- 1475 bradley-oauth-jwt-encoded-state-09 (work in progress), 4 1476 November 2018, 1477 . 1480 [I-D.ietf-oauth-closing-redirectors] 1481 Bradley, J., Sanso, A., and H. Tschofenig, "OAuth 2.0 1482 Security: Closing Open Redirectors in OAuth", draft-ietf- 1483 oauth-closing-redirectors-00 (work in progress), 4 1484 February 2016, 1485 . 1488 [I-D.ietf-oauth-jwsreq] 1489 Sakimura, N. and J. Bradley, "The OAuth 2.0 Authorization 1490 Framework: JWT Secured Authorization Request (JAR)", 1491 draft-ietf-oauth-jwsreq-17 (work in progress), 21 October 1492 2018, 1493 . 1496 [I-D.ietf-oauth-mix-up-mitigation] 1497 Jones, M., Bradley, J., and N. Sakimura, "OAuth 2.0 Mix-Up 1498 Mitigation", draft-ietf-oauth-mix-up-mitigation-01 (work 1499 in progress), 7 July 2016, 1500 . 1503 [I-D.ietf-oauth-mtls] 1504 Campbell, B., Bradley, J., Sakimura, N., and T. 1505 Lodderstedt, "OAuth 2.0 Mutual TLS Client Authentication 1506 and Certificate Bound Access Tokens", draft-ietf-oauth- 1507 mtls-12 (work in progress), 18 October 2018, 1508 . 1511 [I-D.ietf-oauth-pop-key-distribution] 1512 Bradley, J., Hunt, P., Jones, M., Tschofenig, H., and M. 1513 Mihaly, "OAuth 2.0 Proof-of-Possession: Authorization 1514 Server to Client Key Distribution", draft-ietf-oauth-pop- 1515 key-distribution-04 (work in progress), 23 October 2018, 1516 . 1519 [I-D.ietf-oauth-resource-indicators] 1520 Campbell, B., Bradley, J., and H. Tschofenig, "Resource 1521 Indicators for OAuth 2.0", draft-ietf-oauth-resource- 1522 indicators-01 (work in progress), 19 October 2018, 1523 . 1526 [I-D.ietf-oauth-signed-http-request] 1527 Richer, J., Bradley, J., and H. Tschofenig, "A Method for 1528 Signing HTTP Requests for OAuth", draft-ietf-oauth-signed- 1529 http-request-03 (work in progress), 8 August 2016, 1530 . 1533 [I-D.ietf-oauth-token-binding] 1534 Jones, M., Campbell, B., Bradley, J., and W. Denniss, 1535 "OAuth 2.0 Token Binding", draft-ietf-oauth-token- 1536 binding-08 (work in progress), 19 October 2018, 1537 . 1540 [I-D.ietf-tokbind-https] 1541 Popov, A., Nystrom, M., Balfanz, D., Langley, A., Harper, 1542 N., and J. Hodges, "Token Binding over HTTP", draft-ietf- 1543 tokbind-https-18 (work in progress), 26 June 2018, 1544 . 1547 [I-D.sakimura-oauth-jpop] 1548 Sakimura, N., Li, K., and J. Bradley, "The OAuth 2.0 1549 Authorization Framework: JWT Pop Token Usage", draft- 1550 sakimura-oauth-jpop-04 (work in progress), 27 March 2017, 1551 . 1554 [oauth-v2-form-post-response-mode] 1555 "OAuth 2.0 Form Post Response Mode", 27 April 2015. 1557 [oauth_security_jcs_14] 1558 Maffeis, S., "Discovering concrete attacks on website 1559 authorization by formal analysis", 23 April 2014. 1561 [OpenID] "OpenID Connect Core 1.0 incorporating errata set 1", 8 1562 November 2014. 1564 [owasp] "Open Web Application Security Project Home Page", 1565 December 2018. 1567 [owasp_csrf] 1568 "Cross-Site Request Forgery (CSRF) Prevention Cheat 1569 Sheet", December 2018. 1571 [RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H., 1572 Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext 1573 Transfer Protocol -- HTTP/1.1", RFC 2616, 1574 DOI 10.17487/RFC2616, June 1999, 1575 . 1577 [RFC3986] Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform 1578 Resource Identifier (URI): Generic Syntax", STD 66, 1579 RFC 3986, DOI 10.17487/RFC3986, January 2005, 1580 . 1582 [RFC6749] Hardt, D., Ed., "The OAuth 2.0 Authorization Framework", 1583 RFC 6749, DOI 10.17487/RFC6749, October 2012, 1584 . 1586 [RFC6750] Jones, M. and D. Hardt, "The OAuth 2.0 Authorization 1587 Framework: Bearer Token Usage", RFC 6750, 1588 DOI 10.17487/RFC6750, October 2012, 1589 . 1591 [RFC6819] Lodderstedt, T., Ed., McGloin, M., and P. Hunt, "OAuth 2.0 1592 Threat Model and Security Considerations", RFC 6819, 1593 DOI 10.17487/RFC6819, January 2013, 1594 . 1596 [RFC7231] Fielding, R., Ed. and J. Reschke, Ed., "Hypertext Transfer 1597 Protocol (HTTP/1.1): Semantics and Content", RFC 7231, 1598 DOI 10.17487/RFC7231, June 2014, 1599 . 1601 [RFC7591] Richer, J., Ed., Jones, M., Bradley, J., Machulak, M., and 1602 P. Hunt, "OAuth 2.0 Dynamic Client Registration Protocol", 1603 RFC 7591, DOI 10.17487/RFC7591, July 2015, 1604 . 1606 [RFC7636] Sakimura, N., Ed., Bradley, J., and N. Agarwal, "Proof Key 1607 for Code Exchange by OAuth Public Clients", RFC 7636, 1608 DOI 10.17487/RFC7636, September 2015, 1609 . 1611 [RFC7800] Jones, M., Bradley, J., and H. Tschofenig, "Proof-of- 1612 Possession Key Semantics for JSON Web Tokens (JWTs)", 1613 RFC 7800, DOI 10.17487/RFC7800, April 2016, 1614 . 1616 [RFC8414] Jones, M., Sakimura, N., and J. Bradley, "OAuth 2.0 1617 Authorization Server Metadata", RFC 8414, 1618 DOI 10.17487/RFC8414, June 2018, 1619 . 1621 [webappsec-referrer-policy] 1622 "Referrer Policy", 20 April 2017. 1624 Appendix A. Document History 1626 [[ To be removed from the final specification ]] 1628 -11 1630 * Adapted section 2.1.2 to outcome of consensus call 1632 * more text on refresh token inactivity and implementation note on 1633 refres token replay detection via refresh token rotation 1635 -10 1637 * incorporated feedback by Joseph Heenan 1639 * changed occurrences of SHALL to MUST 1641 * added text on lack of token/cert binding support tokens issued in 1642 the authorization response as justification to not recommend 1643 issuing tokens there at all 1645 * added requirement to authenticate clients during code exchange 1646 (PKCE or client credential) to 2.1.1. 1648 * added section on refresh tokens 1650 * editorial enhancements to 2.1.2 based on feedback 1652 -09 1654 * changed text to recommend not to use implicit but code 1656 * added section on access token injection 1658 * reworked sections 3.1 through 3.3 to be more specific on implicit 1659 grant issues 1661 -08 1663 * added recommendations re implicit and token injection 1665 * uppercased key words in Section 2 according to RFC 2119 1667 -07 1669 * incorporated findings of Doug McDorman 1671 * added section on HTTP status codes for redirects 1673 * added new section on access token privilege restriction based on 1674 comments from Johan Peeters 1676 -06 1678 * reworked section 3.8.1 1680 * incorporated Phil Hunt's feedback 1682 * reworked section on mix-up 1684 * extended section on code leakage via referrer header to also cover 1685 state leakage 1687 * added Daniel Fett as author 1689 * replaced text intended to inform WG discussion by recommendations 1690 to implementors 1692 * modified example URLs to conform to RFC 2606 1694 -05 1696 * Completed sections on code leakage via referrer header, attacks in 1697 browser, mix-up, and CSRF 1699 * Reworked Code Injection Section 1701 * Added reference to OpenID Connect spec 1703 * removed refresh token leakage as respective considerations have 1704 been given in section 10.4 of RFC 6749 1706 * first version on open redirection 1708 * incorporated Christian Mainka's review feedback 1710 -04 1712 * Restructured document for better readability 1714 * Added best practices on Token Leakage prevention 1716 -03 1718 * Added section on Access Token Leakage at Resource Server 1720 * incorporated Brian Campbell's findings 1722 -02 1724 * Folded Mix up and Access Token leakage through a bad AS into new 1725 section for dynamic OAuth threats 1727 * reworked dynamic OAuth section 1729 -01 1731 * Added references to mitigation methods for token leakage 1733 * Added reference to Token Binding for Authorization Code 1735 * incorporated feedback of Phil Hunt 1737 * fixed numbering issue in attack descriptions in section 2 1739 -00 (WG document) 1741 * turned the ID into a WG document and a BCP 1743 * Added federated app login as topic in Other Topics 1745 Authors' Addresses 1747 Torsten Lodderstedt 1748 yes.com 1750 Email: torsten@lodderstedt.net 1752 John Bradley 1753 Yubico 1755 Email: ve7jtb@ve7jtb.com 1757 Andrey Labunets 1758 Facebook 1760 Email: isciurus@fb.com 1762 Daniel Fett 1763 yes.com 1765 Email: mail@danielfett.de