# Missing TLS validation

## Overview

* **Rule ID**: `java_lang_ssl_verification`
* **Applicable Languages**: Java
* **Weakness ID**: CWE-295

## Description

Your code is at risk of Man-in-the-Middle attacks if it fails to validate TLS certificates. This vulnerability occurs when your application connects without verifying the server's hostname, exposing it to data interception and other security threats. Using deprecated components like `DefaultHttpClient`, which does not perform hostname verification, or relying on the SSL protocol, known for its security flaws, further exacerbates these risks.

## Remediation Guidelines

* **Use** modern HTTP clients, such as `java.net.http.HttpClient`, that automatically handle TLS validation.
* Whenever possible, **prefer the latest TLS protocol over SSL** to enhance security. Explicitly request TLS in your application to mitigate vulnerabilities associated with SSL.

  ```java
  SSLContext.getInstance("TLS");
  ```
* **Avoid** relying on deprecated HTTP clients like `DefaultHttpClient`, as they do not perform essential security checks such as TLS validation, leaving your application vulnerable."

## References

* [**CWE-295: Improper Certificate Validation**](https://cwe.mitre.org/data/definitions/295.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-tls-validation.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.
