# Observable Timing Discrepancy

## Overview

* **Rule ID**: `java_lang_observable_timing`
* **Applicable Languages**: Java
* **Weakness ID**: CWE-208

## Description

Observable Timing Discrepancy occurs when attackers can measure and observe the duration of specific operations. This vulnerability is especially problematic when sensitive information is involved, such as password checks or secret comparisons. By analyzing the time taken for these operations, attackers might deduce confidential details, putting your data at risk.

## Remediation Guidelines

* **Use** algorithms that process sensitive information in constant time to prevent attackers from inferring secrets based on operation duration.
* **Utilize** built-in security features and cryptographic libraries that provide functions safe from timing attacks for comparing secret values.
* **Avoid** direct string comparisons for sensitive information, as early termination on a mismatch can reveal timing information.

  ```java
  boolean isAdmin = "admin".equals(username); // unsafe
  ```
* **Avoid** designing application logic that alters execution paths in a way that could create timing discrepancies based on user input or secret values.

## References

* [**OWASP Guide to Cryptography**](https://cheatsheetseries.owasp.org/cheatsheets/Cryptographic_Storage_Cheat_Sheet.html)
* [**CWE-208: Observable Timing Discrepancy**](https://cwe.mitre.org/data/definitions/208.html)

## 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/observable-timing-discrepancy.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.
