← Home ← Codex ← DEBT ← Engine
Browse by Category
+ added · updated 7d
← Back to glossary

SameSite Cookie Attribute

Security CWE-352 OWASP A1:2021 PHP 7.3+ Intermediate
debt(d5/e2/b3/t6)
d5 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'specialist tool catches' (d5), semgrep and owasp-zap can flag missing SameSite attributes or SameSite=None without Secure, but it won't show up in normal compilation or default linting.

e2 Effort Remediation debt — work required to fix once spotted

Closest to 'one-line patch' (e1) but slightly higher because cookie settings may be set in multiple places (session_set_cookie_params, setcookie calls, framework config), so e2 reflects a small parameterised fix across a handful of call sites.

b3 Burden Structural debt — long-term weight of choosing wrong

Closest to 'localised tax' (b3), applies to web context cookie configuration — affects authentication/session layer but doesn't reshape the system architecture.

t6 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'serious trap' (t7), the misconception that Lax fully replaces CSRF tokens is widespread and dangerous, plus the SameSite=None+Secure requirement contradicts intuition — developers consistently guess wrong about coverage.

About DEBT scoring →

Also Known As

SameSite attribute SameSite=Strict SameSite=Lax SameSite=None

TL;DR

A cookie attribute controlling whether the browser sends a cookie with cross-site requests, providing strong CSRF mitigation.

Explanation

SameSite has three values: Strict (cookie never sent with cross-site requests — breaks OAuth flows), Lax (cookie sent on top-level navigations like link clicks, not on embedded requests — default in modern browsers), and None (cookie sent everywhere — requires Secure attribute). SameSite=Lax is the practical CSRF defence for most session cookies. In PHP, set it via session_set_cookie_params(['samesite' => 'Lax', 'secure' => true, 'httponly' => true]) or in the Set-Cookie header via setcookie().

Common Misconception

SameSite=Lax fully replaces CSRF tokens. Lax allows cookies on top-level GET navigations, meaning GET endpoints that trigger state changes are still unprotected. CSRF tokens remain necessary for complete coverage.

Why It Matters

SameSite prevents browsers from sending cookies on cross-site requests, cutting off the most common CSRF attack vector without requiring token-based protection.

Common Mistakes

  • Setting SameSite=None without also setting the Secure flag — browsers reject this combination.
  • Assuming SameSite=Lax fully protects against CSRF — top-level GET navigations still send the cookie.
  • Not setting SameSite at all and relying on the browser default, which varies across browser versions.
  • Setting SameSite=Strict on cookies needed for third-party embeds, breaking legitimate cross-site access.

Code Examples

✗ Vulnerable
session_set_cookie_params(['httponly' => true]); // missing SameSite & Secure
✓ Fixed
session_set_cookie_params(['httponly' => true, 'secure' => true, 'samesite' => 'Lax']);

Added 15 Mar 2026
Edited 22 Mar 2026
Views 165
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings F 0 pings S 0 pings S 1 ping M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 2 pings M 0 pings T 0 pings W 0 pings T 2 pings F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 1 ping S 2 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 1 ping S
Amazonbot 1
No pings yesterday
ChatGPT 39 Amazonbot 19 Scrapy 13 Perplexity 11 Google 10 SEMrush 7 Ahrefs 6 Bing 5 PetalBot 5 Unknown AI 3 Meta AI 2 Applebot 2 Twitter/X 1 Brave Search 1
crawler 119 crawler_json 4 pre-tracking 1
DEV INTEL Tools & Severity
🟠 High ⚙ Fix effort: Low
⚡ Quick Fix
Set SameSite=Lax for most cookies (default in modern browsers) and SameSite=Strict for highest security admin sessions — use SameSite=None only for explicitly cross-site cookies
📦 Applies To
PHP 7.3+ web
🔗 Prerequisites
🔍 Detection Hints
Session cookie without SameSite attribute; SameSite=None without Secure flag; missing PHP 7.3+ samesite option
Auto-detectable: ✓ Yes owasp-zap semgrep lighthouse
⚠ Related Problems
🤖 AI Agent
Confidence: High False Positives: Low ✓ Auto-fixable Fix: Low Context: Line
CWE-352 CWE-1275


✓ schema.org compliant