# CVE-2021-32659: Automatic room upgrade handling can be used maliciously to bridge a room non-consentually

> A malicious admin can redirect bridged room traffic to an unauthorized room by exploiting missing predecessor validation in Matrix appservice bridges.

- **Severity:** Medium 6.5 (`CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:N`)
- **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:** 16 Jun 2021
- **Updated:** 3 Aug 2024
- **Also known as:** GHSA-35g4-qx3c-vjhx

## What is CVE-2021-32659?

CVE-2021-32659 is a medium-severity vulnerability in matrix-org matrix-appservice-bridge, published on 16 Jun 2021. Any signed-in user can exploit it over the network, with no action from the victim.

### Official description

Matrix-appservice-bridge is the bridging service for the Matrix communication program's application services. In versions 2.6.0 and earlier, if a bridge has room upgrade handling turned on in the configuration (the `roomUpgradeOpts` key when instantiating a new `Bridge` instance.), any `m.room.tombstone` event it encounters will be used to unbridge the current room and bridge into the target room. However, the target room `m.room.create` event is not checked to verify if the `predecessor` field contains the previous room. This means that any malicious admin of a bridged room can repoint the traffic to a different room without the new room being aware. Versions 2.6.1 and greater are patched. As a workaround, disabling the automatic room upgrade handling can be done by removing the `roomUpgradeOpts` key from the `Bridge` class options.

Weakness: CWE-306 (Missing Authentication for Critical Functionality)

## Which versions are affected by CVE-2021-32659?

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


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `matrix-appservice-bridge` | npm | All versions | 2.6.1 |
| `matrix-appservice-bridge` | npm | All versions | 2.6.1 |

Products: Matrix Matrix-Appservice-Bridge.

## How do I fix CVE-2021-32659?

Upgrade matrix-appservice-bridge to 2.6.1 or later.

## Is CVE-2021-32659 being exploited?

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

## Other vulnerabilities in matrix-org matrix-appservice-bridge

- [CVE-2023-38691](https://insights.sbomify.com/CVE-2023-38691/): matrix-appservice-bridge doesn't verify the sub parameter of an openId token exhange, allowing unauthorized access to provisioning APIs (medium 5.0)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2021-32659 and fix it if it is affected.

What it is: CVE-2021-32659 is a medium-severity vulnerability in matrix-org matrix-appservice-bridge, published on 16 Jun 2021. Any signed-in user can exploit it over the network, with no action from the victim.
Exploitation: There is no known exploitation of CVE-2021-32659 in the wild and no public exploit code.

Affected packages and fixed versions:
- matrix-appservice-bridge (npm): affected all versions; fixed in 2.6.1
- matrix-appservice-bridge (npm): affected all versions; fixed in 2.6.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-2021-32659/ (Markdown: https://insights.sbomify.com/CVE-2021-32659/index.md)
```

## Sources

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

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