Sobes.tech
Middle+

What cookie settings are available (httpOnly, secure, expires, domain, path)?

sobes.tech AI

Answer from AI

Cookie is a small data fragment that the server sends to the browser, which the browser saves and sends back on subsequent requests to the same server. Cookies have several important settings:

  • HttpOnly — if set, the cookie is inaccessible via JavaScript (e.g., document.cookie), enhancing security by preventing XSS attacks.
  • Secure — the cookie is only transmitted over a secure HTTPS connection.
  • Expires — the date and time when the cookie expires and is deleted. You can specify a specific date or use Max-Age for the lifetime in seconds.
  • Domain — the domain for which the cookie is valid. It allows sharing cookies between subdomains.
  • Path — the server path for which the cookie will be sent. For example, /account — the cookie will only be sent with requests to this path and its subdirectories.

Example of setting a cookie with these parameters in an HTTP header:

Set-Cookie: sessionId=abc123; HttpOnly; Secure; Expires=Wed, 09 Jun 2024 10:18:14 GMT; Domain=example.com; Path=/