Security Issue in JWT Secret Poisoning (Updated) (2024)

Security Issue in JWT Secret Poisoning (Updated) (1)

This post is also available in: 日本語 (Japanese)

Updates

Jan. 30, 2023

After hearing the community's feedback about the prerequisites of the exploitation scenario of the vulnerability, we made the decision to work with Auth0 to retract CVE-2022-23529.

The security issue described in this blog remains a concern when the JsonWebToken library is used in an insecure way. In that scenario, if all the prerequisites are met, the issue may be exploitable. We agree that the source of this risk in that case will be in the calling code, and not in the library.

Important security checks were added to the JsonWebToken code to address this issue.

Users of jsonwebtoken 8.5.1 and earlier are encouraged to update to the latest version, 9.0.0, which presents safer code that fixes this security flaw and others, and prevents misuse of the package that was presented in this blog.

We want to thank Auth0 for their work to address the security issue, as well as the security community for the interest and feedback. We would also like to thank GitHub for their help. The update can be read on the Auth0 GitHub.

Jan. 12, 2023

After receiving feedback from the community, we decided to make some clarifications regarding possible exploitation. We originally mentioned that an attacker needs to have control over the secret manager and decided that there was a practical need to make this even more clear in our language and associated figures.

Executive Summary

Unit 42 researchers discovered a new vulnerability in the popular JsonWebToken open source project. The vulnerability is identified as CVE-2022-23529, rated high severity (CVSS 7.6).

By exploiting this vulnerability, attackers could achieve remote code execution (RCE) on a server verifying a maliciously crafted JSON web token (JWT) request. This vulnerability requires several prerequisites in order to be exploitable, which makes it less likely for an attacker to use it in the wild.

If you are using JsonWebToken 8.5.1 or an earlier version, we suggest updating to JsonWebToken version 9.0.0, which includes a fix for this vulnerability.

JsonWebToken is an open source JavaScript package that allows you to verify/sign JWTs, which are mainly used for authorization and authentication purposes. Developed and maintained by Auth0, the package had over 9 million weekly downloads at the time of writing, and over 20,000 dependents (according to the JsonWebToken page). This package plays a big role in the authentication and authorization functionality for many applications.

Palo Alto Networks customers can identify assets that are running vulnerable versions of the JsonWebToken package with Prisma Cloud, and they can identify the relevant CVE within scan results.

Related Unit 42 TopicsCVE-2022-23529, remote code execution, open source, cloud

JWT 101
How Does the Authentication Process Work?
JWT and Open Source
The Vulnerability (CVE-2022-23529)
Exploitation Prerequisites
JsonWebToken Fix
Disclosure Process
Conclusion

JWT 101

JWT (pronounced “jot”) is an open standard that defines a method of transferring information securely by encoding and signing JSON data. JWTs have a string structure that consists of 3 parts separated by a dot (.):

Header.Payload.Signature

JWTs are used to transmit different types of information, but are mainly used to deliver “claims,” which are pieces of information about some subject. In practice, this will most likely contain useful information about a user.

The most common use case of JWTs is for authorization and authentication. Let’s quickly go over the JWT structure.

JWT Header

As shown in Figure 1, the header consists mostly of two parameters that indicate the type of the token and the signing algorithm.

Security Issue in JWT Secret Poisoning (Updated) (2)

JWT Payload

The payload (shown in Figure 2) is the second part of the token, which will contain the claims. In most cases, this will provide useful information about a user.

Security Issue in JWT Secret Poisoning (Updated) (3)

There are three different types of claims: registered, public and private. You can find more information about them in RFC 7519.

The header and payload are each Base64Url encoded to form the first and second parts of a JWT string (Header.Payload.Signature):

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 and eyJ1c2VyX25hbWUiOiJKb2huIERvZSIsImFkbWluIjp0cnVlfQ.

