Blog | G5 Cyber Security

SameSite Cookies: Are They Still a Risk?

TL;DR

Yes, SameSite cookie vulnerabilities can still be present today if not implemented correctly or if older browsers are supported. While modern browsers have good support for Secure and SameSite attributes, misconfiguration or lack of consistent application across your entire domain remains a problem. This guide explains how to check for issues and fix them.

1. Understanding SameSite Cookies

SameSite cookies are an important cyber security measure designed to prevent Cross-Site Request Forgery (CSRF) attacks. They control when cookies are sent with cross-site requests. There are three main values:

2. Checking Your Cookie Attributes

You need to verify how your cookies are configured. Here’s how:

  1. Browser Developer Tools: The easiest way is using your browser’s developer tools (usually accessed by pressing F12).
  • Command Line (using curl): You can also use command-line tools to inspect cookies.
    curl -v https://yourdomain.com/somepage

    Look for the Set-Cookie header in the output. It will show you the cookie attributes.

  • 3. Identifying Potential Vulnerabilities

    Here are common issues to look for:

    4. Fixing SameSite Vulnerabilities

    1. Set the SameSite Attribute: For most applications, SameSite=Lax is a good starting point. If you need cross-site functionality, carefully consider using SameSite=None with Secure.
      Set-Cookie: sessionid=abcdefg; Domain=yourdomain.com; Path=/; SameSite=Lax; Secure
    2. Ensure Secure Attribute is Present for None: If using SameSite=None, always include the Secure attribute.
      Set-Cookie: sessionid=abcdefg; Domain=yourdomain.com; Path=/; SameSite=None; Secure
    3. Update Your Code: Modify your server-side code (e.g., PHP, Python, Node.js) to include the SameSite attribute when setting cookies.

      Example (PHP):

      setcookie('sessionid', 'abcdefg', ['samesite' => 'Lax', 'secure' => true]);
    4. Test Thoroughly: After making changes, test your application in different browsers (including older versions) to ensure functionality isn’t broken and cookies are behaving as expected. Use the developer tools described earlier.
    5. Content Security Policy (CSP): Consider using a Content Security Policy to further mitigate CSRF risks by controlling which resources your browser is allowed to load.

    5. Supporting Older Browsers

    Older browsers may not fully support the SameSite attribute. You might need to consider alternative mitigation techniques for these users, such as:

    Exit mobile version