# GHSA-rm8v-mxj3-5rmq: github.com/lestrrat-go/jwx vulnerable to Potential Padding Oracle Attack

> The library leaks padding length via timing and error messages during AES-CBC decryption, potentially aiding padding oracle attacks.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 14 Jun 2023
- **Also known as:** GO-2023-1859

## What is GHSA-rm8v-mxj3-5rmq?

GHSA-rm8v-mxj3-5rmq is a vulnerability in github.com/lestrrat-go/jwx, published on 14 Jun 2023. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

### Summary

Decrypting AES-CBC encrypted JWE has Potential Padding Oracle Attack Vulnerability.

### Details

On [v2.0.10](https://github.com/lestrrat-go/jwx/releases/tag/v2.0.10), decrypting AES-CBC encrypted JWE may return an error "failed to generate plaintext from decrypted blocks: invalid padding":

https://github.com/lestrrat-go/jwx/blob/8840ffd4afc5839f591ff0e9ba9034af52b1643e/jwe/internal/aescbc/aescbc.go#L210-L213

Reporting padding error causes [Padding Oracle Attack](https://en.wikipedia.org/wiki/Padding_oracle_attack) Vulnerability.
RFC 7516 JSON Web Encryption (JWE) says that we **MUST NOT** do this.

> 11.5.  Timing Attacks
> To mitigate the attacks described in RFC 3218 [RFC3218], the
> recipient MUST NOT distinguish between format, padding, and length
> errors of encrypted keys.  It is strongly recommended, in the event
> of receiving an improperly formatted key, that the recipient
> substitute a randomly generated CEK and proceed to the next step, to
> mitigate timing attacks.

In addition, the time to remove padding depends on the length of the padding.
It may leak the length of the padding by Timing Attacks.

https://github.com/lestrrat-go/jwx/blob/796b2a9101cf7e7cb66455e4d97f3c158ee10904/jwe/internal/aescbc/aescbc.go#L33-L66

To mitigate Timing Attacks, it MUST be done in constant time.

### Impact

The authentication tag is verified, so it is not an immediate attack.

## Which versions are affected by GHSA-rm8v-mxj3-5rmq?

6 open source packages ship an affected version, including github.com/lestrrat-go/jwx and github.com/lestrrat-go/jwx/v2.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `github.com/lestrrat-go/jwx` | Go | All versions | 1.2.26 |
| `github.com/lestrrat-go/jwx` | Go | All versions | 1.2.26 |
| `github.com/lestrrat-go/jwx` | Go | All versions | 1.2.26 |
| `github.com/lestrrat-go/jwx/v2` | Go | All versions | 2.0.11 |
| `github.com/lestrrat-go/jwx/v2` | Go | All versions | 2.0.11 |
| `github.com/lestrrat-go/jwx/v2` | Go | All versions | 2.0.11-0.20230614080639-c8b6bec919a1 |

## How do I fix GHSA-rm8v-mxj3-5rmq?

Upgrade github.com/lestrrat-go/jwx to 1.2.26 or later.

## Is GHSA-rm8v-mxj3-5rmq being exploited?

There is no known exploitation of GHSA-rm8v-mxj3-5rmq in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-rm8v-mxj3-5rmq and fix it if it is affected.

What it is: GHSA-rm8v-mxj3-5rmq is a vulnerability in github.com/lestrrat-go/jwx, published on 14 Jun 2023. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: There is no known exploitation of GHSA-rm8v-mxj3-5rmq in the wild and no public exploit code.

Affected packages and fixed versions:
- github.com/lestrrat-go/jwx (Go): affected all versions; fixed in 1.2.26
- github.com/lestrrat-go/jwx (Go): affected all versions; fixed in 1.2.26
- github.com/lestrrat-go/jwx (Go): affected all versions; fixed in 1.2.26
- github.com/lestrrat-go/jwx/v2 (Go): affected all versions; fixed in 2.0.11
- github.com/lestrrat-go/jwx/v2 (Go): affected all versions; fixed in 2.0.11
- github.com/lestrrat-go/jwx/v2 (Go): affected all versions; fixed in 2.0.11-0.20230614080639-c8b6bec919a1

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-rm8v-mxj3-5rmq/ (Markdown: https://insights.sbomify.com/GHSA-rm8v-mxj3-5rmq/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-rm8v-mxj3-5rmq

---
From sbomify Insights: https://insights.sbomify.com/GHSA-rm8v-mxj3-5rmq/
Summaries are generated and may contain mistakes; the official description above is the record.
