# Unsanitized User Input in UI

## Overview

* **Rule ID**: `javascript_express_ui_redress`
* **Applicable Languages**: Javascript
* **Weakness ID**: CWE-1021

## Description

UI redress attacks, also known as clickjacking, occur when an attacker manipulates the appearance of a webpage to deceive users into performing unintended actions. One common vector for such attacks is the misuse of HTTP headers like X-Frame-Options and Content-Security-Policy (CSP), especially when they are configured with unsanitized user input.

## Remediation Guidelines

* Do set the most secure values for these headers to enhance protection against clickjacking.

  ```javascript
  res.set('X-Frame-Options', 'DENY');
  res.set('Content-Security-Policy', "frame-ancestors 'none'");

  ```
* Do not directly use user input to set these headers. Instead, implement a safelist approach to ensure only approved values are used.

  ```javascript
  const frameOptions = ['deny', 'sameorigin'];

  if (frameOptions.includes(req.query.options.toLowerCase())) {
    res.set('X-Frame-Options', req.query.options.toUpperCase());
  }

  ```

## References

* [**OWASP Clickjacking attack explained**](https://owasp.org/www-community/attacks/Clickjacking)
* [**OWASP Clickjacking defense cheat sheet**](https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html)
* [**CWE-1021: Improper Restriction of Rendered UI Layers or Frames**](https://cwe.mitre.org/data/definitions/1021.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/unsanitized-user-input-in-ui.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.
