# Missing Protection against Session Fixation Attacks

## Overview

* **Rule ID**: `java_spring_missing_session_fixation`
* **Applicable Languages**: Java
* **Weakness ID**: CWE-384

## Description

A session fixation attack occurs when an attacker sets a user's session ID to a known value before login, potentially leading to unauthorized session hijacking. By default, the Spring framework mitigates this risk by creating a new session or changing the user's session ID upon login. Disabling this default behavior increases your application's vulnerability to session fixation attacks.

## Remediation Guidelines

* **Do not** disable Spring's default session fixation protection, as it removes a critical layer of security.

  ```java
  http.sessionManagement().sessionFixation().none() // not recommended
  ```
* **Instead, implement a session fixation protection strategy** by configuring Spring to create a new session or migrate to a new session ID upon login. This step is crucial for safeguarding user sessions against hijacking.

  ```java
  http.sessionManagement().sessionFixation().newSession() // or
  http.sessionManagement().sessionFixation().migrateSession()

  ```

## References

* [**OWASP Session Management Cheat Sheet**](https://cheatsheetseries.owasp.org/cheatsheets/Session_Management_Cheat_Sheet.html)
* [**Java Spring Session Fixation Configurer**](https://docs.spring.io/spring-security/site/docs/5.1.x/api/org/springframework/security/config/annotation/web/configurers/SessionManagementConfigurer.SessionFixationConfigurer.html)
* [**CWE-384: Session Fixation**](https://cwe.mitre.org/data/definitions/384.html)
* [**OWASP Top 10: A07:2021 - Identification and Authentication Failures**](https://owasp.org/Top10/A07_2021-Identification_and_Authentication_Failures/)

## 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/2-java/missing-protection-against-session-fixation-attacks.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.
