Insecure Cookie Configuration in Bolt Application
Your Bolt.new application stores authentication tokens or session data in cookies without proper security attributes. Missing HttpOnly, Secure, and SameSite flags leave your users' sessions vulnerable to theft through XSS attacks, man-in-the-middle interception, and cross-site request forgery.
When Bolt generates authentication code, it may set cookies using basic document.cookie assignments or use a cookie library with default (insecure) settings. This means session tokens can be read by JavaScript (enabling XSS-based theft), transmitted over unencrypted HTTP connections, and sent along with cross-site requests.
An attacker who steals a session cookie can impersonate any user on your platform, access their data, make purchases on their behalf, or escalate privileges to admin accounts. This is a silent vulnerability that leaves no trace until it's exploited.
Error Messages You Might See
Common Causes
- Missing HttpOnly flag — Cookies are readable by JavaScript via document.cookie, so any XSS vulnerability can steal session tokens
- Missing Secure flag — Cookies are sent over unencrypted HTTP connections, allowing interception on public WiFi networks
- SameSite not set to Strict or Lax — Cookies are sent with cross-site requests, enabling CSRF attacks
- Cookies set from client-side JavaScript — Using document.cookie or js-cookie instead of setting cookies from the server with proper flags
- Overly broad cookie domain or path — Cookies scoped to a parent domain or root path, making them accessible to other subdomains or paths that may be compromised
How to Fix It
- Set cookies from the server — Use Set-Cookie headers from your API routes instead of document.cookie: res.setHeader('Set-Cookie', `token=${value}; HttpOnly; Secure; SameSite=Lax; Path=/; Max-Age=86400`)
- Enable HttpOnly — This prevents JavaScript from accessing the cookie, blocking XSS-based theft entirely
- Enable Secure flag — Ensures cookies are only sent over HTTPS connections, preventing interception
- Set SameSite to Lax or Strict — Lax allows cookies on top-level navigations (links), Strict blocks all cross-site cookie sending
- Use a session library — Install iron-session or next-auth which handle secure cookie configuration by default
- Set proper expiration — Use Max-Age or Expires instead of session cookies for persistent login, and set reasonable timeouts
Real developers can help you.
You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.
Get HelpFrequently Asked Questions
What is the difference between HttpOnly, Secure, and SameSite?
HttpOnly prevents JavaScript access to the cookie (blocks XSS theft). Secure ensures the cookie is only sent over HTTPS. SameSite controls whether cookies are sent with cross-site requests (blocks CSRF). You need all three for proper security.
Should I use localStorage or cookies for auth tokens?
Cookies with HttpOnly and Secure flags are safer for auth tokens because JavaScript cannot access them, making XSS attacks ineffective. localStorage is readable by any script on the page, so a single XSS vulnerability exposes all tokens.