# CVE-2023-38691: matrix-appservice-bridge doesn't verify the sub parameter of an openId token exhange, allowing unauthorized access to provisioning APIs

> A malicious Matrix server can impersonate users via OpenID token exchange flaws, allowing unauthorized access to provisioning APIs in the matrix-appservice-bridge library.

- **Severity:** Medium 5.0 (`CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:L/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:** 4 Aug 2023
- **Updated:** 7 Oct 2024
- **Also known as:** GHSA-vc7j-h8xg-fv5x

## What is CVE-2023-38691?

CVE-2023-38691 is a medium-severity authentication bypass vulnerability in matrix-org matrix-appservice-bridge, published on 4 Aug 2023. Any signed-in user can exploit it over the network, with no action from the victim.

### Official description

matrix-appservice-bridge provides an API for setting up bridges. Starting in version 4.0.0 and prior to versions 8.1.2 and 9.0.1, a malicious Matrix server can use a foreign user's MXID in an OpenID exchange, allowing a bad actor to impersonate users when using the provisioning API. The library does not check that the servername part of the `sub` parameter (containing the user's *claimed* MXID) is the the same as the servername we are talking to. A malicious actor could spin up a server on any given domain, respond with a `sub` parameter according to the user they want to act as and use the resulting token to perform provisioning requests. Versions 8.1.2 and 9.0.1 contain a patch. As a workaround, disable the provisioning API.

Weakness: CWE-287 (Improper Authentication)

## Which versions are affected by CVE-2023-38691?

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


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `matrix-appservice-bridge` | npm | From 4.0.0 | 8.1.2 |
| `matrix-appservice-bridge` | npm | From 4.0.0 | 8.1.2 |
| `matrix-appservice-bridge` | npm | From 9.0.0 | 9.0.1 |
| `matrix-appservice-bridge` | npm | From 9.0.0 | 9.0.1 |

Products: Matrix Matrix-Appservice-Bridge.

## How do I fix CVE-2023-38691?

Upgrade matrix-appservice-bridge to a fixed version for your release line: 8.1.2 or 9.0.1.

## Is CVE-2023-38691 being exploited?

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

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

- [CVE-2021-32659](https://insights.sbomify.com/CVE-2021-32659/): Automatic room upgrade handling can be used maliciously to bridge a room non-consentually (medium 6.5)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2023-38691 and fix it if it is affected.

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

Affected packages and fixed versions:
- matrix-appservice-bridge (npm): affected from 4.0.0; fixed in 8.1.2
- matrix-appservice-bridge (npm): affected from 4.0.0; fixed in 8.1.2
- matrix-appservice-bridge (npm): affected from 9.0.0; fixed in 9.0.1
- matrix-appservice-bridge (npm): affected from 9.0.0; fixed in 9.0.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-2023-38691/ (Markdown: https://insights.sbomify.com/CVE-2023-38691/index.md)
```

## Sources

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

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