# Leakage of sensitive data in dynamic file generation

## Overview

* **Rule ID**: `javascript_lang_file_generation`
* **Applicable Languages**: Javascript
* **Weakness ID**: CWE-313

## Description

Sensitive data leakage in dynamic file generation occurs when confidential information is written to static files, such as logs, backups, or data exports. This vulnerability can expose sensitive data to unauthorized access, increasing the risk of data breaches or misuse.

## Remediation Guidelines

* **Do not** write sensitive data directly to logs, backups, or data exports. This practice can lead to unauthorized access and compromise the confidentiality of the information.

  ```java
  fs.writeFile("data.csv", JSON.stringify(users), "utf-8", (err) => {
    if (err) console.log(err)
  })

  ```
* **Do** obfuscate or filter sensitive data before writing it to static files. This reduces the risk of sensitive data exposure.

## References

* [**CWE-313: Cleartext Storage in a File or on Disk**](https://cwe.mitre.org/data/definitions/313.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-dynamic-file-generation.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.
