> 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/2-java/missing-http-only-option-in-cookie-configuration.md).

# Missing HTTP Only Option in Cookie Configuration

## Overview

* **Rule ID**: `java_lang_cookie_missing_http_only`
* **Applicable Languages**: Java
* **Weakness ID**: CWE-1004

## Description

Not configuring the HTTP Only attribute as `true` in cookie settings exposes the cookie to potential access by client-side JavaScript. This oversight can lead to the exposure of sensitive cookie values, especially on websites vulnerable to Cross-Site Scripting (XSS) attacks. Enabling HTTP Only is critical to prevent malicious scripts from accessing cookie values through JavaScript.

## Remediation Guidelines

To protect cookies from unauthorized access by client-side JavaScript, always set the HTTP Only attribute to `true`. This is a crucial measure in safeguarding your cookies against XSS vulnerabilities.

```java
cookie.setHttpOnly(true);
```

## Refrences

* [**CWE-1004: Sensitive Cookie Without 'HttpOnly' Flag**](https://cwe.mitre.org/data/definitions/1004.html)
* [**A05:2021 - Security Misconfiguration**](https://owasp.org/Top10/A05_2021-Security_Misconfiguration/)

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