> For the complete documentation index, see [llms.txt](https://docs.sec1.io/user-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sec1.io/user-docs/4-sast/3-javascript/unsanitized-user-input-in-ui.md).

# 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)
