# CVE-2024-7348: PostgreSQL relation replacement during pg_dump executes arbitrary SQL

> A race condition in pg_dump allows attackers to execute arbitrary SQL as the dumping user, potentially escalating privileges to superuser.

- **Severity:** High 8.8 (`CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H`)
- **Exploited in the wild:** Not known
- **Login needed:** Any signed-in user
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 8 Aug 2024
- **Updated:** 22 Aug 2024
- **Also known as:** ALPINE-CVE-2024-7348, ALSA-2024:5999, ALSA-2024:6000, ALSA-2024:6018, AZL-47636, AZL-47690, BELL-CVE-2024-7348, BIT-postgresql-2024-7348, CLEANSTART-2026-PN72397, CLSA-2024-1727453123, CLSA-2024-1728056209, CLSA-2025-1737993791, DEBIAN-CVE-2024-7348, DSA-5745-1, DSA-5746-1, ECHO-e561-1daf-c313, GHSA-3c6g-7v4g-5xcm, JLSEC-2026-52, MGASA-2024-0301, MINI-8hc6-xmh7-p5wg, OESA-2024-1977, OESA-2024-2054, OESA-2024-2055, OESA-2024-2056, RHSA-2024:5999, RHSA-2024:6000, RHSA-2024:6018, RHSA-2024:6137, RHSA-2024:6138, RHSA-2024:6139, RHSA-2024:6140, RHSA-2024:6141, RHSA-2024:6144, RHSA-2024:6145, RHSA-2024:6557, RHSA-2024:6558, RHSA-2024:6559, RHSA-2024:8495, RLSA-2024:5999, RLSA-2024:6000, RLSA-2024:6018, SUSE-SU-2024:3153-1, SUSE-SU-2024:3154-1, SUSE-SU-2024:3158-1, SUSE-SU-2024:3158-2, SUSE-SU-2024:3158-3, SUSE-SU-2024:3160-1, SUSE-SU-2024:3168-1, SUSE-SU-2024:3169-1, SUSE-SU-2024:3170-1, SUSE-SU-2024:3171-1, SUSE-SU-2024:3181-1, SUSE-SU-2024:3191-1, SUSE-SU-2024:3192-1, SUSE-SU-2024:3224-1, UBUNTU-CVE-2024-7348, USN-6968-1, USN-6968-2, USN-6968-3, openSUSE-SU-2024:14348-1, openSUSE-SU-2024:14349-1, openSUSE-SU-2024:14350-1, openSUSE-SU-2024:14351-1, openSUSE-SU-2024:14361-1

## What is CVE-2024-7348?

CVE-2024-7348 is a high-severity vulnerability in Postgresql Postgresql, published on 8 Aug 2024. Any signed-in user can exploit it over the network, with no action from the victim.

### Official description

Time-of-check Time-of-use (TOCTOU) race condition in pg_dump in PostgreSQL allows an object creator to execute arbitrary SQL functions as the user running pg_dump, which is often a superuser. The attack involves replacing another relation type with a view or foreign table. The attack requires waiting for pg_dump to start, but winning the race condition is trivial if the attacker retains an open transaction. Versions before PostgreSQL 16.4, 15.8, 14.13, 13.16, and 12.20 are affected.

Weakness: CWE-367 (Time-of-check Time-of-use (TOCTOU) Race Condition)

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

