Modify

Opened 2 months ago

Closed 2 months ago

#14361 closed defect (fixed)

AttributeError raised when session id is regenerated with Python 3

Reported by: Jun Omae Owned by: Jun Omae
Priority: normal Component: AccountManagerPlugin
Severity: normal Keywords:
Cc: Trac Release: 1.6

Description

Originally reported at trac:#13792.

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/trac/web/api.py", line 662, in __getattr__
    value = self.callbacks[name](self)
  File "/usr/local/lib/python3.10/dist-packages/trac/web/main.py", line 180, in authenticate
    authname = authenticator.authenticate(req)
  File "/usr/local/lib/python3.10/dist-packages/acct_mgr/util.py", line 54, in wrap
    return func(self, *args, **kwds)
  File "/usr/local/lib/python3.10/dist-packages/acct_mgr/web_ui.py", line 488, in authenticate
    return super(LoginModule, self).authenticate(req)
  File "/usr/local/lib/python3.10/dist-packages/trac/web/auth.py", line 97, in authenticate
    authname = self._get_name_for_cookie(req,
  File "/usr/local/lib/python3.10/dist-packages/acct_mgr/web_ui.py", line 596, in _get_name_for_cookie
    cookie.value = hex_entropy()
AttributeError: can't set attribute 'value'

Using .set method seems to to be fixed instead of directly set .value property.

  • acct_mgr/web_ui.py

    a b class LoginModule(auth.LoginModule): 
    593593            if random.random() + self.cookie_refresh_pct / 100.0 > 1:
    594594                old_cookie = cookie.value
    595595                # Update auth cookie value
    596                 cookie.value = hex_entropy()
     596                new_cookie = hex_entropy()
     597                cookie.set('value', new_cookie, new_cookie)
    597598                self.log.debug("Changing session id for user %s to %s", name,
    598599                               cookie.value)
    599600

Python 3

Python 3.11.10 (main, Sep  7 2024, 18:35:42) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from trac.web.api import Cookie
>>> cookies = Cookie('name1=value1; name2=value2')
>>> cookies
<Cookie: name1='value1' name2='value2'>
>>> cookies['name1']
<Morsel: name1=value1>
>>> cookies['name1'].value = '?'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: property 'value' of 'Morsel' object has no setter
>>> cookies['name1'].value = 'vvv'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: property 'value' of 'Morsel' object has no setter
>>> cookies['name1'].set('value', 'vvvv', 'vvvv')
>>> cookies['name1'].value
'vvvv'
>>>

Python 2.7

Python 2.7.18 (default, Jul  1 2022, 12:27:04)
[GCC 9.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from trac.web.api import Cookie
>>> cookies = Cookie('name1=value1; name2=value2')
>>> cookies['name1']
<Morsel: name1='value1'>
>>> cookies['name1'].set('value', 'vvvv', 'vvvv')
>>> cookies['name1']
<Morsel: value='vvvv'>
>>> cookies
<Cookie: name1='vvvv' name2='value2'>
>>>

Attachments (0)

Change History (1)

comment:1 Changed 2 months ago by Jun Omae

Resolution: fixed
Status: assignedclosed

In 18669:

TracAccountManager 0.6.1dev: fix AttributeError raised when session cookie is regenerated (closes #14361)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Jun Omae.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.