Skip to content

[Cookie] System.Net.Cookie doesn't conform to RFC 2965 #19746

Closed

Description

@mconnew

In RFC 2965, section 3.2.2 it states

Version=value
REQUIRED. The value of the Version attribute, a decimal integer,
identifies the version of the state management specification to
which the cookie conforms. For this specification, Version=1
applies.

In the msdn documentation for Cookie.Version, it states

The default value for the Version property is 0, complying with the original Netscape specification. If the value is explicitly set to 1, then this Cookie must conform to RFC 2109.

RFC 2109 was obsoleted by RFC 2965 so as per the newer spec, specifying Version=1 means RFC 2965 applies. RFC 2109 requires a specified domain to be have a leading dot whereas RFC 2965 does not require this. When making a request using HttpClient to an HTTP server which returns a cookie with an explicit domain without a leading dot and specifying version=1, the cookie is dropped. Here is some simple code reproducing the issue.

            var mycookie = "lang=en-US; Domain=example.com;Path=/;version=1";
            var uri = new Uri("http://example.com");
            CookieContainer container = new CookieContainer();
            container.SetCookies(uri, mycookie);

This throws a CookieException when the cookie is valid. The cookie parsing code in HttpClient swallows this exception.

RFC 2965 is further obsoleted by RFC 6265 which makes no mention of the Version attribute but does say that there is no need for a leading dot, and if it is there, to strip it out and ignore it. So either the latest RFC should apply in which case the example cookie I provided should parse, or the latest RFC which claims it should apply which mentions the Version attribute should apply.

Activity

  1. davidsh commented on Feb 26, 2017

    @davidsh
    Contributor

    Changing this could break app-compat. Will need to study it and write pinning tests to validate behaviors.

  2. CIPop commented on Mar 23, 2017

    @CIPop
    Contributor

    This seems to be a duplicate of #18597.
    @mconnew please reopen if I missunderstood.

  3. mconnew commented on May 3, 2017

    @mconnew
    MemberAuthor

    Reopening as this is a different issue than #18597. That's about retrieving a cookie which is in CookieCollection. This is about CookieContainer throwing an exception when parsing a valid cookie that is being attempted to be added. If the scope of issue #18597 includes addressing parsing of valid cookies which are currently being dropped, then please can you explicitly add that to the issue so that it doesn't get dropped.
    Btw, I discovered this issue while trying to use OAuth connecting to a public facing Microsoft service from a UWP app in a personal project. I had to revert to using the UWP HttpClient as the native cookie management implementation handled the cookies correctly and it only got dropped when copying the cookies to the managed CookieContainer class. So there is currently an interop issue with the managed HttpClient and public Microsoft http services.

  4. reopened this on May 3, 2017
  5. karelz commented on May 4, 2017

    @karelz
    Member

    Triage: Does not look critical + it is involved => moved to Future.

  6. mconnew commented on May 18, 2017

    @mconnew
    MemberAuthor

    @karelz, this will prevent OAuth authentication from working when communicating with some services. This is how I discovered the issue, I was trying to use a Microsoft public OAuth provider and my code wouldn't work as the needed cookie was being dropped. If my project hadn't been a UWP app and instead a .Net Core app, I would have had no solution. I would consider the complete inability to authenticate against some websites as being more than non-critical,

  7. karelz commented on May 19, 2017

    @karelz
    Member

    Does it work in Desktop?
    How common is the scenario?

  8. mconnew commented on Jun 14, 2017

    @mconnew
    MemberAuthor

    Doesn't work on Desktop. I can't tell you how common it is, but it was a Microsoft public service that I was communicating with that had the OAuth cookie which was dropped so we are in the situation where a Microsoft networking stack doesn't work with a Microsoft service.

  9. karelz commented on Jun 14, 2017

    @karelz
    Member

    Makes sense. Let's keep it in Future, until we get more information on the impact.

    The fact the 'affected' service was Microsoft service does not change things too much. If it was something large and impactful (inside MS or outside), we would consider it / work with the service owners to adjust it or work around the limitation. At this moment I don't know which service it is and if the owners consider it important problem at all.

  10. changed the title [-]System.Net.Cookie doesn't conform to RFC 2965[/-] [+][Cookie] System.Net.Cookie doesn't conform to RFC 2965[/+] on May 8, 2018
  11. caesar-chen commented on May 11, 2018

    @caesar-chen
    Contributor

    The developing work (implementing RFC 6265) is tracked in #26141.

  12. transferred this issue fromdotnet/corefxon Jan 31, 2020
  13. added this to the 3.0 milestone on Jan 31, 2020
  14. ghost locked as resolved and limited conversation to collaborators on Dec 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Netenhancementtenet-compatibility

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions