ShieldX Toolly
Open a tool Donate
Home Home
Blog Blog
FAQ FAQ
Open a tool Donate
Back to cheatsheets
Web Security

Cookie Security Flags

Set-Cookie security best practices — HttpOnly, Secure, SameSite, and __Host- prefix.

2 snippets Beginner cookie-analyzer
HttpOnlySecureSameSitecookie prefix

What you'll learn

  • Secure cookie settings
  • Express.js cookie config

How to use these snippets

  1. Click the Copy button next to any snippet to copy it to your clipboard.
  2. Paste the code into your project, IDE, or terminal.
  3. Replace placeholder values (like example.com or your-secret) with your actual data.
  4. Review the code comments for important security notes and caveats.
  5. Try the interactive related tool to see the concept in action.
Code Snippets

Copy-paste code snippets

2 ready-to-use snippets for cookie security flags. Click copy and paste into your project.

Secure cookie settings
                // Recommended Set-Cookie header
Set-Cookie: session=abc123;   HttpOnly;   Secure;   SameSite=Strict;   Path=/;   Max-Age=86400;   __Host- prefix

// SameSite values:
// Strict — never send on cross-site requests (most secure)
// Lax   — send on top-level navigation (default in modern browsers)
// None  — always send (requires Secure, least secure)
              
Express.js cookie config
                res.cookie('session', token, {
  httpOnly: true,       // no JS access
  secure: true,         // HTTPS only
  sameSite: 'strict',   // no cross-site
  path: '/',
  maxAge: 86400000,     // 24h
  signed: true          // prevent tampering
});

// __Host- prefix requires:
// - Secure flag
// - Path=/
// - No Domain attribute
              
Tool

Try this concept hands-on with the interactive tool.

100% Free · No signup · No cost

Generate something unguessable right now

148 bits of entropy, a crack-time estimate you can trust, and a clipboard that clears itself after 30 seconds.

Open the toolkit

Part of the Toolly ecosystem · secure.toolly.site