Skip to content

MozillaCookieJar does not handle session cookies #61366

Closed

Description

@piotrdobrogost
BPO 17164
Nosy @orsenthil, @jdetrey, @remilapeyre
PRs
  • gh-61366: Read session cookies written by curl and Wget #11792
  • gh-61366: Read session cookies written by curl and Wget #11792
  • gh-61366: Read session cookies written by curl and Wget #11792
  • Files
  • session-cookies.patch: patch
  • session-cookies-test.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2013-02-08.21:23:23.026>
    labels = ['3.7', '3.8', 'type-bug', 'library']
    title = 'MozillaCookieJar does not handle session cookies'
    updated_at = <Date 2019-02-08.16:39:40.983>
    user = 'https://bugs.python.org/piotrdobrogost'

    bugs.python.org fields:

    activity = <Date 2019-02-08.16:39:40.983>
    actor = 'remi.lapeyre'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2013-02-08.21:23:23.026>
    creator = 'piotr.dobrogost'
    dependencies = []
    files = ['37627', '37629']
    hgrepos = []
    issue_num = 17164
    keywords = ['patch']
    message_count = 6.0
    messages = ['181703', '182501', '233574', '233579', '335081', '335095']
    nosy_count = 5.0
    nosy_names = ['orsenthil', 'piotr.dobrogost', 'jdetrey', 'remi.lapeyre', 'Ramy Abdel-Azim']
    pr_nums = ['11792', '11792', '11792']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue17164'
    versions = ['Python 3.6', 'Python 3.7', 'Python 3.8']

    Linked PRs

    Activity

    1. piotrdobrogost commented on Feb 8, 2013

      piotrdobrogostmannequin
      MannequinAuthor

      It seems there's no information on how should session cookies be stored in the Netscape/Mozilla's cookies.txt file with regard to expiry time - see http://www.cookiecentral.com/faq/#3.5 Maybe Netscape has not been saving such cookies at all thus this lack of specification? Nevertheless, both wget and curl use 0 as expiry time to denote session cookies; it works both when reading cookies from file and writing to file. However Python's MozillaCookieJar's class uses empty string for the same purpose which makes it incompatible both with wget and curl - see http://hg.python.org/cpython/file/bd8afb90ebf2/Lib/http/cookiejar.py#l2027

      I propose to make a change in implementation of MozillaCookieJar class and treat cookies with 0 set as expiry time as session cookies both when reading from a file and writing to a file.

      Motivation for this bug report comes from the following question on Stack Overflow - http://stackoverflow.com/q/14742899/95735

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or error
      on Feb 8, 2013
    3. piotrdobrogost commented on Feb 20, 2013

      piotrdobrogostmannequin
      MannequinAuthor

      I could try to write a patch with some help if there was any chance it might be accepted. Where do I start?

    4. jdetrey commented on Jan 7, 2015

      jdetreymannequin
      Mannequin

      Dear all,

      Here is a small tentative patch for fixing this issue.

      Expiry times for session cookies are now written as "0", and both "0" and "" are parsed as valid expiry times for session cookies.

      Cheers,
      Jérémie.

    5. jdetrey commented on Jan 7, 2015

      jdetreymannequin
      Mannequin

      Hi again,

      Attached is a patch for adding test cases to test_cookiejar.

      Cheers,
      Jérémie.

    6. RamyAbdel-Azim commented on Feb 8, 2019

      RamyAbdel-Azimmannequin
      Mannequin

      Hi,

      Is there any update on this ticket? I would love to use Requests instead of writing a curl command and running it from the command line out of my script but I need this functionality to pull the cookies.txt file in.

      Thanks!
      _Ramy

    7. remilapeyre commented on Feb 8, 2019

      remilapeyremannequin
      Mannequin

      Hi Ramy, thanks for bumping the issue.

      The solution suggested by Piotr Dobrogost is backward compatible and I think it's the right thing to do.

      I opened a new PR thanks to the patch of Jérémie Detrey.

    8. transferred this issue fromon Apr 10, 2022
    9. serhiy-storchaka commented on Aug 12, 2026

      @serhiy-storchaka
      Member

      There is no standard for this file format. RFC 6265 only specifies the Set-Cookie and Cookie headers, and the Netscape format was never specified. The de-facto definition is curl's documentation, which describes the expires field as "seconds since Jan 1st 1970, or 0".

      Reading and writing are not symmetric. I checked with curl 8.18 and Python 3.13 and 3.14:

      • curl ignores the line if the expires field is empty, so session cookies written by MozillaCookieJar.save() are lost when the file is read by curl.
      • Older Python interprets 0 as an already expired timestamp and discards the cookie, so session cookies written by curl are lost when the file is read by Python.

      Reading both 0 and the empty field is therefore safe and can be backported. But writing 0 makes the files incompatible with unpatched Python, including 3.13 and 3.14, so it is rather a new feature.

      #11792 changes both. Its test also uses test.support.TESTFN and MozillaCookieJar.header, which no longer exist, and this is why all CI jobs fail.

    10. 3 remaining items

    11. added 7 commits that reference this issue on Aug 12, 2026
    12. added a commit that references this issue on Aug 12, 2026
    13. added 2 commits that reference this issue on Aug 14, 2026
    14. added a commit that references this issue on Oct 10, 2026
    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

      3.13only security fixes3.14bugs and security fixes3.15bugs and security fixes3.16new features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

      Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions