# CVE-2026-27959: Koa has Host Header Injection via `ctx.hostname`

> Koa's hostname parsing flaw allows Host header injection, enabling attackers to manipulate generated URLs for password resets or routing.

- **Severity:** High 7.5 (`CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:N`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 26 Feb 2026
- **Updated:** 15 Jul 2026
- **Also known as:** CLSA-2026-1788264598, GHSA-7gcc-r8m5-44qm, ROOT-APP-NPM-CVE-2026-27959

## What is CVE-2026-27959?

CVE-2026-27959 is a high-severity vulnerability in koajs koa, published on 26 Feb 2026. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

Koa is middleware for Node.js using ES2017 async functions. Prior to versions 3.1.2 and 2.16.4, Koa's `ctx.hostname` API performs naive parsing of the HTTP Host header, extracting everything before the first colon without validating the input conforms to RFC 3986 hostname syntax. When a malformed Host header containing a `@` symbol is received, `ctx.hostname` returns `evil[.]com` - an attacker-controlled value. Applications using `ctx.hostname` for URL generation, password reset links, email verification URLs, or routing decisions are vulnerable to Host header injection attacks. Versions 3.1.2 and 2.16.4 fix the issue.

Weakness: CWE-20 (Improper Input Validation)

## Which versions are affected by CVE-2026-27959?

4 open source packages ship an affected version, including koa. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `koa` | npm | All versions | 2.16.4 |
| `koa` | npm | All versions | 2.16.4 |
| `koa` | npm | From 3.0.0 | 3.1.2 |
| `koa` | npm | From 3.0.0 | 3.1.2 |

Products: Koajs Koa.

## How do I fix CVE-2026-27959?

Upgrade koa to a fixed version for your release line: 2.16.4 or 3.1.2.

## Is CVE-2026-27959 being exploited?

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

Public exploit code:

- https://github.com/mlouazir/CVE-2026-27959-mini-lab (github_poc): https://github.com/mlouazir/CVE-2026-27959-mini-lab

## Other vulnerabilities in koajs koa

- [CVE-2025-25200](https://insights.sbomify.com/CVE-2025-25200/): Koa has Inefficient Regular Expression Complexity (critical 9.2)
- [CVE-2025-8129](https://insights.sbomify.com/CVE-2025-8129/): KoaJS Koa HTTP Header response.js back redirect (medium 5.1)
- [CVE-2025-32379](https://insights.sbomify.com/CVE-2025-32379/): XSS at ctx.redirect() function in Koajs (medium 5.0)
- [CVE-2025-62595](https://insights.sbomify.com/CVE-2025-62595/): Koa Vulnerable to Open Redirect via Trailing Double-Slash (//) in back Redirect Logic (medium 4.3)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2026-27959 and fix it if it is affected.

What it is: CVE-2026-27959 is a high-severity vulnerability in koajs koa, published on 26 Feb 2026. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: It is not confirmed as exploited in the wild, but public exploit code for CVE-2026-27959 exists.

Affected packages and fixed versions:
- koa (npm): affected all versions; fixed in 2.16.4
- koa (npm): affected all versions; fixed in 2.16.4
- koa (npm): affected from 3.0.0; fixed in 3.1.2
- koa (npm): affected from 3.0.0; fixed in 3.1.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-2026-27959/ (Markdown: https://insights.sbomify.com/CVE-2026-27959/index.md)
```

## Sources

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

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