# CVE-2025-31498: c-ares has a use-after-free in read_answers()

> A use-after-free in c-ares allows remote or local attackers to cause denial of service or potentially execute code via crafted DNS responses.

- **Severity:** High 8.3 (`CVSS:4.0/AV:N/AC:H/AT:N/PR:N/UI:N/VC:L/VI:L/VA:H/SC:N/SI:N/SA:N`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 8 Apr 2025
- **Updated:** 8 Apr 2025
- **Also known as:** ALPINE-CVE-2025-31498, ALSA-2025:4461, ALSA-2025:7426, ALSA-2025:7502, AZL-59742, BELL-CVE-2025-31498, CLEANSTART-2025-JX38595, DEBIAN-CVE-2025-31498, ECHO-6bde-78e8-d894, GHSA-6hxc-62jh-p29v, MINI-xvq2-8p4m-7v2c, RHSA-2025:4461, RHSA-2025:7426, RHSA-2025:7502, RHSA-2025:7537, RLSA-2025:4461, RLSA-2025:7426, ROOT-OS-ALPINE-320-CVE-2025-31498, USN-7477-1, openSUSE-SU-2025:14977-1

## What is CVE-2025-31498?

CVE-2025-31498 is a high-severity use after free vulnerability in c-ares, published on 8 Apr 2025. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

c-ares is an asynchronous resolver library. From 1.32.3 through 1.34.4, there is a use-after-free in read_answers() when process_answer() may re-enqueue a query either due to a DNS Cookie Failure or when the upstream server does not properly support EDNS, or possibly on TCP queries if the remote closed the connection immediately after a response. If there was an issue trying to put that new transaction on the wire, it would close the connection handle, but read_answers() was still expecting the connection handle to be available to possibly dequeue other responses. In theory a remote attacker might be able to trigger this by flooding the target with ICMP UNREACHABLE packets if they also control the upstream nameserver and can return a result with one of those conditions, this has been untested. Otherwise only a local attacker might be able to change system behavior to make send()/write() return a failure condition. This vulnerability is fixed in 1.34.5.

Weakness: CWE-416 (Use After Free)

## Which versions are affected by CVE-2025-31498?


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `nodejs` | AlmaLinux:10 | All versions | 1:22.15.0-1.el10_0 |
| `nodejs-devel` | AlmaLinux:10 | All versions | 1:22.15.0-1.el10_0 |
| `nodejs-docs` | AlmaLinux:10 | All versions | 1:22.15.0-1.el10_0 |
| `nodejs-full-i18n` | AlmaLinux:10 | All versions | 1:22.15.0-1.el10_0 |
| `nodejs-libs` | AlmaLinux:10 | All versions | 1:22.15.0-1.el10_0 |
| `nodejs-npm` | AlmaLinux:10 | All versions | 1:10.9.2-1.22.15.0.1.el10_0 |
| `nodejs` | AlmaLinux:8 | All versions | 1:20.19.1-1.module_el8.10.0+3987+dbda4426 |
| `nodejs-devel` | AlmaLinux:8 | All versions | 1:20.19.1-1.module_el8.10.0+3987+dbda4426 |
| `nodejs-docs` | AlmaLinux:8 | All versions | 1:20.19.1-1.module_el8.10.0+3987+dbda4426 |
| `nodejs-full-i18n` | AlmaLinux:8 | All versions | 1:20.19.1-1.module_el8.10.0+3987+dbda4426 |
| `nodejs-nodemon` | AlmaLinux:8 | All versions | 3.0.1-1.module_el8.10.0+3982+85c136aa |
| `nodejs-packaging` | AlmaLinux:8 | All versions | 2021.06-4.module_el8.10.0+3987+dbda4426 |
| `nodejs-packaging-bundler` | AlmaLinux:8 | All versions | 2021.06-4.module_el8.10.0+3958+472a6467 |
| `npm` | AlmaLinux:8 | All versions | 1:10.8.2-1.20.19.1.1.module_el8.10.0+3987+dbda4426 |
| `nodejs` | AlmaLinux:9 | All versions | 1:20.19.1-1.module_el9.6.0+163+d268fe53 |
| `nodejs-devel` | AlmaLinux:9 | All versions | 1:20.19.1-1.module_el9.6.0+163+d268fe53 |
| `nodejs-docs` | AlmaLinux:9 | All versions | 1:20.19.1-1.module_el9.6.0+163+d268fe53 |
| `nodejs-full-i18n` | AlmaLinux:9 | All versions | 1:20.19.1-1.module_el9.6.0+163+d268fe53 |
| `nodejs-nodemon` | AlmaLinux:9 | All versions | 3.0.1-1.module_el9.5.0+125+8dc38870 |
| `nodejs-packaging` | AlmaLinux:9 | All versions | 2021.06-4.module_el9.6.0+162+8dc602e5 |
| `nodejs-packaging-bundler` | AlmaLinux:9 | All versions | 2021.06-4.module_el9.6.0+162+8dc602e5 |
| `npm` | AlmaLinux:9 | All versions | 1:10.8.2-1.20.19.1.1.module_el9.6.0+163+d268fe53 |
| `nodejs` | Red Hat:enterprise_linux:10.0 | All versions | 1:22.15.0-1.el10_0 |
| `nodejs-debuginfo` | Red Hat:enterprise_linux:10.0 | All versions | 1:22.15.0-1.el10_0 |
| `nodejs-devel` | Red Hat:enterprise_linux:10.0 | All versions | 1:22.15.0-1.el10_0 |
| `nodejs-docs` | Red Hat:enterprise_linux:10.0 | All versions | 1:22.15.0-1.el10_0 |
| `nodejs-full-i18n` | Red Hat:enterprise_linux:10.0 | All versions | 1:22.15.0-1.el10_0 |
| `nodejs-libs` | Red Hat:enterprise_linux:10.0 | All versions | 1:22.15.0-1.el10_0 |
| `nodejs-libs-debuginfo` | Red Hat:enterprise_linux:10.0 | All versions | 1:22.15.0-1.el10_0 |
| `nodejs-npm` | Red Hat:enterprise_linux:10.0 | All versions | 1:10.9.2-1.22.15.0.1.el10_0 |
| `nodejs22` | Red Hat:enterprise_linux:10.0 | All versions | 1:22.15.0-1.el10_0 |
| `nodejs22-debuginfo` | Red Hat:enterprise_linux:10.0 | All versions | 1:22.15.0-1.el10_0 |
| `nodejs22-debugsource` | Red Hat:enterprise_linux:10.0 | All versions | 1:22.15.0-1.el10_0 |
| `nodejs` | Red Hat:enterprise_linux:8::appstream | All versions | 1:20.19.1-1.module+el8.10.0+23054+5431297f |
| `nodejs-debuginfo` | Red Hat:enterprise_linux:8::appstream | All versions | 1:20.19.1-1.module+el8.10.0+23054+5431297f |
| `nodejs-debugsource` | Red Hat:enterprise_linux:8::appstream | All versions | 1:20.19.1-1.module+el8.10.0+23054+5431297f |
| `nodejs-devel` | Red Hat:enterprise_linux:8::appstream | All versions | 1:20.19.1-1.module+el8.10.0+23054+5431297f |
| `nodejs-docs` | Red Hat:enterprise_linux:8::appstream | All versions | 1:20.19.1-1.module+el8.10.0+23054+5431297f |
| `nodejs-full-i18n` | Red Hat:enterprise_linux:8::appstream | All versions | 1:20.19.1-1.module+el8.10.0+23054+5431297f |
| `nodejs-nodemon` | Red Hat:enterprise_linux:8::appstream | All versions | 0:3.0.1-1.module+el8.10.0+22904+d0fedeff |

## How do I fix CVE-2025-31498?

Upgrade to a fixed version.

## Is CVE-2025-31498 being exploited?

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

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2025-31498 and fix it if it is affected.

What it is: CVE-2025-31498 is a high-severity use after free vulnerability in c-ares, published on 8 Apr 2025. 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-2025-31498 in the wild and no public exploit code.

Affected product: c-ares. No package-level version data is available, so check the vendor advisory linked from the reference page.

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-2025-31498/ (Markdown: https://insights.sbomify.com/CVE-2025-31498/index.md)
```

## Sources

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

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