idnits 2.17.1 draft-ietf-oauth-jwt-bcp-00.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: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- ** The document seems to lack a Security Considerations section. ** The abstract seems to contain references ([RFC7519]), which it shouldn't. Please replace those with straight textual mentions of the documents in question. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year -- The document date (July 19, 2017) is 2474 days in the past. Is this intentional? 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) ** Obsolete normative reference: RFC 7159 (Obsoleted by RFC 8259) == Outdated reference: A later version (-10) exists of draft-ietf-oauth-discovery-06 == Outdated reference: A later version (-13) exists of draft-ietf-secevent-token-02 Summary: 3 errors (**), 0 flaws (~~), 3 warnings (==), 1 comment (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 OAuth Working Group Y. Sheffer 3 Internet-Draft Intuit 4 Intended status: Best Current Practice D. Hardt 5 Expires: January 20, 2018 Amazon 6 M. Jones 7 Microsoft 8 July 19, 2017 10 JSON Web Token Best Current Practices 11 draft-ietf-oauth-jwt-bcp-00 13 Abstract 15 JSON Web Tokens, also known as JWTs [RFC7519], are URL-safe JSON- 16 based security tokens that contain a set of claims that can be signed 17 and/or encrypted. JWTs are being widely used and deployed as a 18 simple security token format in numerous protocols and applications, 19 both in the area of digital identity, and in other application areas. 20 The goal of this Best Current Practices document is to provide 21 actionable guidance leading to secure implementation and deployment 22 of JWTs. 24 Status of This Memo 26 This Internet-Draft is submitted in full conformance with the 27 provisions of BCP 78 and BCP 79. 29 Internet-Drafts are working documents of the Internet Engineering 30 Task Force (IETF). Note that other groups may also distribute 31 working documents as Internet-Drafts. The list of current Internet- 32 Drafts is at http://datatracker.ietf.org/drafts/current/. 34 Internet-Drafts are draft documents valid for a maximum of six months 35 and may be updated, replaced, or obsoleted by other documents at any 36 time. It is inappropriate to use Internet-Drafts as reference 37 material or to cite them other than as "work in progress." 39 This Internet-Draft will expire on January 20, 2018. 41 Copyright Notice 43 Copyright (c) 2017 IETF Trust and the persons identified as the 44 document authors. All rights reserved. 46 This document is subject to BCP 78 and the IETF Trust's Legal 47 Provisions Relating to IETF Documents 48 (http://trustee.ietf.org/license-info) in effect on the date of 49 publication of this document. Please review these documents 50 carefully, as they describe your rights and restrictions with respect 51 to this document. Code Components extracted from this document must 52 include Simplified BSD License text as described in Section 4.e of 53 the Trust Legal Provisions and are provided without warranty as 54 described in the Simplified BSD License. 56 Table of Contents 58 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 2 59 1.1. Target Audience . . . . . . . . . . . . . . . . . . . . . 3 60 1.2. Conventions used in this document . . . . . . . . . . . . 4 61 2. Threats and Vulnerabilities . . . . . . . . . . . . . . . . . 4 62 2.1. Weak Signatures and Insufficient Signature Validation . . 4 63 2.2. Weak symmetric keys . . . . . . . . . . . . . . . . . . . 4 64 2.3. Multiplicity of JSON encodings . . . . . . . . . . . . . 4 65 2.4. Incorrect Composition of Encryption and Signature . . . . 5 66 2.5. Insecure Use of Elliptic Curve Encryption . . . . . . . . 5 67 2.6. Substitution Attacks . . . . . . . . . . . . . . . . . . 5 68 2.7. Cross-JWT Confusion . . . . . . . . . . . . . . . . . . . 5 69 3. Best Practices . . . . . . . . . . . . . . . . . . . . . . . 5 70 3.1. Perform Algorithm Verification . . . . . . . . . . . . . 6 71 3.2. Use Appropriate Algorithms . . . . . . . . . . . . . . . 6 72 3.3. Validate All Cryptographic Operations . . . . . . . . . . 6 73 3.4. Validate Cryptographic Inputs . . . . . . . . . . . . . . 6 74 3.5. Ensure Cryptographic Keys have Sufficient Entropy . . . . 7 75 3.6. Use UTF-8 . . . . . . . . . . . . . . . . . . . . . . . . 7 76 3.7. Validate Issuer and Subject . . . . . . . . . . . . . . . 7 77 3.8. Use and Validate Audience . . . . . . . . . . . . . . . . 7 78 3.9. Use Explicit Typing . . . . . . . . . . . . . . . . . . . 8 79 3.10. Use Mutually Exclusive Validation Rules for Different 80 Kinds of JWTs . . . . . . . . . . . . . . . . . . . . . . 8 81 4. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 9 82 5. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . 9 83 6. References . . . . . . . . . . . . . . . . . . . . . . . . . 9 84 6.1. Normative References . . . . . . . . . . . . . . . . . . 9 85 6.2. Informative References . . . . . . . . . . . . . . . . . 10 86 Appendix A. Document History . . . . . . . . . . . . . . . . . . 11 87 A.1. draft-ietf-oauth-jwt-bcp-00 . . . . . . . . . . . . . . . 11 88 A.2. draft-sheffer-oauth-jwt-bcp-01 . . . . . . . . . . . . . 11 89 A.3. draft-sheffer-oauth-jwt-bcp-00 . . . . . . . . . . . . . 11 90 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 11 92 1. Introduction 94 JSON Web Tokens, also known as JWTs [RFC7519], are URL-safe JSON- 95 based security tokens that contain a set of claims that can be signed 96 and/or encrypted. The JWT specification has seen rapid adoption 97 because it encapsulates security-relevant information in one, easy to 98 protect location, and because it is easy to implement using widely- 99 available tools. One application area in which JWTs are commonly 100 used is representing digital identity information, such as OpenID 101 Connect ID Tokens [OpenID.Core] and OAuth 2.0 [RFC6749] access tokens 102 and refresh tokens, the details of which are deployment-specific. 104 Since the JWT specification was published, there have been several 105 widely published attacks on implementations and deployments. Such 106 attacks are the result of under-specified security mechanisms, as 107 well as incomplete implementations and incorrect usage by 108 applications. 110 The goal of this document is to facilitate secure implementation and 111 deployment of JWTs. Many of the recommendations in this document 112 will actually be about implementation and use of the cryptographic 113 mechanisms underlying JWTs that are defined by JSON Web Signature 114 (JWS) [RFC7515], JSON Web Encryption (JWE) [RFC7516], and JSON Web 115 Algorithms (JWA) [RFC7518]. Others will be about use of the JWT 116 claims themselves. 118 These are intended to be minimum recommendations for the use of JWTs 119 in the vast majority of implementation and deployment scenarios. 120 Other specifications that reference this document can have stricter 121 requirements related to one or more aspects of the format, based on 122 their particular circumstances; when that is the case, implementers 123 are advised to adhere to those stricter requirements. Furthermore, 124 this document provides a floor, not a ceiling, so stronger options 125 are always allowed (e.g., depending on differing evaluations of the 126 importance of cryptographic strength vs. computational load). 128 Community knowledge about the strength of various algorithms and 129 feasible attacks can change quickly, and experience shows that a Best 130 Current Practice (BCP) document about security is a point-in-time 131 statement. Readers are advised to seek out any errata or updates 132 that apply to this document. 134 1.1. Target Audience 136 The targets of this document are: 138 - Implementers of JWT libraries (and the JWS and JWE libraries used 139 by them), 141 - Implementers of code that uses such libraries (to the extent that 142 some mechanisms may not be provided by libraries, or until they 143 are), and 145 - Developers of specifications that rely on JWTs, both inside and 146 outside the IETF. 148 1.2. Conventions used in this document 150 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 151 "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and 152 "OPTIONAL" in this document are to be interpreted as described in 153 [RFC2119]. 155 2. Threats and Vulnerabilities 157 This section lists some known and possible problems with JWT 158 implementations and deployments. Each problem description is 159 followed by references to one or more mitigations to those problems. 161 2.1. Weak Signatures and Insufficient Signature Validation 163 Signed JSON Web Tokens carry an explicit indication of the signing 164 algorithm, in the form of the "alg" header parameter, to facilitate 165 cryptographic agility. This, in conjunction with design flaws in 166 some libraries and applications, have led to several attacks: 168 - The algorithm can be changed to "none" by an attacker, and some 169 libraries would trust this value and "validate" the JWT without 170 checking any signature. 172 - An "RS256" (RSA, 2048 bit) parameter value can be changed into 173 "HS256" (HMAC, SHA-256), and some libraries would try to validate 174 the signature using HMAC-SHA256 and using the RSA public key as 175 the HMAC shared secret. 177 For mitigations, see Section 3.1 and Section 3.2. 179 2.2. Weak symmetric keys 181 In addition, some applications sign tokens using a weak symmetric key 182 and a keyed MAC algorithm such as "HS256". In most cases, these keys 183 are human memorable passwords that are vulnerable to dictionary 184 attacks [Langkemper]. 186 For mitigations, see Section 3.5. 188 2.3. Multiplicity of JSON encodings 190 Many practitioners are not aware that JSON [RFC7159] allows several 191 different character encodings: UTF-8, UTF-16 and UTF-32. As a 192 result, the JWT might be misinterpreted by its recipient. 194 For mitigations, see Section 3.6. 196 2.4. Incorrect Composition of Encryption and Signature 198 Some libraries that decrypt a JWE-encrypted JWT to obtain a JWS- 199 signed object do not always validate the internal signature. 201 For mitigations, see Section 3.3. 203 2.5. Insecure Use of Elliptic Curve Encryption 205 Per [Sanso], several JOSE libraries fail to validate their inputs 206 correctly when performing elliptic curve key agreement (the "ECDH-ES" 207 algorithm). An attacker that is able to send JWEs of its choosing 208 that use invalid curve points and observe the cleartext outputs 209 resulting from decryption with the invalid curve points can use this 210 vulnerability to recover the recipient's private key. 212 For mitigations, see Section 3.4. 214 2.6. Substitution Attacks 216 There are attacks in which one recipient will have a JWT intended for 217 it and attempt to use it at a different recipient that it was not 218 intended for. If not caught, these attacks can result in the 219 attacker gaining access to resources that it is not entitled to 220 access. 222 For mitigations, see Section 3.7 and Section 3.8. 224 2.7. Cross-JWT Confusion 226 As JWTs are being used by more different protocols in diverse 227 application areas, it becomes increasingly important to prevent cases 228 of JWT tokens that have been issued for one purpose being subverted 229 and used for another. Note that this is a specific type of 230 substitution attack. If the JWT could be used in an application 231 context in which it could be confused with other kinds of JWTs, then 232 mitigations MUST be employed to prevent these substitution attacks. 234 For mitigations, see Section 3.7, Section 3.8, Section 3.9, and 235 Section 3.10. 237 3. Best Practices 239 The best practices listed below should be applied by practitioners to 240 mitigate the threats listed in the preceding section. 242 3.1. Perform Algorithm Verification 244 Libraries MUST enable the caller to specify a supported set of 245 algorithms and MUST NOT use any other algorithms when performing 246 cryptographic operations. The library MUST ensure that the "alg" or 247 "enc" header specifies the same algorithm that is used for the 248 cryptographic operation. Moreover, each key MUST be used with 249 exactly one algorithm, and this MUST be checked when the 250 cryptographic operation is performed. 252 3.2. Use Appropriate Algorithms 254 As Section 5.2 of [RFC7515] says, "it is an application decision 255 which algorithms may be used in a given context. Even if a JWS can 256 be successfully validated, unless the algorithm(s) used in the JWS 257 are acceptable to the application, it SHOULD consider the JWS to be 258 invalid." 260 Therefore, applications MUST only allow the use of cryptographically 261 current algorithms that meet the security requirements of the 262 application. This set will vary over time as new algorithms are 263 introduced and existing algorithms are deprecated due to discovered 264 cryptographic weaknesses. Applications must therefore be designed to 265 enable cryptographic agility. 267 That said, if a JWT is cryptographically protected by a transport 268 layer, such as TLS using cryptographically current algorithms, there 269 may be no need to apply another layer of cryptographic protections to 270 the JWT. In such cases, the use of the "none" algorithm can be 271 perfectly acceptable. JWTs using "none" are often used in 272 application contexts in which the content is optionally signed; then 273 the URL-safe claims representation and processing can be the same in 274 both the signed and unsigned cases. 276 3.3. Validate All Cryptographic Operations 278 All cryptographic operations used in the JWT MUST be validated and 279 the entire JWT MUST be rejected if any of them fail to validate. 280 This is true not only of JWTs with a single set of Header Parameters 281 but also for Nested JWTs, in which both outer and inner operations 282 MUST be validated using the keys and algorithms supplied by the 283 application. 285 3.4. Validate Cryptographic Inputs 287 Some cryptographic operations, such as Elliptic Curve Diffie-Hellman 288 key agreement ("ECDH-ES") take inputs that may contain invalid 289 values, such as points not on the specified elliptic curve or other 290 invalid points. Either the JWS/JWE library itself must validate 291 these inputs before using them or it must use underlying 292 cryptographic libraries that do so (or both!). 294 3.5. Ensure Cryptographic Keys have Sufficient Entropy 296 The Key Entropy and Random Values advice in Section 10.1 of [RFC7515] 297 and the Password Considerations in Section 8.8 of [RFC7518] MUST be 298 followed. In particular, human-memorizable passwords MUST NOT be 299 directly used as the key to a keyed-MAC algorithm such as "HS256". 301 3.6. Use UTF-8 303 [RFC7515], [RFC7516], and [RFC7519] all specify that UTF-8 be used 304 for encoding and decoding JSON used in Header Parameters and JWT 305 Claims Sets. Implementations and applications MUST do this, and not 306 use other Unicode encodings for these purposes. 308 3.7. Validate Issuer and Subject 310 When a JWT contains an "iss" (issuer) claim, the application MUST 311 validate that the cryptographic keys used for the cryptographic 312 operations in the JWT belong to the issuer. If they do not, the 313 application MUST reject the JWT. 315 The means of determining the keys owned by an issuer is application- 316 specific. As one example, OpenID Connect [OpenID.Core] issuer values 317 are "https" URLs that reference a JSON metadata document that 318 contains a "jwks_uri" value that is an "https" URL from which the 319 issuer's keys are retrieved as a JWK Set [RFC7517]. This same 320 mechanism is used by [I-D.ietf-oauth-discovery]. Other applications 321 may use different means of binding keys to issuers. 323 Similarly, when the JWT contains a "sub" (subject) claim, the 324 application MUST validate that the subject value corresponds to a 325 valid subject and/or issuer/subject pair at the application. This 326 may include confirming that the issuer is trusted by the application. 327 If the issuer, subject, or the pair are invalid, the application MUST 328 reject the JWT. 330 3.8. Use and Validate Audience 332 If the same issuer can issue JWTs that are intended for use by more 333 than one relying party or application, the JWT MUST contain an "aud" 334 (audience) claim that can be used to determine whether the JWT is 335 being used by an intended party or was substituted by an attacker at 336 an unintended party. Furthermore, the relying party or application 337 MUST validate the audience value and if the audience value is not 338 associated with the recipient, it MUST reject the JWT. 340 3.9. Use Explicit Typing 342 Confusion of one kind of JWT for another can be prevented by having 343 all the kinds of JWTs that could otherwise potentially be confused 344 include an explicit JWT type value and include checking the type 345 value in their validation rules. Explicit JWT typing is accomplished 346 by using the "typ" header parameter. For instance, the 347 [I-D.ietf-secevent-token] specification uses the "application/ 348 secevent+jwt" media type to perform explicit typing of Security Event 349 Tokens (SETs). 351 Per the definition of "typ" in Section 4.1.9 of [RFC7515], it is 352 RECOMMENDED that the "application/" prefix be omitted from the "typ" 353 value. Therefore, for example, the "typ" value used to explicitly 354 include a type for a SET SHOULD be "secevent+jwt". When explicit 355 typing is employed for a JWT, it is RECOMMENDED that a media type 356 name of the format "application/example+jwt" be used, where "example" 357 is replaced by the identifier for the specific kind of JWT. 359 Note that the use of explicit typing may not achieve disambiguation 360 from existing kinds of JWTs, as the validation rules for existing 361 kinds JWTs often do not use the "typ" header parameter value. 362 Explicit typing is RECOMMENDED for new uses of JWTs. 364 3.10. Use Mutually Exclusive Validation Rules for Different Kinds of 365 JWTs 367 Each application of JWTs defines a profile specifying the required 368 and optional JWT claims and the validation rules associated with 369 them. If more than one kind of JWT can be issued by the same issuer, 370 the validation rules for those JWTs MUST be written such that they 371 are mutually exclusive, rejecting JWTs of the wrong kind. To prevent 372 substitution of JWTs from one context into another, a number of 373 strategies may be employed: 375 - Use explicit typing for different kinds of JWTs. Then the 376 distinct "typ" values can be used to differentiate between the 377 different kinds of JWTs. 379 - Use different sets of required claims or different required claim 380 values. Then the validation rules for one kind of JWT will reject 381 those with different claims or values. 383 - Use different sets of required header parameters or different 384 required header parameter values. Then the validation rules for 385 one kind of JWT will reject those with different header parameters 386 or values. 388 - Use different keys for different kinds of JWTs. Then the keys 389 used to validate one kind of JWT will fail to validate other kinds 390 of JWTs. 392 - Use different "aud" values for different uses of JWTs from the 393 same issuer. Then audience validation will reject JWTs 394 substituted into inappropriate contexts. 396 - Use different issuers for different kinds of JWTs. Then the 397 distinct "iss" values can be used to segregate the different kinds 398 of JWTs. 400 Given the broad diversity of JWT usage and applications, the best 401 combination of types, required claims, values, header parameters, key 402 usages, and issuers to differentiate among different kinds of JWTs 403 will, in general, be application specific. 405 4. IANA Considerations 407 This document requires no IANA actions. 409 5. Acknowledgements 411 Thanks to Antonio Sanso for bringing the "ECDH-ES" invalid point 412 attack to the attention of JWE and JWT implementers. Thanks to Nat 413 Sakimura for advocating the use of explicit typing. 415 6. References 417 6.1. Normative References 419 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 420 Requirement Levels", BCP 14, RFC 2119, 421 DOI 10.17487/RFC2119, March 1997, 422 . 424 [RFC7159] Bray, T., Ed., "The JavaScript Object Notation (JSON) Data 425 Interchange Format", RFC 7159, DOI 10.17487/RFC7159, March 426 2014, . 428 [RFC7515] Jones, M., Bradley, J., and N. Sakimura, "JSON Web 429 Signature (JWS)", RFC 7515, DOI 10.17487/RFC7515, May 430 2015, . 432 [RFC7516] Jones, M. and J. Hildebrand, "JSON Web Encryption (JWE)", 433 RFC 7516, DOI 10.17487/RFC7516, May 2015, 434 . 436 [RFC7518] Jones, M., "JSON Web Algorithms (JWA)", RFC 7518, 437 DOI 10.17487/RFC7518, May 2015, 438 . 440 [RFC7519] Jones, M., Bradley, J., and N. Sakimura, "JSON Web Token 441 (JWT)", RFC 7519, DOI 10.17487/RFC7519, May 2015, 442 . 444 6.2. Informative References 446 [I-D.ietf-oauth-discovery] 447 Jones, M., Sakimura, N., and J. Bradley, "OAuth 2.0 448 Authorization Server Metadata", draft-ietf-oauth- 449 discovery-06 (work in progress), March 2017. 451 [I-D.ietf-secevent-token] 452 Hunt, P., Denniss, W., Ansari, M., and M. Jones, "Security 453 Event Token (SET)", draft-ietf-secevent-token-02 (work in 454 progress), June 2017. 456 [Langkemper] 457 Langkemper, S., "Attacking JWT Authentication", September 458 2016, . 461 [OpenID.Core] 462 Sakimura, N., Bradley, J., Jones, M., Medeiros, B., and C. 463 Mortimore, "OpenID Connect Core 1.0", November 2014, 464 . 466 [RFC6749] Hardt, D., Ed., "The OAuth 2.0 Authorization Framework", 467 RFC 6749, DOI 10.17487/RFC6749, October 2012, 468 . 470 [RFC7517] Jones, M., "JSON Web Key (JWK)", RFC 7517, 471 DOI 10.17487/RFC7517, May 2015, 472 . 474 [Sanso] Sanso, A., "Critical Vulnerability Uncovered in JSON 475 Encryption", March 2017, 476 . 479 Appendix A. Document History 481 [[ to be removed by the RFC editor before publication as an RFC ]] 483 A.1. draft-ietf-oauth-jwt-bcp-00 485 - Initial WG draft. No change from the latest individual version. 487 A.2. draft-sheffer-oauth-jwt-bcp-01 489 - Added explicit typing. 491 A.3. draft-sheffer-oauth-jwt-bcp-00 493 - Initial version. 495 Authors' Addresses 497 Yaron Sheffer 498 Intuit 500 EMail: yaronf.ietf@gmail.com 502 Dick Hardt 503 Amazon 505 EMail: dick@amazon.com 507 Michael B. Jones 508 Microsoft 510 EMail: mbj@microsoft.com 511 URI: http://self-issued.info/