# CVE-2024-7318: Keycloak-core: one time passcode (otp) is valid longer than expiration timeseverity

> Expired OTP codes remain valid for an extended period, allowing attackers to bypass two-factor authentication and compromise user accounts.

- **Severity:** Medium 4.8 (`CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:L/A:N`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 9 Sep 2024
- **Updated:** 26 Jan 2026
- **Also known as:** BIT-keycloak-2024-7318, GHSA-xmmm-jw76-q7vg

## What is CVE-2024-7318?

CVE-2024-7318 is a medium-severity vulnerability in Redhat Build of Keycloak, published on 9 Sep 2024. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

A vulnerability was found in Keycloak. Expired OTP codes are still usable when using FreeOTP when the OTP token period is set to 30 seconds (default). Instead of expiring and deemed unusable around 30 seconds in, the tokens are valid for an additional 30 seconds totaling 1 minute.
A one time passcode that is valid longer than its expiration time increases the attack window for malicious actors to abuse the system and compromise accounts. Additionally, it increases the attack surface because at any given time, two OTPs are valid.

Weakness: CWE-324 (Use of a Key Past its Expiration Date)

## Which versions are affected by CVE-2024-7318?

5 open source packages ship an affected version, including org.keycloak:keycloak-core and keycloak. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `org.keycloak:keycloak-core` | Maven | All versions | 24.0.7 |
| `org.keycloak:keycloak-core` | Maven | All versions | 24.0.7 |
| `org.keycloak:keycloak-core` | Maven | From 25.0.0 | 25.0.4 |
| `org.keycloak:keycloak-core` | Maven | From 25.0.0 | 25.0.4 |
| `keycloak` | Bitnami | From 22.0.0 | 24.0.7 |

Products: Redhat Build of Keycloak.

## How do I fix CVE-2024-7318?

Upgrade org.keycloak:keycloak-core to a fixed version for your release line: 24.0.7 or 25.0.4.

## Is CVE-2024-7318 being exploited?

There is no known exploitation of CVE-2024-7318 in the wild and no public exploit code.

## Other vulnerabilities in Redhat Build of Keycloak

- [CVE-2026-15572](https://insights.sbomify.com/CVE-2026-15572/): Keycloak-services: keycloak-services: dcr protocol mapper type-swap policy bypass allows privilege escalation (high 8.8)
- [CVE-2026-3047](https://insights.sbomify.com/CVE-2026-3047/): Keycloak SAML Broken has Authentication Bypass by Primary Weakness (high 8.8)
- [CVE-2026-15573](https://insights.sbomify.com/CVE-2026-15573/): Keycloak-services: keycloak-services: authorization bypass via unnormalized uri matching in pathmatcher (high 8.1)
- [CVE-2026-16102](https://insights.sbomify.com/CVE-2026-16102/): Keycloak-services: keycloak-services: default dcr policy allows role forgery via user property mappers (high 8.1)
- [CVE-2026-1609](https://insights.sbomify.com/CVE-2026-1609/): Org.keycloak/keycloak-quarkus-server: keycloak: unauthorized access via jwt authorization grant with disabled users (high 8.1)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2024-7318 and fix it if it is affected.

What it is: CVE-2024-7318 is a medium-severity vulnerability in Redhat Build of Keycloak, published on 9 Sep 2024. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: There is no known exploitation of CVE-2024-7318 in the wild and no public exploit code.

Affected packages and fixed versions:
- org.keycloak:keycloak-core (Maven): affected all versions; fixed in 24.0.7
- org.keycloak:keycloak-core (Maven): affected all versions; fixed in 24.0.7
- org.keycloak:keycloak-core (Maven): affected from 25.0.0; fixed in 25.0.4
- org.keycloak:keycloak-core (Maven): affected from 25.0.0; fixed in 25.0.4
- keycloak (Bitnami): affected from 22.0.0; fixed in 24.0.7

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2024-7318/ (Markdown: https://insights.sbomify.com/CVE-2024-7318/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2024-7318
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2024-7318
- OSV: https://osv.dev/vulnerability/CVE-2024-7318

---
From sbomify Insights: https://insights.sbomify.com/CVE-2024-7318/
Summaries are generated and may contain mistakes; the official description above is the record.
