Μετάβαση στο κύριο περιεχόμενο
← 📄 HTML & the platform·Ενότητα A3 · Μάθημα 16
ΕργασίαBuild a logout form. <form method='post' action='/logout'> with a CSRF hidden input, a clear submit button labelled 'Log out'. Add a Note paragraph below explaining 'GET would be unsafe here — the browser would attach your session cookie even from a third-party link.'

Cookies SameSite: το ήμισυ της άμυνας CSRF που κάνει το πρόγραμμα περιήγησης για εσάς

75 XP7 min
Θεωρία

What SameSite does

When your server sets a cookie, you can tag it with a SameSite attribute. The browser then decides whether to send that cookie on cross-site requests.

Set-Cookie: session=abc; HttpOnly; Secure; SameSite=Lax
SameSite valueBehaviour
StrictCookie sent ONLY when the request URL matches your site. Even clicking a link from google.com to yoursite.com arrives logged-out.
Lax (browser default in 2026)Sent on top-level GET navigations from other sites, NOT on cross-site POSTs / iframes / fetch. Stops most CSRF without breaking link-clicks.
NoneSent on everything cross-site. Requires Secure. Use only for embeds you genuinely need (3rd-party iframes, federated auth).

Why this isn't a full defence

SameSite=Lax blocks the classic auto-submitting <form> attack from earlier — Chrome / Firefox / Safari all enforce it now. But:

  • Older browsers / corporate-pinned versions don't enforce it.
  • Subdomains can still bite you (evil.yoursite.com is "same site").
  • If your endpoint accepts GET for a state-changing action, Lax doesn't help (GET requests still send the cookie).

Use SameSite=Lax + a CSRF token together. Defence in depth.

What the form lesson says

The cookie attribute is a server concern, not HTML. But the form's method is yours: never use `method="get"` for anything that changes state. The whole SameSite + CSRF system assumes state changes happen via POST.

🔒

Εγγράψου για να αρχίσεις να προγραμματίζεις

Η θεωρία είναι ανοιχτή για όλους. Ο επεξεργαστής, η ζωντανή προεπισκόπηση και ο έλεγχος ξεκλειδώνουν με 7-ήμερη δωρεάν δοκιμή — απαιτείται κάρτα.

Εγγραφή — δωρεάν δοκιμή →

Τα πρώτα 10 μαθήματα κάθε διαδρομής είναι δωρεάν. Δεν χρειάζεται κάρτα.

← ΠροηγούμενοΕπόμενο μάθημα →

Μια συμβουλή Python ή web την ημέρα — με email

Σύντομο, γραμμένο στο χέρι, χωρίς spam. Διαγραφή με ένα κλικ.