Bug 6405 - HttpWebRequest sends duplicate cookies
Summary: HttpWebRequest sends duplicate cookies
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: master
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-08-06 00:45 UTC by Martin Potter
Modified: 2012-08-15 16:29 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Martin Potter 2012-08-06 00:45:11 UTC
We currently use some WCF endpoints that were failing when upgrading to Mono 2.11.2. It appears that the cookies in the supplied CookieContainer are being duplicated, causing the cookie-based authentication to fail. In testing, it appears there is a difference in the way Mono and Microsoft handle cookie headers when a CookieContainer is specified. To demonstrate the issue, run compile the following program and examine the cookie header sent.


using System;
using System.Net;

namespace WebRequestCookies
{
	class WebRequestCookies
	{
		static void Main(string[] args)
		{
			CookieContainer container = new CookieContainer();
			container.Add(new Uri("http://www.mono-project.com"), new Cookie("foo", "bar"));
			HttpWebRequest request = (HttpWebRequest) WebRequest.Create("http://www.mono-project.com/Main_Page");
			request.CookieContainer = container;
			WebHeaderCollection headers = request.Headers;
			headers.Add("Cookie", "foo=baz");
			HttpWebResponse response = (HttpWebResponse)request.GetResponse();
		}
	}
}


Only foo=bar should be sent as the cookie header; Mono currently sends foo=baz,foo=bar. On Microsoft's implementation, it appears that when a CookieContainer is set, it becomes the authoritative source for cookie information and only the cookies present in the CookieContainer are sent.
Comment 1 Martin Potter 2012-08-06 00:50:05 UTC
Submitted pull request with fix, https://github.com/mono/mono/pull/420
Comment 2 Martin Potter 2012-08-06 15:03:03 UTC
Added tests for the expected behavior.
Comment 3 Miguel de Icaza [MSFT] 2012-08-15 16:29:36 UTC
Patch applied