1 open source package ship an affected version, including postgresql. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `postgresql` | Bitnami | All versions | 12.20.0, 13.16.0, 14.13.0, 15.8.0, 16.4.0 |
| `pg_repack` | AlmaLinux:8 | All versions | 1.4.6-3.module_el8.6.0+2760+1746ec94 |
| `pg_repack` | AlmaLinux:8 | All versions | 1.4.6-3.module_el8.6.0+3095+ee60d910 |
| `pg_repack` | AlmaLinux:8 | All versions | 1.4.6-3.module_el8.9.0+3704+f1f917ce |
| `pgaudit` | AlmaLinux:8 | All versions | 1.4.0-7.module_el8.9.0+3740+0e74851f.alma.1 |
| `pgaudit` | AlmaLinux:8 | All versions | 1.5.0-1.module_el8.6.0+2760+1746ec94 |
| `pgaudit` | AlmaLinux:8 | All versions | 1.5.0-1.module_el8.6.0+3095+ee60d910 |
| `postgres-decoderbufs` | AlmaLinux:8 | All versions | 0.10.0-2.module_el8.6.0+2760+1746ec94 |
| `postgres-decoderbufs` | AlmaLinux:8 | All versions | 0.10.0-2.module_el8.6.0+3095+ee60d910 |
| `postgres-decoderbufs` | AlmaLinux:8 | All versions | 0.10.0-2.module_el8.9.0+3704+f1f917ce |
| `postgresql` | AlmaLinux:8 | All versions | 12.20-1.module_el8.10.0+3886+1dfe41d7 |
| `postgresql` | AlmaLinux:8 | All versions | 13.16-1.module_el8.10.0+3887+93e5d125 |
| `postgresql-contrib` | AlmaLinux:8 | All versions | 12.20-1.module_el8.10.0+3886+1dfe41d7 |
| `postgresql-contrib` | AlmaLinux:8 | All versions | 13.16-1.module_el8.10.0+3887+93e5d125 |
| `postgresql-docs` | AlmaLinux:8 | All versions | 12.20-1.module_el8.10.0+3886+1dfe41d7 |
| `postgresql-docs` | AlmaLinux:8 | All versions | 13.16-1.module_el8.10.0+3887+93e5d125 |
| `postgresql-plperl` | AlmaLinux:8 | All versions | 12.20-1.module_el8.10.0+3886+1dfe41d7 |
| `postgresql-plperl` | AlmaLinux:8 | All versions | 13.16-1.module_el8.10.0+3887+93e5d125 |
| `postgresql-plpython3` | AlmaLinux:8 | All versions | 12.20-1.module_el8.10.0+3886+1dfe41d7 |
| `postgresql-plpython3` | AlmaLinux:8 | All versions | 13.16-1.module_el8.10.0+3887+93e5d125 |
| `postgresql-pltcl` | AlmaLinux:8 | All versions | 12.20-1.module_el8.10.0+3886+1dfe41d7 |
| `postgresql-pltcl` | AlmaLinux:8 | All versions | 13.16-1.module_el8.10.0+3887+93e5d125 |
| `postgresql-server` | AlmaLinux:8 | All versions | 12.20-1.module_el8.10.0+3886+1dfe41d7 |
| `postgresql-server` | AlmaLinux:8 | All versions | 13.16-1.module_el8.10.0+3887+93e5d125 |
| `postgresql-server-devel` | AlmaLinux:8 | All versions | 12.20-1.module_el8.10.0+3886+1dfe41d7 |
| `postgresql-server-devel` | AlmaLinux:8 | All versions | 13.16-1.module_el8.10.0+3887+93e5d125 |
| `postgresql-static` | AlmaLinux:8 | All versions | 12.20-1.module_el8.10.0+3886+1dfe41d7 |
| `postgresql-static` | AlmaLinux:8 | All versions | 13.16-1.module_el8.10.0+3887+93e5d125 |
| `postgresql-test` | AlmaLinux:8 | All versions | 12.20-1.module_el8.10.0+3886+1dfe41d7 |
| `postgresql-test` | AlmaLinux:8 | All versions | 13.16-1.module_el8.10.0+3887+93e5d125 |
| `postgresql-test-rpm-macros` | AlmaLinux:8 | All versions | 12.20-1.module_el8.10.0+3886+1dfe41d7 |
| `postgresql-test-rpm-macros` | AlmaLinux:8 | All versions | 13.16-1.module_el8.10.0+3887+93e5d125 |
| `postgresql-upgrade` | AlmaLinux:8 | All versions | 12.20-1.module_el8.10.0+3886+1dfe41d7 |
| `postgresql-upgrade` | AlmaLinux:8 | All versions | 13.16-1.module_el8.10.0+3887+93e5d125 |
| `postgresql-upgrade-devel` | AlmaLinux:8 | All versions | 12.20-1.module_el8.10.0+3886+1dfe41d7 |
| `postgresql-upgrade-devel` | AlmaLinux:8 | All versions | 13.16-1.module_el8.10.0+3887+93e5d125 |
| `postgresql` | AlmaLinux:9 | All versions | 13.16-1.el9_4 |
| `postgresql-contrib` | AlmaLinux:9 | All versions | 13.16-1.el9_4 |
| `postgresql-docs` | AlmaLinux:9 | All versions | 13.16-1.el9_4 |
| `postgresql-plperl` | AlmaLinux:9 | All versions | 13.16-1.el9_4 |

Products: Postgresql Postgresql.

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

Upgrade postgresql to a fixed version for your release line: 12.20.0, 13.16.0, 14.13.0 or 15.8.0.

## Is CVE-2024-7348 being exploited?

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

## Other vulnerabilities in Postgresql Postgresql

- [CVE-2013-1902](https://insights.sbomify.com/CVE-2013-1902/): Information disclosure in n/a (critical 10.0)
- [CVE-2013-1903](https://insights.sbomify.com/CVE-2013-1903/): Information disclosure in n/a (critical 10.0)
- [CVE-2007-3279](https://insights.sbomify.com/CVE-2007-3279/): Privilege escalation in n/a (critical 10.0)
- [CVE-2002-1399](https://insights.sbomify.com/CVE-2002-1399/): Integer overflow in n/a (critical 10.0)
- [CVE-2016-3065](https://insights.sbomify.com/CVE-2016-3065/): Information disclosure in n/a (critical 9.1)

## Fix prompt for AI coding agents

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

What it is: CVE-2024-7348 is a high-severity vulnerability in Postgresql Postgresql, published on 8 Aug 2024. Any signed-in user can exploit it over the network, with no action from the victim.
Exploitation: There is no known exploitation of CVE-2024-7348 in the wild and no public exploit code.

Affected packages and fixed versions:
- postgresql (Bitnami): affected all versions; fixed in 12.20.0, 13.16.0, 14.13.0, 15.8.0, 16.4.0

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

## Sources

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

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