# GHSA-mvrp-3cvx-c325: Zod denial of service vulnerability during email validation

> Attackers can cause denial of service in API servers using Zod email validation via inefficient regex complexity.

- **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:** 4 Oct 2023

## What is GHSA-mvrp-3cvx-c325?

GHSA-mvrp-3cvx-c325 is a denial of service vulnerability in express-zod-api, published on 4 Oct 2023. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

### Impact

API servers running `express-zod-api` having:

- version of `express-zod-api` below `10.0.0-beta1`,
- and using the following (or similar) validation schema in its implementation: `z.string().email()`,

are vulnerable to a DoS attack due to: 

- Inefficient Regular Expression Complexity in `zod` versions up to `3.22.2`,
- depending on `zod`.

### Patches

The patched version of `zod` fixing the vulnerability is `3.22.3`.

However, it's highly recommended to upgrade `express-zod-api` to at least version `10.0.0`, which does not depend on `zod` strictly and directly, but requires its installation as a peer dependency instead, enabling you to install the patched `zod` version yourself.

### Workarounds

When it's not possible to upgrade your dependencies, consider the following replacement in your implementation:

```diff
- z.string().email()
+ z.string().regex(
+   /^(?!\.)(?!.*\.\.)([A-Z0-9_+-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i
+ )
```

This regular expression is taken from the suggested patch of `zod`.

### References

- Original issue: https://github.com/colinhacks/zod/issues/2609
- The patch: https://github.com/colinhacks/zod/pull/2824
- Entry in database: https://nvd.nist.gov/vuln/detail/CVE-2023-4316
- Enumeration: https://cwe.mitre.org/data/definitions/1333.html
- Parent advisory: https://github.com/advisories/GHSA-m95q-7qp3-xv42
- Changelog entry for `express-zod-api` version `10.0.0-beta1`: https://github.com/RobinTail/express-zod-api/blob/master/CHANGELOG.md#v1000-beta1

## Which versions are affected by GHSA-mvrp-3cvx-c325?

2 open source packages ship an affected version, including express-zod-api.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `express-zod-api` | npm | All versions | 10.0.0-beta1 |
| `express-zod-api` | npm | All versions | 10.0.0-beta1 |

## How do I fix GHSA-mvrp-3cvx-c325?

Upgrade express-zod-api to 10.0.0-beta1 or later.

## Is GHSA-mvrp-3cvx-c325 being exploited?

There is no known exploitation of GHSA-mvrp-3cvx-c325 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-mvrp-3cvx-c325 and fix it if it is affected.

What it is: GHSA-mvrp-3cvx-c325 is a denial of service vulnerability in express-zod-api, published on 4 Oct 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-mvrp-3cvx-c325 in the wild and no public exploit code.

Affected packages and fixed versions:
- express-zod-api (npm): affected all versions; fixed in 10.0.0-beta1
- express-zod-api (npm): affected all versions; fixed in 10.0.0-beta1

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-mvrp-3cvx-c325/ (Markdown: https://insights.sbomify.com/GHSA-mvrp-3cvx-c325/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-mvrp-3cvx-c325

---
From sbomify Insights: https://insights.sbomify.com/GHSA-mvrp-3cvx-c325/
Summaries are generated and may contain mistakes; the official description above is the record.
