The Security Trio: HttpOnly, Secure, and SameSite
Learn about the three critical security flags that protect cookies from common attacks.
In this lesson, you will learn to:
- Define the purpose and function of the HttpOnly, Secure, and SameSite cookie attributes.
The Security Trio: HttpOnly, Secure, and SameSite
This lesson introduces the HttpOnly, Secure, and SameSite flags. You will learn what each flag does, how it is configured, and which attack it prevents.
Understanding the Security Flags
Cookies have three critical security flags that developers can set to protect them from common attacks. These flags are sent as attributes when the server creates the cookie.
HttpOnly – This flag prevents JavaScript from accessing the cookie. When HttpOnly is set, the cookie can only be sent to the server through HTTP requests. This is crucial because it stops Cross-Site Scripting (XSS) attacks from stealing session cookies through malicious JavaScript code.
Secure – This flag ensures the cookie is only sent over HTTPS connections. If the Secure flag is set, the browser will never transmit the cookie over an unencrypted HTTP connection. This protects against network sniffing and Man-in-the-Middle attacks.
SameSite – This flag controls when the cookie is sent in cross-site requests. It has three values: Strict (only sent for same-site requests), Lax (sent for top-level navigation), and None (sent for all requests, but requires Secure). This flag is designed to prevent Cross-Site Request Forgery (CSRF) attacks by limiting how cookies are sent to other domains.