# CVE-2025-46721: nosurf vulnerable to CSRF due to non-functional same-origin request checks

> An attacker with control over site content or subdomains can bypass CSRF protections in the nosurf Go library to perform actions on behalf of users.

- **Severity:** Medium 6.0 (`CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:P/VC:N/VI:H/VA:N/SC:N/SI:N/SA:N`)
- **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:** 13 May 2025
- **Updated:** 13 May 2025
- **Also known as:** GHSA-w9hf-35q4-vcjw, GO-2025-3683

## What is CVE-2025-46721?

CVE-2025-46721 is a medium-severity vulnerability in justinas nosurf, published on 13 May 2025. 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

nosurf is cross-site request forgery (CSRF) protection middleware for Go. A vulnerability in versions prior to 1.2.0 allows an attacker who controls content on the target site, or on a subdomain of the target site (either via XSS, or otherwise) to bypass CSRF checks and issue requests on user's behalf. Due to misuse of the Go `net/http` library, nosurf categorizes all incoming requests as plain-text HTTP requests, in which case the `Referer` header is not checked to have the same origin as the target webpage. If the attacker has control over HTML contents on either the target website (e.g. `example.com`), or on a website hosted on a subdomain of the target (e.g. `attacker.example.com`), they will also be able to manipulate cookies set for the target website. By acquiring the secret CSRF token from the cookie, or overriding the cookie with a new token known to the attacker, `attacker.example.com` is able to craft cross-site requests to `example.com`. A patch for the issue was released in nosurf 1.2.0. In lieu of upgrading to a patched version of nosurf, users may additionally use another HTTP middleware to ensure that a non-safe HTTP request is coming from the same origin (e.g. by requiring a `Sec-Fetch-Site: same-origin` header in the request).

Weakness: CWE-352 (Cross-Site Request Forgery)

## Which versions are affected by CVE-2025-46721?

3 open source packages ship an affected version, including github.com/justinas/nosurf. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `github.com/justinas/nosurf` | Go | All versions | 1.2.0 |
| `github.com/justinas/nosurf` | Go | All versions | 1.2.0 |
| `github.com/justinas/nosurf` | Go | All versions | 1.2.0 |

Products: Nosurf Project Nosurf.

## How do I fix CVE-2025-46721?

Upgrade github.com/justinas/nosurf to 1.2.0 or later.

## Is CVE-2025-46721 being exploited?

It is not confirmed as exploited in the wild, but public exploit code for CVE-2025-46721 exists.

Public exploit code:

- https://github.com/justinas/nosurf-cve-2025-46721 (github_poc): https://github.com/justinas/nosurf-cve-2025-46721

## Other vulnerabilities in justinas nosurf

- [CVE-2020-36564](https://insights.sbomify.com/CVE-2020-36564/): Improper input validation in github.com/justinas/nosurf (high 7.5)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2025-46721 and fix it if it is affected.

What it is: CVE-2025-46721 is a medium-severity vulnerability in justinas nosurf, published on 13 May 2025. An attacker can exploit it over the internet without logging in, and only if a user opens a file or follows a link.
Exploitation: It is not confirmed as exploited in the wild, but public exploit code for CVE-2025-46721 exists.

Affected packages and fixed versions:
- github.com/justinas/nosurf (Go): affected all versions; fixed in 1.2.0
- github.com/justinas/nosurf (Go): affected all versions; fixed in 1.2.0
- github.com/justinas/nosurf (Go): affected all versions; fixed in 1.2.0

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

## Sources

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

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