Guide · Security basics
Cookies and CORS for an AI-built app, in plain English
Your app’s cookies hold your users’ sign-in, and three settings keep them safe: Secure, HttpOnly and SameSite. CORS is the rule that decides which other websites may read your app’s answers inside a visitor’s browser. The dangerous mistake is a server that says yes to every website, with the visitor’s cookies attached. Each fix is a few lines, and neither problem shows until someone uses it.
The four, at a glance
Secure: the browser never sends the cookie over plain http://.Set itHttpOnly: a script slipped into your page can’t copy it.Set itSameSite=Lax or Strict: requests that start elsewhere go without the sign-in.Set itAccess-Control-Allow-Origin names your domains, never whoever asks.Set itThe first three go on each cookie. The last is a header your server sends with its answers.
Cookies: Secure, HttpOnly and SameSite
A cookie is a small note your server asks the browser to keep. The browser sends it back with every request to your site, which is how your app remembers who’s signed in. So whoever has the sign-in cookie is signed in as that person. Three settings in the Set-Cookie header that creates a cookie keep it where it belongs (MDN):
- Secure: the browser sends the cookie only over HTTPS, so nobody on the same Wi-Fi can read it on the way.
- HttpOnly: JavaScript on the page can’t read the cookie (MDN). If someone slips a script into your page, it can’t copy the sign-in and use it elsewhere. The cookie is still sent with every request, so your app works the same.
- SameSite: decides whether the cookie goes along with requests that start on another website.
Laxsends it when someone follows a link to your site, but not with other sites’ form posts or background requests.Strictnever sends it from another site.Nonealways does, and must also be Secure.
Some browsers treat a cookie with no SameSite as Lax, but not all of them do. So set it yourself. And only a Set-Cookie header from your server can make a cookie HttpOnly. A cookie your page’s own JavaScript writes can be read by any script on the page.
What our checker flags: every cookie your page sets on the first visit needs Secure and SameSite. A cookie whose name looks like a sign-in (it contains sess, sid, token, auth, jwt or login) also needs HttpOnly. Without it, that’s a Fix now. The rest are Worth fixing.
If a sign-in library sets your cookies, fix them in its settings, not in headers you write by hand. The prompt asks your AI tool to do it that way.
Prompt for Lovable, Bolt, Cursor or Claude Code
Review every cookie my app sets. Make all of them Secure and SameSite=Lax (or Strict), and make any session, auth or token cookie HttpOnly so JavaScript can’t read it. If my auth library sets them, change its config instead of writing headers by hand.
How do I see my app’s cookies?
- Open your live app in Chrome and the developer tools (F12, or right-click › Inspect). Go to Application › Storage › Cookies and pick your site (Chrome docs). Firefox’s Storage Inspector shows the same list.
- Each row is a cookie. Look at the Secure, HttpOnly and SameSite columns. A blank one isn’t set.
- Sign in and look again. The sign-in cookie often appears only then.
Our checker sees the cookies your page sets on a first visit, signed out. Step 3 is the part only you can do.
CORS: who may read your answers
Browsers keep websites apart. A page on another site can send a request to your app, but its scripts can’t read the answer unless your app says that site may (MDN). That permission is the Access-Control-Allow-Origin header. It names the one website allowed to read the answer, or * for any. Letting the visitor’s cookies come along is a second permission, Access-Control-Allow-Credentials: true.
CORS is a rule browsers follow, not a lock on your API. curl, scripts and other servers ignore it and can call your API directly (PortSwigger). So your API still has to check who’s signed in on every request.
The mistake: saying yes to every website
The header can name only one website (MDN). So when an app needs to allow a few, a quick fix is to copy whichever website is asking into the header. Then every website is allowed. With credentials allowed too, any site your users visit can make requests to your app with their sign-in and read the answers: their profile, their data, anything your app would show them. Security researchers list it among the classic CORS bugs (PortSwigger).
What our checker flags: we ask your page for its answer as if from a made-up website. If that made-up address comes back in Access-Control-Allow-Origin and credentials are allowed, that’s Fix now. Echoed without credentials, it’s Worth fixing: no sign-in goes along, but the answer is open to every site.
The safe way is a list of your own domains. Check the request’s Origin against it and send it back only if it’s on the list. Send Vary: Origin too, so a cache doesn’t hand one site’s answer to another (MDN).
Prompt for Lovable, Bolt, Cursor or Claude Code
My server reflects any Origin in Access-Control-Allow-Origin. Replace this with an explicit list of my own domains, and only send Access-Control-Allow-Credentials on routes that really need it.
Is a * in Access-Control-Allow-Origin a problem?
For a public page, no. Anyone can open it anyway, and browsers refuse to combine * with credentials (MDN), so a * answer never carries a sign-in. Our checker passes it and says so. For your API, name your own domains instead, so only your app’s pages can read its answers.
How do I see my CORS headers?
Ask your app for a page as if from another website, and look at what comes back:
Command for your terminal
curl -s -o /dev/null -D - -H "Origin: https://example.com" https://yourapp.com/
It prints the headers your app sends back. If access-control-allow-origin says https://example.com, your app echoes any website. Look for access-control-allow-credentials: true too. Then run it again with one of your API addresses in place of the last part.
What this can’t tell you
We check the page you give us, once, on a first visit, signed out. Cookies set after sign-in and the CORS headers on your API routes can be different, so look at those yourself with the steps above. And these settings only limit the damage. A locked-down sign-in cookie still needs an app that checks, on every request, what that person may see.