# CVE-2022-31781: Regular Expression Denial of Service (ReDoS) in ContentType.java. (GHSL-2022-022)

> Attackers can cause denial of service via catastrophic backtracking in ContentType parsing if external input reaches the constructor.

- **Severity:** High 7.5 (`CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 13 Jul 2022
- **Updated:** 3 Aug 2024
- **Also known as:** GHSA-227g-7cvv-6ff3

## What is CVE-2022-31781?

CVE-2022-31781 is a high-severity denial of service vulnerability in Apache Tapestry, published on 13 Jul 2022. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

Apache Tapestry up to version 5.8.1 is vulnerable to Regular Expression Denial of Service (ReDoS) in the way it handles Content Types. Specially crafted Content Types may cause catastrophic backtracking, taking exponential time to complete. Specifically, this is about the regular expression used on the parameter of the org.apache.tapestry5.http.ContentType class. Apache Tapestry 5.8.2 has a fix for this vulnerability. Notice the vulnerability cannot be triggered by web requests in Tapestry code alone. It would only happen if there's some non-Tapestry codepath passing some outside input to the ContentType class constructor.

Weakness: CWE-1333 (Inefficient Regular Expression Complexity)

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

2 open source packages ship an affected version, including org.apache.tapestry:tapestry-core. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `org.apache.tapestry:tapestry-core` | Maven | All versions | 5.8.2 |
| `org.apache.tapestry:tapestry-core` | Maven | All versions | 5.8.2 |

Products: Apache Tapestry.

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

Upgrade org.apache.tapestry:tapestry-core to 5.8.2 or later.

## Is CVE-2022-31781 being exploited?

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

## Other vulnerabilities in Apache Tapestry

- [CVE-2022-46366](https://insights.sbomify.com/CVE-2022-46366/): Apache Tapestry prior to version 4 (EOL) allows RCE though deserialization of untrusted input (critical 9.8)
- [CVE-2021-27850](https://insights.sbomify.com/CVE-2021-27850/): Bypass of the fix for CVE-2019-0195 (critical 9.8)
- [CVE-2020-17531](https://insights.sbomify.com/CVE-2020-17531/): Deserialization flaw in EOL Tapestry 4. (critical 9.8)
- [CVE-2019-0195](https://insights.sbomify.com/CVE-2019-0195/): Deserialization of Untrusted Data in Apache Tapestry (critical 9.8)
- [CVE-2019-10071](https://insights.sbomify.com/CVE-2019-10071/): Timing attack on HMAC signature comparison in Apache Tapestry (critical 9.8)

## Fix prompt for AI coding agents

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

What it is: CVE-2022-31781 is a high-severity denial of service vulnerability in Apache Tapestry, published on 13 Jul 2022. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: There is no known exploitation of CVE-2022-31781 in the wild and no public exploit code.

Affected packages and fixed versions:
- org.apache.tapestry:tapestry-core (Maven): affected all versions; fixed in 5.8.2
- org.apache.tapestry:tapestry-core (Maven): affected all versions; fixed in 5.8.2

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-31781/ (Markdown: https://insights.sbomify.com/CVE-2022-31781/index.md)
```

## Sources

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

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