idnits 2.17.1 draft-sheffer-oauth-jwt-bcp-01.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 03, 2017) is 2489 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 4, 2018 Amazon 6 M. Jones 7 Microsoft 8 July 03, 2017 10 JSON Web Token Best Current Practices 11 draft-sheffer-oauth-jwt-bcp-01 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 4, 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-sheffer-oauth-jwt-bcp-01 . . . . . . . . . . . . . 11 88 A.2. draft-sheffer-oauth-jwt-bcp-00 . . . . . . . . . . . . . 11 89 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 11 91 1. Introduction 93 JSON Web Tokens, also known as JWTs [RFC7519], are URL-safe JSON- 94 based security tokens that contain a set of claims that can be signed 95 and/or encrypted. The JWT specification has seen rapid adoption 96 because it encapsulates security-relevant information in one, easy to 97 protect location, and because it is easy to implement using widely- 98 available tools. One application area in which JWTs are commonly 99 used is representing digital identity information, such as OpenID 100 Connect ID Tokens [OpenID.Core] and OAuth 2.0 [RFC6749] access tokens 101 and refresh tokens, the details of which are deployment-specific. 103 Since the JWT specification was published, there have been several 104 widely published attacks on implementations and deployments. Such 105 attacks are the result of under-specified security mechanisms, as 106 well as incomplete implementations and incorrect usage by 107 applications. 109 The goal of this document is to facilitate secure implementation and 110 deployment of JWTs. Many of the recommendations in this document 111 will actually be about implementation and use of the cryptographic 112 mechanisms underlying JWTs that are defined by JSON Web Signature 113 (JWS) [RFC7515], JSON Web Encryption (JWE) [RFC7516], and JSON Web 114 Algorithms (JWA) [RFC7518]. Others will be about use of the JWT 115 claims themselves. 117 These are intended to be minimum recommendations for the use of JWTs 118 in the vast majority of implementation and deployment scenarios. 119 Other specifications that reference this document can have stricter 120 requirements related to one or more aspects of the format, based on 121 their particular circumstances; when that is the case, implementers 122 are advised to adhere to those stricter requirements. Furthermore, 123 this document provides a floor, not a ceiling, so stronger options 124 are always allowed (e.g., depending on differing evaluations of the 125 importance of cryptographic strength vs. computational load). 127 Community knowledge about the strength of various algorithms and 128 feasible attacks can change quickly, and experience shows that a Best 129 Current Practice (BCP) document about security is a point-in-time 130 statement. Readers are advised to seek out any errata or updates 131 that apply to this document. 133 1.1. Target Audience 135 The targets of this document are: 137 - Implementers of JWT libraries (and the JWS and JWE libraries used 138 by them), 140 - Implementers of code that uses such libraries (to the extent that 141 some mechanisms may not be provided by libraries, or until they 142 are), and 144 - Developers of specifications that rely on JWTs, both inside and 145 outside the IETF. 147 1.2. Conventions used in this document 149 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 150 "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and 151 "OPTIONAL" in this document are to be interpreted as described in 152 [RFC2119]. 154 2. Threats and Vulnerabilities 156 This section lists some known and possible problems with JWT 157 implementations and deployments. Each problem description is 158 followed by references to one or more mitigations to those problems. 160 2.1. Weak Signatures and Insufficient Signature Validation 162 Signed JSON Web Tokens carry an explicit indication of the signing 163 algorithm, in the form of the "alg" header parameter, to facilitate 164 cryptographic agility. This, in conjunction with design flaws in 165 some libraries and applications, have led to several attacks: 167 - The algorithm can be changed to "none" by an attacker, and some 168 libraries would trust this value and "validate" the JWT without 169 checking any signature. 171 - An "RS256" (RSA, 2048 bit) parameter value can be changed into 172 "HS256" (HMAC, SHA-256), and some libraries would try to validate 173 the signature using HMAC-SHA256 and using the RSA public key as 174 the HMAC shared secret. 176 For mitigations, see Section 3.1 and Section 3.2. 178 2.2. Weak symmetric keys 180 In addition, some applications sign tokens using a weak symmetric key 181 and a keyed MAC algorithm such as "HS256". In most cases, these keys 182 are human memorable passwords that are vulnerable to dictionary 183 attacks [Langkemper]. 185 For mitigations, see Section 3.5. 187 2.3. Multiplicity of JSON encodings 189 Many practitioners are not aware that JSON [RFC7159] allows several 190 different character encodings: UTF-8, UTF-16 and UTF-32. As a 191 result, the JWT might be misinterpreted by its recipient. 193 For mitigations, see Section 3.6. 195 2.4. Incorrect Composition of Encryption and Signature 197 Some libraries that decrypt a JWE-encrypted JWT to obtain a JWS- 198 signed object do not always validate the internal signature. 200 For mitigations, see Section 3.3. 202 2.5. Insecure Use of Elliptic Curve Encryption 204 Per [Sanso], several JOSE libraries fail to validate their inputs 205 correctly when performing elliptic curve key agreement (the "ECDH-ES" 206 algorithm). An attacker that is able to send JWEs of its choosing 207 that use invalid curve points and observe the cleartext outputs 208 resulting from decryption with the invalid curve points can use this 209 vulnerability to recover the recipient's private key. 211 For mitigations, see Section 3.4. 213 2.6. Substitution Attacks 215 There are attacks in which one recipient will have a JWT intended for 216 it and attempt to use it at a different recipient that it was not 217 intended for. If not caught, these attacks can result in the 218 attacker gaining access to resources that it is not entitled to 219 access. 221 For mitigations, see Section 3.7 and Section 3.8. 223 2.7. Cross-JWT Confusion 225 As JWTs are being used by more different protocols in diverse 226 application areas, it becomes increasingly important to prevent cases 227 of JWT tokens that have been issued for one purpose being subverted 228 and used for another. Note that this is a specific type of 229 substitution attack. If the JWT could be used in an application 230 context in which it could be confused with other kinds of JWTs, then 231 mitigations MUST be employed to prevent these substitution attacks. 233 For mitigations, see Section 3.7, Section 3.8, Section 3.9, and 234 Section 3.10. 236 3. Best Practices 238 The best practices listed below should be applied by practitioners to 239 mitigate the threats listed in the preceding section. 241 3.1. Perform Algorithm Verification 243 Libraries MUST enable the caller to specify a supported set of 244 algorithms and MUST NOT use any other algorithms when performing 245 cryptographic operations. The library MUST ensure that the "alg" or 246 "enc" header specifies the same algorithm that is used for the 247 cryptographic operation. Moreover, each key MUST be used with 248 exactly one algorithm, and this MUST be checked when the 249 cryptographic operation is performed. 251 3.2. Use Appropriate Algorithms 253 As Section 5.2 of [RFC7515] says, "it is an application decision 254 which algorithms may be used in a given context. Even if a JWS can 255 be successfully validated, unless the algorithm(s) used in the JWS 256 are acceptable to the application, it SHOULD consider the JWS to be 257 invalid." 259 Therefore, applications MUST only allow the use of cryptographically 260 current algorithms that meet the security requirements of the 261 application. This set will vary over time as new algorithms are 262 introduced and existing algorithms are deprecated due to discovered 263 cryptographic weaknesses. Applications must therefore be designed to 264 enable cryptographic agility. 266 That said, if a JWT is cryptographically protected by a transport 267 layer, such as TLS using cryptographically current algorithms, there 268 may be no need to apply another layer of cryptographic protections to 269 the JWT. In such cases, the use of the "none" algorithm can be 270 perfectly acceptable. JWTs using "none" are often used in 271 application contexts in which the content is optionally signed; then 272 the URL-safe claims representation and processing can be the same in 273 both the signed and unsigned cases. 275 3.3. Validate All Cryptographic Operations 277 All cryptographic operations used in the JWT MUST be validated and 278 the entire JWT MUST be rejected if any of them fail to validate. 279 This is true not only of JWTs with a single set of Header Parameters 280 but also for Nested JWTs, in which both outer and inner operations 281 MUST be validated using the keys and algorithms supplied by the 282 application. 284 3.4. Validate Cryptographic Inputs 286 Some cryptographic operations, such as Elliptic Curve Diffie-Hellman 287 key agreement ("ECDH-ES") take inputs that may contain invalid 288 values, such as points not on the specified elliptic curve or other 289 invalid points. Either the JWS/JWE library itself must validate 290 these inputs before using them or it must use underlying 291 cryptographic libraries that do so (or both!). 293 3.5. Ensure Cryptographic Keys have Sufficient Entropy 295 The Key Entropy and Random Values advice in Section 10.1 of [RFC7515] 296 and the Password Considerations in Section 8.8 of [RFC7518] MUST be 297 followed. In particular, human-memorizable passwords MUST NOT be 298 directly used as the key to a keyed-MAC algorithm such as "HS256". 300 3.6. Use UTF-8 302 [RFC7515], [RFC7516], and [RFC7519] all specify that UTF-8 be used 303 for encoding and decoding JSON used in Header Parameters and JWT 304 Claims Sets. Implementations and applications MUST do this, and not 305 use other Unicode encodings for these purposes. 307 3.7. Validate Issuer and Subject 309 When a JWT contains an "iss" (issuer) claim, the application MUST 310 validate that the cryptographic keys used for the cryptographic 311 operations in the JWT belong to the issuer. If they do not, the 312 application MUST reject the JWT. 314 The means of determining the keys owned by an issuer is application- 315 specific. As one example, OpenID Connect [OpenID.Core] issuer values 316 are "https" URLs that reference a JSON metadata document that 317 contains a "jwks_uri" value that is an "https" URL from which the 318 issuer's keys are retrieved as a JWK Set [RFC7517]. This same 319 mechanism is used by [I-D.ietf-oauth-discovery]. Other applications 320 may use different means of binding keys to issuers. 322 Similarly, when the JWT contains a "sub" (subject) claim, the 323 application MUST validate that the subject value corresponds to a 324 valid subject and/or issuer/subject pair at the application. This 325 may include confirming that the issuer is trusted by the application. 326 If the issuer, subject, or the pair are invalid, the application MUST 327 reject the JWT. 329 3.8. Use and Validate Audience 331 If the same issuer can issue JWTs that are intended for use by more 332 than one relying party or application, the JWT MUST contain an "aud" 333 (audience) claim that can be used to determine whether the JWT is 334 being used by an intended party or was substituted by an attacker at 335 an unintended party. Furthermore, the relying party or application 336 MUST validate the audience value and if the audience value is not 337 associated with the recipient, it MUST reject the JWT. 339 3.9. Use Explicit Typing 341 Confusion of one kind of JWT for another can be prevented by having 342 all the kinds of JWTs that could otherwise potentially be confused 343 include an explicit JWT type value and include checking the type 344 value in their validation rules. Explicit JWT typing is accomplished 345 by using the "typ" header parameter. For instance, the 346 [I-D.ietf-secevent-token] specification uses the "application/ 347 secevent+jwt" media type to perform explicit typing of Security Event 348 Tokens (SETs). 350 Per the definition of "typ" in Section 4.1.9 of [RFC7515], it is 351 RECOMMENDED that the "application/" prefix be omitted from the "typ" 352 value. Therefore, for example, the "typ" value used to explicitly 353 include a type for a SET SHOULD be "secevent+jwt". When explicit 354 typing is employed for a JWT, it is RECOMMENDED that a media type 355 name of the format "application/example+jwt" be used, where "example" 356 is replaced by the identifier for the specific kind of JWT. 358 Note that the use of explicit typing may not achieve disambiguation 359 from existing kinds of JWTs, as the validation rules for existing 360 kinds JWTs often do not use the "typ" header parameter value. 361 Explicit typing is RECOMMENDED for new uses of JWTs. 363 3.10. Use Mutually Exclusive Validation Rules for Different Kinds of 364 JWTs 366 Each application of JWTs defines a profile specifying the required 367 and optional JWT claims and the validation rules associated with 368 them. If more than one kind of JWT can be issued by the same issuer, 369 the validation rules for those JWTs MUST be written such that they 370 are mutually exclusive, rejecting JWTs of the wrong kind. To prevent 371 substitution of JWTs from one context into another, a number of 372 strategies may be employed: 374 - Use explicit typing for different kinds of JWTs. Then the 375 distinct "typ" values can be used to differentiate between the 376 different kinds of JWTs. 378 - Use different sets of required claims or different required claim 379 values. Then the validation rules for one kind of JWT will reject 380 those with different claims or values. 382 - Use different sets of required header parameters or different 383 required header parameter values. Then the validation rules for 384 one kind of JWT will reject those with different header parameters 385 or values. 387 - Use different keys for different kinds of JWTs. Then the keys 388 used to validate one kind of JWT will fail to validate other kinds 389 of JWTs. 391 - Use different "aud" values for different uses of JWTs from the 392 same issuer. Then audience validation will reject JWTs 393 substituted into inappropriate contexts. 395 - Use different issuers for different kinds of JWTs. Then the 396 distinct "iss" values can be used to segregate the different kinds 397 of JWTs. 399 Given the broad diversity of JWT usage and applications, the best 400 combination of types, required claims, values, header parameters, key 401 usages, and issuers to differentiate among different kinds of JWTs 402 will, in general, be application specific. 404 4. IANA Considerations 406 This document requires no IANA actions. 408 5. Acknowledgements 410 Thanks to Antonio Sanso for bringing the "ECDH-ES" invalid point 411 attack to the attention of JWE and JWT implementers. Thanks to Nat 412 Sakimura for advocating the use of explicit typing. 414 6. References 416 6.1. Normative References 418 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 419 Requirement Levels", BCP 14, RFC 2119, 420 DOI 10.17487/RFC2119, March 1997, 421 . 423 [RFC7159] Bray, T., Ed., "The JavaScript Object Notation (JSON) Data 424 Interchange Format", RFC 7159, DOI 10.17487/RFC7159, March 425 2014, . 427 [RFC7515] Jones, M., Bradley, J., and N. Sakimura, "JSON Web 428 Signature (JWS)", RFC 7515, DOI 10.17487/RFC7515, May 429 2015, . 431 [RFC7516] Jones, M. and J. Hildebrand, "JSON Web Encryption (JWE)", 432 RFC 7516, DOI 10.17487/RFC7516, May 2015, 433 . 435 [RFC7518] Jones, M., "JSON Web Algorithms (JWA)", RFC 7518, 436 DOI 10.17487/RFC7518, May 2015, 437 . 439 [RFC7519] Jones, M., Bradley, J., and N. Sakimura, "JSON Web Token 440 (JWT)", RFC 7519, DOI 10.17487/RFC7519, May 2015, 441 . 443 6.2. Informative References 445 [I-D.ietf-oauth-discovery] 446 Jones, M., Sakimura, N., and J. Bradley, "OAuth 2.0 447 Authorization Server Metadata", draft-ietf-oauth- 448 discovery-06 (work in progress), March 2017. 450 [I-D.ietf-secevent-token] 451 Hunt, P., Denniss, W., Ansari, M., and M. Jones, "Security 452 Event Token (SET)", draft-ietf-secevent-token-02 (work in 453 progress), June 2017. 455 [Langkemper] 456 Langkemper, S., "Attacking JWT Authentication", September 457 2016, . 460 [OpenID.Core] 461 Sakimura, N., Bradley, J., Jones, M., Medeiros, B., and C. 462 Mortimore, "OpenID Connect Core 1.0", November 2014, 463 . 465 [RFC6749] Hardt, D., Ed., "The OAuth 2.0 Authorization Framework", 466 RFC 6749, DOI 10.17487/RFC6749, October 2012, 467 . 469 [RFC7517] Jones, M., "JSON Web Key (JWK)", RFC 7517, 470 DOI 10.17487/RFC7517, May 2015, 471 . 473 [Sanso] Sanso, A., "Critical Vulnerability Uncovered in JSON 474 Encryption", March 2017, 475 . 478 Appendix A. Document History 480 [[ to be removed by the RFC editor before publication as an RFC ]] 482 A.1. draft-sheffer-oauth-jwt-bcp-01 484 - Added explicit typing. 486 A.2. draft-sheffer-oauth-jwt-bcp-00 488 - Initial version. 490 Authors' Addresses 492 Yaron Sheffer 493 Intuit 495 EMail: yaronf.ietf@gmail.com 497 Dick Hardt 498 Amazon 500 EMail: dick@amazon.com 502 Michael B. Jones 503 Microsoft 505 EMail: mbj@microsoft.com 506 URI: http://self-issued.info/