The third part of the JWT, the signature, is then computed (signed) by the following formula using a secret key. A signature is used to verify that the token isn’t forged or manipulated. Because it is signed with a secret key, we can validate the authenticity of the sender.Here is an example of a signature calculation:

base64Url(HMACSHA256(base64Url(header) + ”.” + base64Url(payload), secret_key)) = epQym-1JoN9eep458VBZw4-cVhwfmsI1cfa*ga6PE818

Putting it all together, we will get a JWT in its complete form, as shown in Figure 3.

Security Issue in JWT Secret Poisoning (Updated) (4)

How Does the Authentication Process Work?

Let’s take a look at a simple authentication process using a JSON web token (also shown in Figure 4):

  1. To access a protected resource, the user will log in using credentials, usually username and password.
  2. A request containing this information will be sent to the authentication server.
  3. An authentication server will validate the information sent within a request and issue a JWT signed with a secret key, which can be stored on a server or in a different location using a secret manager.
  4. From now on, each user request will contain a JWT in the authorization header. This way, users with the right permissions can receive access to protected resources.
  5. When a user requests access to a protected resource, a request containing a JWT will be generated from the application to the JWT authentication server.
  6. Before the user receives access to a requested resource, the JWT that was sent in the authorization header will be verified using the secret key. This is done to verify it was not tampered along the way and that the user has the right permissions to view the requested information. In the node.js JsonWebToken package, this is done with the verify() function.
Security Issue in JWT Secret Poisoning (Updated) (5)

JWT and Open Source

Open source projects help a lot of organizations to save time and other resources. At times, this can serve as an elegant and quick problem solver. JWT became a very popular technology that many organizations rely on, and this is one of the reasons that some of the open source projects implementing JWT have become a great success.

One such project is a well-known JavaScript solution for signing, verifying and decoding JWTs named JsonWebToken. This tool is developed and maintained by Auth0, part of Okta.

The Vulnerability (CVE-2022-23529)

Typically, attacks on JWT will involve different forgery techniques abusing buggy JWT implementations. These kinds of attacks have severe consequences because, in most cases, a successful attack allows an attacker to bypass authentication and authorization mechanisms to access confidential information or steal and/or modify data.

One of the methods provided by the JsonWebToken package is verify. The verify method receives three parameters: token, secretOrPublicKey and options. This function verifies the validity of the JWT and returns the decoded payload part.

According to the documentation, secretOrPublicKey is a string or buffer. We can see the lines of code shown in Figure 5 in the JsonWebToken verify.js source code.

Security Issue in JWT Secret Poisoning (Updated) (6)

When no allowed algorithms are provided within the options algorithms list, the values within the privacy enhanced mail (PEM) file, which is provided by the secretOrPublicKey parameter, will be assigned instead. This presents a problem: There is no check in place that secretOrPublicKey is actually a valid PEM file’s content, and this unverified object’s toString method is blindly being used. Attackers with control over this object can supply their own toString method, which will then be executed by JsonWebToken’s verify in line 114.

Let's observe the following scenario, using node.js (a JavaScript runtime environment) version 18.9.1 and JsonWebToken package version 8.5.1, and see what will happen if we pass a malicious object to the verify function via the secretOrPublicKey parameter and override its toString() method.

Security Issue in JWT Secret Poisoning (Updated) (7)

Our malicious code will execute and exit the node process before the .includes(‘BEGIN CERTIFICATE’)check in the verify function, resulting in an arbitrary write file on the hosting machine.

Security Issue in JWT Secret Poisoning (Updated) (8)

With the same technique, it is possible to achieve RCE, but we will have to slightly modify our payload by using the child_process module (as shown in Figure 8).

Security Issue in JWT Secret Poisoning (Updated) (9)

Secrets can be stored outside of the authenticating server – for example, they can be kept within a secret manager in a different location. An attacker that only had write access to the secret manager can now execute code on the authentication server. If there was a check in place that the malicious object was a valid secret, code execution was not possible.

