# GHSA-c4cm-r9fh-jgj9: commonground-api-common unexploitable privilege escalation in JWT authentication middleware


- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Fix available:** No
- **Published:** 9 Feb 2024

## What is GHSA-c4cm-r9fh-jgj9?

GHSA-c4cm-r9fh-jgj9 is a vulnerability in commonground-api-common, published on 9 Feb 2024. 

### Official description

### Impact

This is a privilege escalation vulnerability. The impact is negligible and entirely theoretical.

A non-exploitable weakness was found in how the client-supplied JWTs are verified. Because an explicit allow-list
of known algorithms is used in the PyJWT library, user-supplied (invalid) algorithms are rejected.

If this was not the case, then the client JWTs could be tampered with, resulting in privilege escalation which
would allow the attacker to perform any operation as any client (impersonation) without leaving a trace of
the real user/client.

### Patches

Will be fixed in 1.12.2

### Workarounds

None needed. But be careful when updating PyJWT. Check that the used PyJWT has no algorithms specified with a name in "", "HS25", "HS2", "HS", "H", or that those algorithms are acceptable.

### Details

The header and payload of JSON Web Tokens (JWTs) are cryptographically signed with an algorithm. A JWT has a header field `alg` that specifies the algorithm used in the signature.

The `vng-api-common.middleware.AuthMiddleware` uses PyJWT to check the validity of JWT and indicates it should be "HS256", otherwise an attacker could construct a token with a cryptographically weak token. It should indicate this with a list of acceptable algorithms  `["HS256"]`, but instead the string `"HS256"` is passed to PyJWT.  PyJWT does not check the type of the argument and checks if the `alg` string in the header exists in the acceptable algorithms value with the `in` operator. Any substring of `"HS256"` passes this `in` check. It is not exploitable because there is no such substring in de set of algorithms PyJWT supports.

## Which versions are affected by GHSA-c4cm-r9fh-jgj9?

6 open source packages ship an affected version, including commonground-api-common, vng-api-common and vng-api-common-utrecht.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `commonground-api-common` | PyPI | All versions to 1.12.1 | None |
| `commonground-api-common` | PyPI | All versions to 1.12.1 | None |
| `vng-api-common` | PyPI | All versions to 2.0.5 | None |
| `vng-api-common` | PyPI | All versions to 2.0.5 | None |
| `vng-api-common-utrecht` | PyPI | All versions to 1.3.2 | None |
| `vng-api-common-utrecht` | PyPI | All versions to 1.3.2 | None |

## How do I fix GHSA-c4cm-r9fh-jgj9?

No fix has been published for GHSA-c4cm-r9fh-jgj9 yet. Limit exposure of the affected software until one is available.

## Is GHSA-c4cm-r9fh-jgj9 being exploited?

There is no known exploitation of GHSA-c4cm-r9fh-jgj9 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-c4cm-r9fh-jgj9 and fix it if it is affected.

What it is: GHSA-c4cm-r9fh-jgj9 is a vulnerability in commonground-api-common, published on 9 Feb 2024. 
Exploitation: There is no known exploitation of GHSA-c4cm-r9fh-jgj9 in the wild and no public exploit code.

Affected packages and fixed versions:
- commonground-api-common (PyPI): affected all versions up to 1.12.1; no fix listed
- commonground-api-common (PyPI): affected all versions up to 1.12.1; no fix listed
- vng-api-common (PyPI): affected all versions up to 2.0.5; no fix listed
- vng-api-common (PyPI): affected all versions up to 2.0.5; no fix listed
- vng-api-common-utrecht (PyPI): affected all versions up to 1.3.2; no fix listed
- vng-api-common-utrecht (PyPI): affected all versions up to 1.3.2; no fix listed

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/GHSA-c4cm-r9fh-jgj9/ (Markdown: https://insights.sbomify.com/GHSA-c4cm-r9fh-jgj9/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-c4cm-r9fh-jgj9

---
From sbomify Insights: https://insights.sbomify.com/GHSA-c4cm-r9fh-jgj9/
Summaries are generated and may contain mistakes; the official description above is the record.
