# CVE-2009-2940: PyGreSQL Might Be Vulnerable to Encoding-Based SQL Injection

> Remote attackers can exploit improper string escaping in the pygresql module to perform SQL injection attacks, potentially reading or modifying database contents.

- **Severity:** High 7.5 (`AV:N/AC:L/Au:N/C:P/I:P/A:P`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 22 Oct 2009
- **Updated:** 7 Aug 2024
- **Also known as:** DEBIAN-CVE-2009-2940, DSA-1911-1, GHSA-xv6x-43gq-4hfj, PYSEC-2009-18

## What is CVE-2009-2940?

CVE-2009-2940 is a high-severity SQL injection vulnerability in n/a, published on 22 Oct 2009. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

The pygresql module 3.8.1 and 4.0 for Python does not properly support the PQescapeStringConn function, which might allow remote attackers to leverage escaping issues involving multibyte character encodings.

## Which versions are affected by CVE-2009-2940?

5 open source packages ship an affected version, including pygresql and PyGreSQL. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `pygresql` | PyPI | All versions to 3.8.1 | None |
| `pygresql` | PyPI | From 3.8.1 to 4.0 | None |
| `pygresql` | PyPI | From 4.0 | 4.1 |
| `PyGreSQL` | PyPI | All versions to 3.8.1 | None |
| `PyGreSQL` | PyPI | From 4.0 | 4.1 |

Products: Pygresql Pygresql.

## How do I fix CVE-2009-2940?

Upgrade pygresql to 4.1 or later.

## Is CVE-2009-2940 being exploited?

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

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2009-2940 and fix it if it is affected.

What it is: CVE-2009-2940 is a high-severity SQL injection vulnerability in n/a, published on 22 Oct 2009. 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-2009-2940 in the wild and no public exploit code.

Affected packages and fixed versions:
- pygresql (PyPI): affected all versions up to 3.8.1; no fix listed
- pygresql (PyPI): affected from 3.8.1 up to 4.0; no fix listed
- pygresql (PyPI): affected from 4.0; fixed in 4.1
- PyGreSQL (PyPI): affected all versions up to 3.8.1; no fix listed
- PyGreSQL (PyPI): affected from 4.0; fixed in 4.1

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

## Sources

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

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