# Unsanitized user input in HTTP request (SSRF)

## Overview

* **Rule ID**: `javascript_express_server_side_request_forgery`
* **Applicable Languages**: Javascript
* **Weakness ID**: CWE-918

## Description

Incorporating unsanitized user input directly into URLs for data retrieval exposes your application to server-side request forgery (SSRF) attacks. This vulnerability occurs when URLs include user-provided data without proper validation or sanitization.

## Remediation Guidelines

* **Do not** directly use user input to construct URLs for backend requests, as this can lead to SSRF vulnerabilities.

  ```javascript
  axios.get(`https://${req.params.host}`); // unsafe

  ```
* **Do validate** or sanitize user input before using it in URLs. Prefer using a predefined list of allowed hosts and map user input to this list to ensure only safe and expected URLs are constructed.

  ```javascript
  var host = "default-api.com";
  if (req.params.host === "something-else") {
  host = "other-api.com";
  }

  axios.get(`https://${host}`);
  ```

## References

* [**OWASP - Server-Side Request Forgery (SSRF) prevention cheat sheet**](https://cheatsheetseries.owasp.org/cheatsheets/Server_Side_Request_Forgery_Prevention_Cheat_Sheet.html)
* [**CWE-918: Server-Side Request Forgery (SSRF)**](https://cwe.mitre.org/data/definitions/918.html)
* [**OWASP Top 10: A10:2021 - Server-side Request Forgery (SSRF)**](https://owasp.org/Top10/A10_2021-Server-Side_Request_Forgery_%28SSRF%29/)

## 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-http-request-ssrf.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.
