Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
V5630. OWASP. Possible cookie...
menu mobile close menu
Additional information
toggle menu Contents

V5630. OWASP. Possible cookie injection. Potentially tainted data is used to create a cookie.

Jun 05 2025

The analyzer has detected that unverified external data is used to create a cookie object. If this data is compromised, it may cause a cookie injection.

The example:

public void ChangeCookie()
{
  String cookieValue = Request.Form["userRole"];

  Response.Cookies.Add(
    new HttpCookie(WebLocalizationConfiguration.CookieName, cookieValue)
    {
      Expires = Clock.Now.AddYears(2),
      Path = Request.ApplicationPath
    }
  );
  ....
}

In this case, a new object of the HttpCookie class is added to HttpResponse and is initialized using the external data, Request.Form. Using data without any verification or validation can allow attackers to manipulate an application.

To protect code against cookie injections, ensure that any data used to initialize the HttpCookie object is validated.

The fixed code:

public void ChangeCookie()
{
  String cultureValue = Request.Form["userRole"];
  
  if (!Regex.IsMatch(cultureValue, DataValidationPattern))
    return;

  Response.Cookies.Add(
    new HttpCookie(WebLocalizationConfiguration.CookieName, cultureValue)
    {
      Expires = Clock.Now.AddYears(2),
      Path = Request.ApplicationPath
    }
  );
  ....
}

Before initializing the HttpCookie object with potentially tainted data, execute a validation check via a regular expression.

This diagnostic is classified as:

close form

Fill out the form in 2 simple steps below:

Your contact information:

Step 1
Congratulations! This is your promo code!

Desired license type:

Step 2
Team license
Enterprise license
close form
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
close form
Free PVS‑Studio license for Microsoft MVP specialists
close form
To get the licence for your open-source project, please fill out this form
close form
I want to join the test
* By clicking this button you agree to our Privacy Policy statement

close form
check circle
Message submitted.

Your message has been sent. We will email you at


If you do not see the email in your inbox, please check if it is filtered to one of the following folders:

  • Promotion
  • Updates
  • Spam