How to fix Session Cookie attributes not set application hosted in web app ?

$@chin 115 Reputation points
2024-11-07T18:27:33.9333333+00:00

How to remediate the issue or vulnerability of Session Cookie attributes not being set when the application is hosted in an Azure web app behind the Azure Application Gateway with WAF ?

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,960 questions
Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
990 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Shree Hima Bindu Maganti 895 Reputation points Microsoft Vendor
    2024-11-08T06:29:54.5166667+00:00

    Hi @$@chin ,

    welcome to the Microsoft Q&A Platform!
    To remediate the vulnerability related to session cookies without secure attributes in an Azure Web App behind an Application Gateway with WAF,

    • Set Cookie Attributes in Code: Configure session cookies with Secure, HttpOnly, and SameSite attributes in the application code.
    var cookieOptions = new CookieOptions
    {
        Secure = true,        // Only send over HTTPS
        HttpOnly = true,      // Prevent access from JavaScript
        SameSite = SameSiteMode.Strict  // Set cross-site restriction
    };
    
    
    • Web.Config Settings (for .NET): Set cookies to require SSL and specify cookieSecure="Always" in web.config.
    <system.web>
        <authentication mode="Forms">
            <forms requireSSL="true" cookieless="UseCookies" />
        </authentication>
        <sessionState cookieSecure="Always" />
    </system.web>
    
    
    • Use Azure Application Gateway Rewrite Rules: Create rewrite rules in Application Gateway to add Secure, HttpOnly, and SameSite attributes if they are missing.
    • Enable HTTPS-Only in Azure Web App: Go to TLS/SSL settings and enable HTTPS Only.
    • Verify with Security Tools: Confirm session cookies have secure attributes using browser dev tools or a vulnerability scanner.
      It help secure session cookies and reduce vulnerability.
      If the answer is helpful, please click "Accept Answer" and kindly upvote it.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.