# GHSA-vhxv-fg4m-p2w8: Some CORS middleware allow untrusted origins

> CORS middleware incorrectly allows untrusted origins when multiple patterns share a suffix, enabling cross-origin attacks.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** A user has to click or open something
- **Fix available:** Yes
- **Published:** 3 May 2024
- **Also known as:** GO-2024-2813

## What is GHSA-vhxv-fg4m-p2w8?

GHSA-vhxv-fg4m-p2w8 is a vulnerability in github.com/jub0bs/cors, published on 3 May 2024. An attacker can exploit it over the internet without logging in, and only if a user opens a file or follows a link.

### Official description

### Impact

Some CORS middleware (more specifically those created by specifying two or more origin patterns whose hosts share a proper suffix) incorrectly allow some untrusted origins, thereby opening the door to cross-origin attacks from the untrusted origins in question.

For example, specifying origin patterns `https://foo.com` and `https://bar.com` (in that order) would yield a middleware that would incorrectly allow untrusted origin `https://barfoo.com`.

### Patches

Patched in v0.1.3.

### Workarounds

None.

## Which versions are affected by GHSA-vhxv-fg4m-p2w8?

3 open source packages ship an affected version, including github.com/jub0bs/cors.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `github.com/jub0bs/cors` | Go | All versions | 0.1.3 |
| `github.com/jub0bs/cors` | Go | All versions | 0.1.3 |
| `github.com/jub0bs/cors` | Go | All versions | 0.1.3 |

## How do I fix GHSA-vhxv-fg4m-p2w8?

Upgrade github.com/jub0bs/cors to 0.1.3 or later.

## Is GHSA-vhxv-fg4m-p2w8 being exploited?

There is no known exploitation of GHSA-vhxv-fg4m-p2w8 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-vhxv-fg4m-p2w8 and fix it if it is affected.

What it is: GHSA-vhxv-fg4m-p2w8 is a vulnerability in github.com/jub0bs/cors, published on 3 May 2024. An attacker can exploit it over the internet without logging in, and only if a user opens a file or follows a link.
Exploitation: There is no known exploitation of GHSA-vhxv-fg4m-p2w8 in the wild and no public exploit code.

Affected packages and fixed versions:
- github.com/jub0bs/cors (Go): affected all versions; fixed in 0.1.3
- github.com/jub0bs/cors (Go): affected all versions; fixed in 0.1.3
- github.com/jub0bs/cors (Go): affected all versions; fixed in 0.1.3

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-vhxv-fg4m-p2w8/ (Markdown: https://insights.sbomify.com/GHSA-vhxv-fg4m-p2w8/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-vhxv-fg4m-p2w8

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