# CVE-2022-3971: matrix-appservice-irc PgDataStore.ts sql injection

> Attackers can execute arbitrary SQL commands via the roomIds argument in the Matrix IRC bridge, potentially reading or modifying database contents.

- **Severity:** Medium 4.6 (`CVSS:3.1/AV:A/AC:H/PR:L/UI:N/S:U/C:L/I:L/A:L`)
- **Exploited in the wild:** Not known
- **Login needed:** Any signed-in user
- **Attackable:** Local or same network only
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 13 Nov 2022
- **Updated:** 15 Apr 2025
- **Also known as:** GHSA-ffwf-47x2-jpr8

## What is CVE-2022-3971?

CVE-2022-3971 is a medium-severity SQL injection vulnerability in unspecified matrix-appservice-irc, published on 13 Nov 2022. It can only be exploited from the same machine or local network, with no action from the victim.

### Official description

A vulnerability was found in matrix-appservice-irc up to 0.35.1. It has been declared as critical. This vulnerability affects unknown code of the file src/datastore/postgres/PgDataStore.ts. The manipulation of the argument roomIds leads to sql injection. Upgrading to version 0.36.0 is able to address this issue. The name of the patch is 179313a37f06b298150edba3e2b0e5a73c1415e7. It is recommended to upgrade the affected component. VDB-213550 is the identifier assigned to this vulnerability.

Weakness: CWE-707 (Improper Neutralization)

## Which versions are affected by CVE-2022-3971?

2 open source packages ship an affected version, including matrix-appservice-irc. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `matrix-appservice-irc` | npm | All versions | 0.36.0 |
| `matrix-appservice-irc` | npm | All versions | 0.36.0 |

Products: Matrix Matrix Irc Bridge.

## How do I fix CVE-2022-3971?

Upgrade matrix-appservice-irc to 0.36.0 or later.

## Is CVE-2022-3971 being exploited?

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

## Other vulnerabilities in unspecified matrix-appservice-irc

- [CVE-2022-39203](https://insights.sbomify.com/CVE-2022-39203/): Parsing issue in matrix-org/node-irc leading to room takeovers (high 8.8)
- [CVE-2022-29166](https://insights.sbomify.com/CVE-2022-29166/): Improper handling of multiline messages in matrix-appservice-irc (high 8.0)
- [CVE-2023-38690](https://insights.sbomify.com/CVE-2023-38690/): matrix-appservice-irc IRC command injection via admin commands containing newlines (medium 5.8)
- [CVE-2022-39202](https://insights.sbomify.com/CVE-2022-39202/): IRC mode parameter confusion in matrix-appservice-irc (medium 4.3)
- [CVE-2023-38700](https://insights.sbomify.com/CVE-2023-38700/): matrix-appservice-irc events can be crafted to leak parts of targeted messages from other bridged rooms (low 3.5)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2022-3971 and fix it if it is affected.

What it is: CVE-2022-3971 is a medium-severity SQL injection vulnerability in unspecified matrix-appservice-irc, published on 13 Nov 2022. It can only be exploited from the same machine or local network, with no action from the victim.
Exploitation: There is no known exploitation of CVE-2022-3971 in the wild and no public exploit code.

Affected packages and fixed versions:
- matrix-appservice-irc (npm): affected all versions; fixed in 0.36.0
- matrix-appservice-irc (npm): affected all versions; fixed in 0.36.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-2022-3971/ (Markdown: https://insights.sbomify.com/CVE-2022-3971/index.md)
```

## Sources

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

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