# Leakage of sensitive data in JWT

## Overview

* **Rule ID**: `javascript_lang_jwt`
* **Applicable Languages**: Javascript
* **Weakness ID**: CWE-312

## Description

Storing sensitive data in JWTs exposes it to potential security risks. While JWTs are meant for securely transmitting data between parties, they are not inherently secure for storing sensitive information.

## Remediation Guidelines

* **Avoid** including sensitive data, such as email addresses, in JWTs. This can result in unauthorized access to personal information.

  ```java
  const jwt = require('jsonwebtoken');
  const token = jwt.sign({ user: { email: 'john@gmail.com' }}); // unsafe


  ```
* **Use non-sensitive**, unique identifiers like a user's UUID in JWTs to reference user information securely.

  ```java
  const jwt = require('jsonwebtoken');
  const token = jwt.sign({ user: user.uuid });
  ```

## References

* [**OWASP sensitive data exposure**](https://owasp.org/www-project-top-ten/2017/A3_2017-Sensitive_Data_Exposure)
* [**CWE-312: Cleartext Storage of Sensitive Information**](https://cwe.mitre.org/data/definitions/312.html)
* [**OWASP Top 10: A04:2021 - Insecure Design**](https://owasp.org/Top10/A04_2021-Insecure_Design/)

## Configuration

To omit this rule during a scan, and to provide you with continuous 24/7 code-level scanning, you can employ our [**SAST TOOL**](https://scopy.sec1.io/login)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sec1.io/user-docs/4-sast/3-javascript/leakage-of-sensitive-data-in-jwt.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
