Works on this device
Secure Cookie Builder
Build the Set-Cookie line your server sends to store a cookie. Choose Secure, HttpOnly, SameSite, Path, Domain and how long the cookie lasts. The tool checks the rules of RFC 6265 and its draft successor, including the __Host- and __Secure- name prefixes, and writes the line that deletes the cookie too.
Enter your values
Check these values
Your values are worked out in this browser. They are not sent to a server.
Your result will show here
Fill in the values, then choose Make the line.
Your result
How it was worked out
How to use the secure cookie builder
- Type the cookie name and value. Start the name with
__Host-for the strictest rules. - Keep Secure and HttpOnly ticked unless you have a reason not to. Choose SameSite.
- Choose how long the cookie lasts: the browser session, a Max-Age in seconds, or an Expires date.
- Choose Make the line. Read the checks, then copy the Set-Cookie line and the line that deletes the cookie.
The attributes
- Secure: the cookie is sent only over HTTPS. HttpOnly: scripts on the page cannot read it.
- SameSite=Lax sends the cookie on links from other sites but not on their forms and frames; Strict never sends it on requests started by other sites; None sends it on every request and needs Secure.
- Path must start with
/. Domain sends the cookie to that domain and every subdomain; leave it out to keep the cookie on one host. - Max-Age is a number of seconds; Expires is an HTTP date such as
Wed, 31 Mar 2027 00:00:00 GMT. Browsers that know Max-Age use it and ignore Expires. - __Secure- in front of the name means Secure is required. __Host- means Secure, no Domain and
Path=/are required. Browsers refuse a cookie with a prefix that breaks these rules.
Worked example
With the starting values the line is Set-Cookie: __Host-session=f3a9c2e17b40; Path=/; Max-Age=86400; Secure; HttpOnly; SameSite=Lax. The name and value have 14 + 12 = 26 bytes, the cookie lasts 86,400 seconds (1 day), and there are no warnings.
The line that deletes it is Set-Cookie: __Host-session=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT; Secure; HttpOnly; SameSite=Lax.
Limits you should know
- The tool writes text only. It does not set a cookie, test a site or read the cookies of your browser.
- SameSite, the prefixes, the 400-day limit and the size limits come from RFC 6265bis, a draft that browsers follow but that is not yet an RFC. Browsers differ in details, such as the SameSite default when the attribute is left out.
- Percent-encoding of the value is a common practice, not part of RFC 6265. Your server must decode the value the same way.
- Domain names must be typed in ASCII.