C Sharp Insecure Cookie Generation
Description
Detects when HTTP cookies are created without required security attributes in C# applications. Cookies missing security flags like Secure, HttpOnly, or SameSite are vulnerable to client-side scripting attacks and session hijacking.
Detection Strategy
• Identifies creation of HttpCookie objects in C# code
• Checks if the cookie object is initialized without security-critical attributes (Secure, HttpOnly, SameSite)
• Reports a vulnerability when a cookie is created with default/insecure settings that could expose it to attacks
• Specifically looks for HttpCookie instantiations that don't set security properties after creation
Vulnerable code example
using System.Net;
using System;
public class CookieExample
{
public void CreateInsecureCookie()
{
// Vulnerable: Cookie created without HttpOnly flag set...✅ Secure code example
using System.Net;
using System;
public class CookieExample
{
public void CreateSecureCookie()
{
// Secure: Cookie with HttpOnly and Secure flags set...Search for vulnerabilities in your apps for free with Fluid Attacks' automated security testing! Start your 21-day free trial and discover the benefits of the Continuous Hacking Essential plan. If you prefer the Advanced plan, which includes the expertise of Fluid Attacks' hacking team, fill out this contact form.