# Unsanitized User Input in Resource Rendering

## Overview

* **Rule ID**: `javascript_express_external_resource`
* **Applicable Languages**: Javascript
* **Weakness ID**: CWE-706

## Description

Exception messages that expose sensitive information can be a critical security vulnerability. When exception details are printed directly to the default output, they might reveal crucial information about the application’s configuration or environment, such as file paths, server details, or database configurations. This not only aids attackers in identifying potential entry points but also risks exposing user-specific data, leading to privacy violations.

## Remediation Guidelines

* **Do not** pass user or request input directly to `res.render()` without sanitization. Using user input directly in resource rendering can introduce security risks.

  ```java
  res.render(req.body.page); // unsafe
  System.out.println(e); // Unsafe

  ```
* **Instead, sanitize the input or use a safelist** if you need to rely on user input for resource rendering. This ensures that only expected and safe resources are rendered.

  ```java
  var path = req.body.path;
  if (['users', 'posts', 'pages'].includes(path)) {
      return res.render(`${path}/success`);
  }
  ```

## References

* [**CWE-706: Use of Incorrectly-Resolved Name or Reference**](https://cwe.mitre.org/data/definitions/706.html)
* [**OWASP Top 10: A01:2021 - Broken Access Control**](https://owasp.org/Top10/A01_2021-Broken_Access_Control/)

## 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/unsanitized-user-input-in-resource-rendering.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.
