fix(deps): update dependency koa to v2.16.4 [security]#488
Open
renovate[bot] wants to merge 1 commit intomasterfrom
Open
fix(deps): update dependency koa to v2.16.4 [security]#488renovate[bot] wants to merge 1 commit intomasterfrom
renovate[bot] wants to merge 1 commit intomasterfrom
Conversation
810afb7 to
b26e1b1
Compare
b26e1b1 to
d2c7438
Compare
d2c7438 to
dceb4bb
Compare
dceb4bb to
7c9cf42
Compare
7c9cf42 to
59112c9
Compare
9c4ca0d to
593bbaa
Compare
593bbaa to
97fec10
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR contains the following updates:
2.16.2→2.16.4Koa Vulnerable to Open Redirect via Trailing Double-Slash (//) in back Redirect Logic
CVE-2025-62595 / GHSA-g8mr-fgfg-5qpc
More information
Details
Summary:
A bypass was discovered in the
Koa.jsframework affecting its back redirect functionality. In certain circumstances, an attacker can manipulate the Referer header to force a user’s browser to navigate to an external, potentially malicious website. This occurs because the implementation incorrectly treats some specially crafted URLs as safe relative paths. Exploiting this vulnerability could allow attackers to perform phishing, social engineering, or other redirect-based attacks on users of affected applications.This vulnerability affects the code referenced in GitHub Advisory GHSA-jgmv-j7ww-jx2x (which is tracked as CVE‑2025‑54420).
Details:
The patched code attempts to treat values that
startWith('/')as safe relative paths and only perform origin checks for absolute URLs. However, protocol‑relative URLs (those beginning with //host) also start with '/' and therefore match the startsWith('/') branch. A protocol‑relative referrer such as//evil.comwith trailing double-slash is treated by the implementation as a safe relative path, but browsers interpret Location: //evil.com as a redirect to https://evil.com (or http:// based on context).This discrepancy allows an attacker to supply Referer: //evil.com and trigger an external redirect - bypassing the intended same‑origin protection.
Proof of concept (PoC):
Affected line of code: https://github.com/koajs/koa/blob/master/lib/response.js#L326
The problematic logic looks like:
Request with a protocol‑relative Referer:
curl -i -H "Referer: //haymiz.dev" http://127.0.0.1:3000/test
Vulnerable response will contain:
HTTP/1.1 302 Found
Location: //haymiz.dev
A browser receiving that Location header navigates to https://haymiz.dev (or http:// depending on context), resulting in an open redirect to an attacker‑controlled host:
Recommendation / Patch:
Impact:
An attacker who can cause a victim to visit a specially crafted link (or inject a request with a controlled Referer) can cause the victim to be redirected to an attacker‑controlled domain. This can be used for phishing, social engineering, or to bypass some protection rules that rely on same‑origin navigation.
Severity
CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:N/I:L/A:NReferences
This data is provided by the GitHub Advisory Database (CC-BY 4.0).
Koa has Host Header Injection via ctx.hostname
CVE-2026-27959 / GHSA-7gcc-r8m5-44qm
More information
Details
Summary
Koa's
ctx.hostnameAPI 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 (e.g.,evil.com:fake@legitimate.com) is received,ctx.hostnamereturnsevil.com- an attacker-controlled value. Applications usingctx.hostnamefor URL generation, password reset links, email verification URLs, or routing decisions are vulnerable to Host header injection attacks.Details
The vulnerability exists in Koa's hostname getter in
lib/request.js:The
hostgetter retrieves the raw header value with HTTP/2 and proxy support:The Problem
The parsing logic simply splits on the first
:and returns the first segment. There is no validation that the resulting string is a valid hostname per RFC 3986 Section 3.2.2.RFC 3986 Section 3.2.2 defines the host component as:
The
@character is explicitly NOT permitted in the host component - it is the delimiter separating userinfo from host in the authority component.Attack Vector
When an attacker sends:
Koa parses this as:
ctx.get('Host')"evil.com:fake@legitimate.com:3000"ctx.hostname"evil.com"ctx.host"evil.com:fake@legitimate.com:3000"ctx.origin"http://evil.com:fake@legitimate.com:3000"The
ctx.hostnameAPI returnsevil.combecause the parser splits on the first:without understanding thatevil.com:fake@legitimate.comis a malformed authority component whereevil.com:fakewould be interpreted as userinfo by a proper URI parser.Additional Concern:
ctx.originKoa's
ctx.originproperty concatenates protocol and host without validation:Applications using
ctx.originfor URL generation receive the full malformed Host header value, creating URLs with embedded credentials that browsers may interpret as userinfo.HTTP/2 Consideration
Koa explicitly checks
httpVersionMajor >= 2to read the:authoritypseudo-header:The same vulnerability applies - malformed
:authorityvalues containing userinfo would be accepted and parsed identically.PoC
Setup
Exploit
curl -H "Host: evil.com:fake@localhost:3000" http://localhost:3000/forgot-passwordResult
{ "message": "Password reset link generated", "resetUrl": "http://evil.com/reset?token=abc123securtoken", "debug": { "rawHost": "evil.com:fake@localhost:3000", "parsedHostname": "evil.com", "origin": "http://evil.com:fake@localhost:3000", "protocol": "http" } }The password reset URL points to
evil.cominstead of the legitimate server. In a real attack:ctx.hostname→https://evil.com/reset?token=SECRETAdditional Test Cases
Deployment Consideration
For this attack to succeed in production, the malicious Host header must reach the Koa application. This occurs when:
app.proxy = true) -X-Forwarded-Hostcan be injectedImpact
Vulnerability Type
Attack Scenarios
1. Password Reset Poisoning (High Severity)
2. Email Verification Bypass
3. OAuth/SSO Callback Manipulation
ctx.hostnamefor OAuth redirect URIs4. Web Cache Poisoning
5. Server-Side Request Forgery (SSRF)
ctx.hostnameWho Is Impacted
ctx.hostnameorctx.originfor URL generation without additional validationSeverity
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:NReferences
This data is provided by the GitHub Advisory Database (CC-BY 4.0).
Release Notes
koajs/koa (koa)
v2.16.4Compare Source
What's Changed
ctx.hostnameby @killagu GHSA-7gcc-r8m5-44qmv2.16.3Compare Source
What's Changed
Full Changelog: koajs/koa@v2.16.2...v2.16.3
Configuration
📅 Schedule: (in timezone Europe/Helsinki)
🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.
♻ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about these updates again.
This PR was generated by Mend Renovate. View the repository job log.