Skip to main content
The Cookie helper provides utilities for reading, writing, and managing HTTP cookies in your Hono application, including support for signed cookies and cookie prefixes.

Import

Getting Cookies

Retrieve a specific cookie value by name:

Get All Cookies

Retrieve all cookies as an object:

Setting Cookies

Set a simple cookie with default options:
Set a cookie with custom options:
string
default:"/"
The path where the cookie is available
boolean
Whether the cookie should only be sent over HTTPS
string
The domain where the cookie is available
boolean
Whether the cookie is accessible only through HTTP(S)
number
Maximum age in seconds
Date
Expiration date of the cookie
'Strict' | 'Lax' | 'None'
SameSite attribute for CSRF protection
'secure' | 'host'
Cookie prefix for enhanced security

Signed Cookies

Signed cookies provide tamper protection by including a cryptographic signature.
getSignedCookie returns false if the signature is invalid, undefined if the cookie doesn’t exist, or the cookie value if valid.

Get All Signed Cookies

Cookie prefixes provide additional security guarantees enforced by browsers.

Secure Prefix

Cookies with __Secure- prefix must be set with the secure flag:

Host Prefix

Cookies with __Host- prefix must be secure, have path /, and no domain:
With host prefix, the domain and custom path options are automatically ignored for security.

Deleting Cookies

Basic Delete

Delete with Options

Match the same options used when setting the cookie:

Get Deleted Value

deleteCookie returns the value that was deleted:
For advanced use cases, generate cookie strings without setting them:

Multiple Cookies

Set multiple cookies in a single response:

Best Practices

Use Signed Cookies

Use signed cookies for sensitive data that needs tamper protection

Set HttpOnly

Use httpOnly: true for cookies that don’t need JavaScript access

Use Secure Flag

Always use secure: true in production to ensure HTTPS-only transmission

Match Delete Options

When deleting cookies, use the same path and domain used when setting

Security Considerations

Never store sensitive data in unsigned cookies - Cookies can be easily read and modified by clients. Use signed cookies or server-side sessions for sensitive data.
Cookie prefixes (__Secure- and __Host-) provide additional security enforced by browsers. Use them for sensitive cookies.