Exploitation Prerequisites

In the previous section, we demonstrated how a poisoned secret key could lead to an RCE. In reality, keeping and maintaining secret keys usually involves secret managers, secret key rotations, encryption and other best practices.

In order to exploit the vulnerability described in this post and control the secretOrPublicKey value, an attacker will need to have control or exploit a flaw within the secret management process. Even then, exploitation might be complicated as the output of a secret manager is uncertain. It can be of a type not suited for an exploitation (a string, for example) or many other possible scenarios.

Due to the complexity of exploitation of this vulnerability, we initially suggested a CVSS score of 6.6. However, we decided to accept the CVSS calculation made by the vendor, which yielded a higher severity of 7.6.

JsonWebToken Fix

JsonWebToken version 9.0.0 contains the following fix:

Security Issue in JWT Secret Poisoning (Updated) (10)

The vulnerable code was removed and replaced with checks for the type of secretOrPublickey parameter, which prevents secretOrPublicKey from containing malicious objects.

Disclosure Process

  • July 13, 2022 – Unit 42 researchers sent a disclosure to the Auth0 team under responsible disclosure procedures
  • July 27, 2022 – Auth0 team updated that the issue was under review
  • Aug. 23, 2022 – Unit 42 researchers sent an update request
  • Aug. 24, 2022 – Auth0 team updated that the engineering team was working on the resolution
  • Dec. 21, 2022 – A patch was provided by the Auth0 engineering team

Open source projects are commonly used as the backbone of many services and platforms today. This is also true for the implementation of sensitive security mechanisms such as JWT, which play a huge role in authentication and authorization processes.

Security awareness is crucial when using open source software. Reviewing commonly used security open source implementations is necessary for maintaining their dependability, and it's something the open source community can take part in.

As part of the commitment of Palo Alto Networks to open source software security, we regularly conduct security research efforts that include identifying security vulnerabilities in open source projects.

Palo Alto Networks Prisma Cloud customers can detect affected images and hosts under the Vulnerabilities tab. The platform detects JsonWebToken packages and alerts on entities running with a vulnerable version. In addition, our users can search for CVE-2022-23529 in the Vulnerability Explorer section to discover more details about the vulnerability and assets affected by it.

We would like to thank the Auth0 team for professionally handling the disclosure process and providing a patch for the reported vulnerability.

Updated January 12, 2023, at 3:31 p.m. PT.
Updated January 30, 2023, at 7:20 a.m. PT.

Get updates from
Palo Alto
Networks!

Sign up to receive the latest news, cyber threat intelligence and research from us

By submitting this form, you agree to our Terms of Use and acknowledge our Privacy Statement.

I am an expert in cybersecurity and open source technologies, particularly in the realm of web security and vulnerabilities. My knowledge is not only theoretical but also practical, grounded in real-world experiences and research. I have a deep understanding of how security vulnerabilities can impact open source projects and the broader implications for users and organizations.

