BTC
ETH
SOL
BNB
GOLD
XRP
DOGE
ADA
Back to home
Security

[MEDIUM] Security Advisory: Hono: Non-breaking space prefix bypass in cookie name handling in getCookie() (hono)

Hono developers fixed a cookie parsing bug in their getCookie() function that attackers could exploit to bypass critical prefix protections like __Secure- and __Host-.

Hono developers fixed a cookie parsing bug in their getCookie() function that attackers could exploit to bypass critical prefix protections like __Secure- and __Host-. The issue stems from a mismatch between how browsers handle cookie names and how Hono’s parser normalizes them. Browsers preserve non-breaking spaces (U+00A0) in cookie names, per RFC 6265bis, but Hono’s old parse() used JavaScript’s trim(), which strips them away. Result: an attacker sets a cookie like "\u00A0dummy-cookie", the browser stores it separately from "dummy-cookie", but Hono reads both as the same key.

This matters because cookie prefixes enforce strict security rules. __Secure- cookies transmit only over HTTPS, blocking man-in-the-middle grabs on HTTP pages. __Host- adds domain and path restrictions, plus requires Secure and HttpOnly flags. Bypassing them opens doors to session hijacking or fixation. If your app uses Hono for auth cookies without extra validation, test now—especially if you handle user sessions or tokens.

Technical Breakdown

RFC 6265bis, the evolving standard for cookies, specifies browsers trim only space (0x20) and horizontal tab (0x09) from cookie names and values. Other whitespace-like characters stick around. Browsers treat these as distinct:

"dummy-cookie"
"\u00A0dummy-cookie"  // Non-breaking space prefix

Hono’s getCookie(), before the patch, relied on a parse() function using native String.prototype.trim(). JavaScript’s trim removes a wider set: spaces, tabs, no-break spaces (U+00A0), and more (Unicode whitespace). Both cookies normalize to "dummy-cookie". When your app calls c.getCookie('dummy-cookie'), it grabs the attacker’s version.

Attack vectors include injecting via non-HTTPS pages, XSS, or open redirects. No privilege needed beyond cookie-setting ability. Hono, a lightweight framework for Node.js, Deno, Bun, and Cloudflare Workers, powers fast APIs. This flaw hit versions before the fix—check your package.json for hono under 4.x if unpatched. The advisory marks it medium severity, but in auth-heavy apps, it escalates.

Real-World Risks and Fixes

Why care? Cookie prefixes defend against downgrade attacks and domain mismatches. Without them, a phishing site or MITM on public WiFi overrides your session cookie. Imagine: legit __Secure-session=abc123 for login. Attacker injects "\u00A0__Secure-session=xyz789" over HTTP. Browser stores both; Hono serves the fake. Boom—account takeover.

Real-world parallel: Similar parsing quirks hit Express.js parsers years back, leading to CVEs like CVE-2016-1000027. Browsers evolve slowly; frameworks must match exactly. Hono patched by swapping to a strict trim matching RFC—only SP and HTAB. Update to latest Hono (4.5.0+ as of advisory). Verify with:

npm ls hono
npm update hono

Mitigate beyond patch: Validate cookie names server-side, reject non-ASCII, or use signed cookies (e.g., cookie-signature lib). Skeptical note: Advisories like this often overstate if apps layer defenses—HttpOnly, SameSite=Strict blunt impacts. But solo reliance on Hono’s parser? Risky. Audit your cookie handling; tools like cookie-parser or custom parsers invite these traps.

Broader context: Cookie security remains a minefield. Chrome 110+ enforces stricter prefix rules, but legacy support lingers. Firefox and Safari align closer to RFC. Devs building on edge runtimes like Bun should prioritize exact spec compliance—speed shouldn’t trump safety. If your stack includes Hono, patch immediately and scan traffic for U+00A0 in headers. This isn’t hype; it’s a reminder parsing differences = bypasses.

April 8, 2026 · 3 min · 10 views · Source: GitHub Security

Related