Pickling/unpickling Cookie.SimpleCookie fails with protocol=2

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Erwin S. Andreasen

    #1

    Pickling/unpickling Cookie.SimpleCookie fails with protocol=2


    Pickling a Cookie.SimpleCo okie (or SmartCookie) when using protocol=2
    seems to do something very strange. Protocol 0/1 work fine:

    $ python2.4
    Python 2.4.2 (#2, Nov 20 2005, 17:04:48)
    [GCC 4.0.3 20051111 (prerelease) (Debian 4.0.2-4)] on linux2
    Type "help", "copyright" , "credits" or "license" for more information.
    [color=blue][color=green][color=darkred]
    >>> import cPickle, Cookie
    >>> cPickle.loads(c Pickle.dumps(Co okie.SimpleCook ie('hi=there')) )[/color][/color][/color]
    <SimpleCookie : hi='there'>

    Protocol 2 however:
    [color=blue][color=green][color=darkred]
    >>> pickle.loads(pi ckle.dumps(Cook ie.Cookie('hi=t here'),2))[/color][/color][/color]
    <SmartCookie: hi=<Morsel: hi='there'>>
    [color=blue][color=green][color=darkred]
    >>>pickle.loads (pickle.dumps(C ookie.Cookie('h i=there'),2))['hi'].__dict__[/color][/color][/color]

    {'coded_value':
    '"ccopy_reg\\01 2_reconstructor \\012p1\\012(cC ookie\\012Morse l\\012p2\\012c_ _builtin__\\012 dict\\012p3\\01 2(dp4\\012S\'co mment\'\\012p5\ \012S\'\'\\012s S\'domain\'\\01 2p6\\012S\'\'\\ 012sS\'version\ '\\012p7\\012S\ '\'\\012sS\'sec ure\'\\012p8\\0 12S\'\'\\012sS\ 'path\'\\012p9\ \012S\'\'\\012s S\'expires\'\\0 12p10\\012S\'\' \\012sS\'max-age\'\\012p11\\ 012S\'\'\\012st Rp12\\012(dp13\ \012S\'coded_va lue\'\\012p14\\ 012S\'there\'\\ 012p15\\012sS\' value\'\\012p16 \\012g15\\012sS \'key\'\\012p17 \\012S\'hi\'\\0 12p18\\012sb."' ,
    'value': <Morsel: hi='there'>, 'key': 'hi'}


    I can't really say what goes wrong here, but it looks like a bug to me
    -- comments? I guess I'll have to go to protocol 0 for this, or not
    serialize the cookie but re-parse it on the other side (this pickle
    gets passed down a UNIX socket together with the file descriptor of a
    request, in a load balancing system).



    --
    =============== =============== =============== =============== ===
    <erwin@andrease n.org> London, E14
    <URL:http://www.andreasen.o rg/> <*>
    =============== =============== =============== =============== ===

  • Paul Rubin

    #2
    Re: Pickling/unpickling Cookie.SimpleCo okie fails with protocol=2

    "Erwin S. Andreasen" <erwin+usenet@a ndreasen.org> writes:[color=blue]
    > Pickling a Cookie.SimpleCo okie (or SmartCookie) when using protocol=2
    > seems to do something very strange. Protocol 0/1 work fine:[/color]

    Don't use SmartCookies because of the security issue. See the docs.

    Comment

    • Georg Brandl

      #3
      Re: Pickling/unpickling Cookie.SimpleCo okie fails with protocol=2

      Erwin S. Andreasen wrote:[color=blue]
      > Pickling a Cookie.SimpleCo okie (or SmartCookie) when using protocol=2
      > seems to do something very strange. Protocol 0/1 work fine:
      >
      > $ python2.4
      > Python 2.4.2 (#2, Nov 20 2005, 17:04:48)
      > [GCC 4.0.3 20051111 (prerelease) (Debian 4.0.2-4)] on linux2
      > Type "help", "copyright" , "credits" or "license" for more information.
      >[color=green][color=darkred]
      >>>> import cPickle, Cookie
      >>>> cPickle.loads(c Pickle.dumps(Co okie.SimpleCook ie('hi=there')) )[/color][/color]
      > <SimpleCookie : hi='there'>
      >
      > Protocol 2 however:
      >[color=green][color=darkred]
      >>>> pickle.loads(pi ckle.dumps(Cook ie.Cookie('hi=t here'),2))[/color][/color]
      > <SmartCookie: hi=<Morsel: hi='there'>>
      >[color=green][color=darkred]
      >>>>pickle.load s(pickle.dumps( Cookie.Cookie(' hi=there'),2))['hi'].__dict__[/color][/color]
      >
      > {'coded_value':
      > '"ccopy_reg\\01 2_reconstructor \\012p1\\012(cC ookie\\012Morse l\\012p2\\012c_ _builtin__\\012 dict\\012p3\\01 2(dp4\\012S\'co mment\'\\012p5\ \012S\'\'\\012s S\'domain\'\\01 2p6\\012S\'\'\\ 012sS\'version\ '\\012p7\\012S\ '\'\\012sS\'sec ure\'\\012p8\\0 12S\'\'\\012sS\ 'path\'\\012p9\ \012S\'\'\\012s S\'expires\'\\0 12p10\\012S\'\' \\012sS\'max-age\'\\012p11\\ 012S\'\'\\012st Rp12\\012(dp13\ \012S\'coded_va lue\'\\012p14\\ 012S\'there\'\\ 012p15\\012sS\' value\'\\012p16 \\012g15\\012sS \'key\'\\012p17 \\012S\'hi\'\\0 12p18\\012sb."' ,
      > 'value': <Morsel: hi='there'>, 'key': 'hi'}
      >
      >
      > I can't really say what goes wrong here, but it looks like a bug to me
      > -- comments? I guess I'll have to go to protocol 0 for this, or not
      > serialize the cookie but re-parse it on the other side (this pickle
      > gets passed down a UNIX socket together with the file descriptor of a
      > request, in a load balancing system).[/color]

      You can report a bug at SourceForge.

      Georg

      Comment

      • Erwin S. Andreasen

        #4
        Re: Pickling/unpickling Cookie.SimpleCo okie fails with protocol=2

        "Erwin S. Andreasen" <erwin+usenet@a ndreasen.org> writes:
        [color=blue]
        > Pickling a Cookie.SimpleCo okie (or SmartCookie) when using protocol=2
        > seems to do something very strange. Protocol 0/1 work fine:[/color]

        Oh well, it seems that it's a well-known bug that has been around for
        more than 2 years:

        http://sourceforge.net/tracker/index...70&atid=105470

        http://sourceforge.net/tracker/index...70&atid=105470

        --
        =============== =============== =============== =============== ===
        <erwin+usenet@a ndreasen.org> London, E14
        <URL:http://www.andreasen.o rg/> <*>
        =============== =============== =============== =============== ===

        Comment

        Working...