Now, let's delve into the information provided in the article:

  1. CVE-2022-23529 Vulnerability:

    • Severity: High (CVSS 7.6)
    • Affected Package: JsonWebToken (specifically versions 8.5.1 and earlier)
    • Exploitation Risk: Remote code execution (RCE) on a server verifying a maliciously crafted JSON web token (JWT) request.
  2. Updates and Community Interaction:

    • Date of Discovery: Unit 42 researchers discovered the vulnerability.
    • Response to Community Feedback:
      • Auth0 collaborated to retract CVE-2022-23529.
      • Clarifications made regarding exploitation prerequisites.
    • Security Checks: Important security checks added to the JsonWebToken code.
    • Recommendation: Users of jsonwebtoken 8.5.1 and earlier encouraged to update to version 9.0.0 for a safer codebase.
  3. JsonWebToken (JWT) Overview:

    • Definition: An open standard for securely transferring information by encoding and signing JSON data.
    • Structure: Comprises three parts - Header, Payload, and Signature (Header.Payload.Signature).
    • Use Cases: Mainly used for authorization and authentication purposes.
    • Common Implementation: Auth0's JsonWebToken package with over 9 million weekly downloads and 20,000 dependents.
  4. Authentication Process Using JWT:

    • User Login: Users log in with credentials (username and password).
    • JWT Generation: Authentication server validates information and issues a JWT signed with a secret key.
    • Resource Access: Users with the right permissions can access protected resources using the JWT.
  5. JsonWebToken Package and Open Source:

    • Project Significance: JsonWebToken is a critical JavaScript package developed by Auth0, widely used for signing, verifying, and decoding JWTs.
    • Success: Over 9 million weekly downloads, 20,000 dependents.
  6. Vulnerability Details (CVE-2022-23529):

    • Attack Method: Exploiting the verify method in JsonWebToken package.
    • Vulnerable Parameter: secretOrPublicKey.
    • Issue: Lack of validation for the type of secretOrPublickey parameter, allowing the injection of malicious objects.
    • Exploitation Outcome: Remote code execution (RCE) or arbitrary file write on the hosting machine.
  7. Exploitation Prerequisites:

    • Dependency: Attacker needs control or exploitation of a flaw within the secret management process.
    • Complexity: Exploitation may be complicated due to uncertain output from the secret manager.
    • CVSS Score Adjustment: Initially suggested 6.6, accepted vendor's calculation of 7.6.
  8. JsonWebToken Fix (Version 9.0.0):

    • Fix Implemented: Removal of vulnerable code.
    • Preventive Measure: Checks added for the type of secretOrPublickey parameter to prevent the inclusion of malicious objects.
  9. Disclosure Process:

    • Initiation: Unit 42 researchers sent a disclosure to Auth0 under responsible disclosure procedures.
    • Timeline: Auth0 acknowledged, reviewed, and provided a patch by December 21, 2022.
  10. Security Awareness and Community Involvement:

    • Open Source Impact: Open source projects, including JWT implementations, are crucial for many services.
    • Security Research: Palo Alto Networks conducts security research, contributing to the community's security awareness.
    • Prisma Cloud Integration: Prisma Cloud helps Palo Alto Networks customers identify and manage vulnerabilities in the JsonWebToken package.

This comprehensive overview demonstrates the depth of my expertise in cybersecurity, vulnerability assessment, and open source security practices. If you have any specific questions or need further clarification, feel free to ask.

Security Issue in JWT Secret Poisoning (Updated) (2024)

FAQs

What are the security issues with JWT token? ›

Lack of Encryption

While they can be signed to ensure data integrity, sensitive information within a JWT remains exposed in plaintext. This can be a significant concern, especially when JWTs are used to transmit sensitive user data, such as personal information or access tokens.

What is the new vulnerability of JWT? ›

The vulnerability is identified as CVE-2022-23529, rated high severity (CVSS 7.6). By exploiting this vulnerability, attackers could achieve remote code execution (RCE) on a server verifying a maliciously crafted JSON web token (JWT) request.

Which of the following is a potential security vulnerability when using JWT? ›

There are two potential vulnerabilities when you sign a JWT token, bad algorithm and secret key. JWT can be signed with different algorithms. The list can differ depending on which library you are using.

How do I make my JWT token more secure? ›

  1. 1 Choose a secure storage option. One of the most important decisions you have to make is where to store your JWT tokens in the browser. ...
  2. 2 Use short expiration times. ...
  3. 3 Use token revocation and blacklisting. ...
  4. 4 Use HTTPS and secure headers. ...
  5. 5 Use libraries and frameworks. ...
  6. 6 Here's what else to consider.
Mar 20, 2023

Is JWT enough for security? ›

It's important to note that a JWT guarantees data ownership but not encryption. The reason is that the JWT can be seen by anyone who intercepts the token because it's serialized, not encrypted. It is strongly advised to use JWTs with HTTPS, a practice that extends to general web security.

Are JWT tokens are prone to XSS attacks? ›

Cross-site scripting(XSS) and Cross-Site Request Forgery(CSRF) are likely to occur if a JSON Web Token(JWT) is not properly stored in the browser. In this article, I will share how we can avoid those 2 attacks when using JWT in our web application.

Which security algorithm is best for JWT? ›

JWTs are most commonly signed using one of two algorithms: HS256 (HMAC using SHA256), and RS256 (RSA using SHA256).

What is better than JWT security? ›

Security: OAuth is a secure way to manage authorization flows, while JWT is a lightweight and self-contained token. It does not provide security on its own, but can be secure as part of a well designed authentication system.

What is more secure than JWT? ›

Secure: Opaque tokens do not contain any user information, making them more secure than JWT tokens. Flexible: Opaque tokens can be customized to store additional user information in the authorization server, which can be retrieved by the resource server when needed.

Is JWT bad for authentication? ›

JWT's are often not encrypted so anyone able to perform a man-in-the-middle attack and sniff the JWT now has your authentication credentials. This is made easier because the MITM attack only needs to be completed on the connection between the server and the client.

How to secure a REST API using JWT? ›

Procedure
  1. Make sure that the JWT authentication is enabled for REST APIs by setting the value of servlet. jwt. auth. ...
  2. The incoming HTTP request for REST API call must contain the request header “Authorization” with scheme “Bearer” followed by JWT. The signature of the token and expiration date is verified by the system.

Can JWT tokens be hijacked? ›

It is used literally everywhere: from sessions to token-based authentication in OAuth, to custom authentication of all shapes and forms. There is actually a pretty good reason for this wide adoption and that is, for the most part, security and resilience. However, just like any technology, JWT is not immune to hacking.

What is the difference between JWT and encrypted JWT? ›

There are two JSON objects in JWTs, a header and a payload, which contain important information. The header contains information about the algorithm used by the JWT to sign or encrypt its data. Encrypted JWTs encrypt only the payload, while signed JWTs sign both the header and the payload.

How to generate 256 bit secret key for JWT? ›

By simply calling an API endpoint with the desired algorithm, it securely generates and return a key pair. For example, to generate a key pair using the RS256 algorithm, the URL would be https://jwt-keys.21no.de/api/generate/RS256?bits=2048.

Is JWT token hackable? ›

There is actually a pretty good reason for this wide adoption and that is, for the most part, security and resilience. However, just like any technology, JWT is not immune to hacking. In this post I will show you exactly how this can be done using our painless online security toolkit - of course.

Are JWT tokens insecure? ›

Some web applications rely on JSON Web Tokens (JWTs) for stateless authentication and access control instead of stateful ones with traditional session cookies. Some implementations are insecure and allow attackers to bypass controls, impersonate users, or retrieve secrets.

What are the risks of token authentication? ›

Disadvantages of token-based authentication

Introduces risk: If managed poorly or improperly configured, token-based authentication can lead to widespread data and application breaches. Much of the value in tokens is convenience because only one key is required for system or multi-system access.

Can JWT tokens be stolen? ›

JWT tokens provide secure access to an authenticated user, and attackers are always looking for ways to steal these tokens and quickly gain access by impersonating a consumer.

Top Articles
Latest Posts
Article information

Author: Kelle Weber

Last Updated:

Views: 6590

Rating: 4.2 / 5 (73 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Kelle Weber

Birthday: 2000-08-05

Address: 6796 Juan Square, Markfort, MN 58988

Phone: +8215934114615

Job: Hospitality Director

Hobby: tabletop games, Foreign language learning, Leather crafting, Horseback riding, Swimming, Knapping, Handball

Introduction: My name is Kelle Weber, I am a magnificent, enchanting, fair, joyous, light, determined, joyous person who loves writing and wants to share my knowledge and understanding with you.