Bug 480913 - RFE: please provide XMLRPC API for changing session cookie without having to relogin
Summary: RFE: please provide XMLRPC API for changing session cookie without having to ...
Keywords:
Status: CLOSED NEXTRELEASE
Alias: None
Product: Bugzilla
Classification: Community
Component: WebService
Version: 3.2
Hardware: All
OS: Linux
low
low
Target Milestone: ---
Assignee: David Lawrence
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2009-01-21 10:43 UTC by Tomas Hoger
Modified: 2009-02-17 16:19 UTC (History)
0 users

Fixed In Version:
Doc Type: Enhancement
Doc Text:
Clone Of:
Environment:
Last Closed: 2009-02-17 16:19:16 UTC
Embargoed:


Attachments (Terms of Use)
Patch to allow XMLRPC client to regenerate cookie without username/password (v1) (3.09 KB, patch)
2009-01-28 17:47 UTC, David Lawrence
nelhawar: review+
Details | Diff
Test script (5.93 KB, text/plain)
2009-02-11 09:41 UTC, Tomas Hoger
no flags Details

Description Tomas Hoger 2009-01-21 10:43:18 UTC
It would be nice to some XMLRPC API to request change of the session id for active session without having to provide user login and password.  It currently only seems possible to achieve cookie change via User.logout + User.login.

Motivation:
Several scripts / bots exist that need to talk to bugzilla.  Traditionally, they have username and password stored in plain text in some configuration or source file.  That may not always be desired.

Another possibility is to change scripts to store session cookie issued by bugzilla in some cookie file (both perl and python provide ready to use libraries for handling Netscape-style cookie files, and support in SOAP/XMLRPC libraries for using those cookie handling modules).  However, if such cookie is leaked / stolen, it can be used until explicit logout is requested in the context of the BZ session (i.e. in the context of automated script, it most likely remain valid forever / until next forced password reset).

It would be good to have a way (for the scripts that care) to invalidate session cookie at arbitrary time, without completely killing the session (that would require re-authentication).  The idea is similar to PHP's session_regenerate_id() function.  So any leaked / stolen cookie will be useless after some time (depending on the regenerate id request frequency from the script / bot).

Comment 1 David Lawrence 2009-01-28 17:47:10 UTC
Created attachment 330264 [details]
Patch to allow XMLRPC client to regenerate cookie without username/password (v1)

Attaching a patch that creates User.regenerate_cookie() which allows creating of a new session cookie if the user passes in a previous valid cookie. Requires the user to pass in the username as a param but not password.

Please review.
Dave

Comment 2 Noura El hawary 2009-01-29 04:10:34 UTC
Comment on attachment 330264 [details]
Patch to allow XMLRPC client to regenerate cookie without username/password (v1)

Hey Dave,

Patch looks good to me, I tested the function and it works good, just the pod section is not validating for me, and i wasn't sure were you fixing previous pod in it or just adding the pod for the new function?

Thanks,
Noura

Comment 3 David Lawrence 2009-01-29 17:12:58 UTC
Thanks for the review Noura. I fixed the POD errors mentioned.

Tomas, you can see how the new method is used by checking out the API docs 
when this update is pushed live.

https://bugzilla.redhat.com/docs/en/html/api/Bugzilla/WebService/User.html

Dave

Comment 4 Tomas Hoger 2009-01-30 09:38:53 UTC
Ooops, this does not work quite as expected... ;(  It seems to kill incorrect session.

My test situation is:
I'm logged in BZ in the browser, and also have a perl scripts that use HTTP::Cookies::Netscape to store session cookie, and valid cookie in cookie jar file (verified using User.valid_cookie()).

When I call User.regenerate_cookie(), I can see the cookie changed in the cookie jar, scripts session remains valid.  To check whether old cookie was properly invalidated, I hand-edited cookie file used by scripts and had set previous value of Bugzilla_logincookie.  Calling User.valid_cookie() again shows that the old cookie is still accepted.

Trying to access BZ via web browsers shows that my browser session / cookie was invalidated instead.  Seems to be easily reproducible, calling User.regenerate_cookie() always kills my browser session, instead of killing old cookie used by scripts.

Is there currently some way to figure out how many sessions are currently valid for some BZ account?  Or a way to "kill all except current one", something similar to what gmail web ui has?

Should I try to clamp my test scripts to some small test case that may help you?

Comment 5 David Lawrence 2009-02-04 22:32:46 UTC
Thomas, Can you try this test of yours on bz-web2-test.devel.redhat.com and see if a recent fix works for you?

Thanks
Dave

Comment 6 Tomas Hoger 2009-02-05 08:32:15 UTC
Tested on bz-web2-test.  The good thing is that regenerate_cookie now invalidates old cookie, so if I manually set the old cookie in the cookie jar, it is no longer valid.  The bad thing is that regenerate_cookie still affects all my current sessions, not only the one in which regenerate_cookie is called.  I tried to log in via web ui, actually I opened two sessions in two browsers.  Both of them were killed.

Comment 7 Tomas Hoger 2009-02-11 09:41:12 UTC
Created attachment 331544 [details]
Test script

I modified my scripts / modules to create this minimal one-file test script.  Use following to reproduce:

- log into BZ using your preferred browser
- edit bztool and add your username / pw
- ./bztool login, this should create cookies.txt in CWD
- check that Bugzilla_logincookie in browser and cookies.txt file differ (hence different sessions are used by browser and script)
- try ./bztool valid_cookie, ./bztool logout, ./bztool valid_cookie
- check that browser session is still valid after ./bztool logout
- ./bztool login again
- ./bztool regenerate_cookie
- see that your browser session cookie is not valid any more

Comment 8 David Lawrence 2009-02-16 22:07:39 UTC
(In reply to comment #7)
> - log into BZ using your preferred browser
> - edit bztool and add your username / pw
> - ./bztool login, this should create cookies.txt in CWD
> - check that Bugzilla_logincookie in browser and cookies.txt file differ (hence
> different sessions are used by browser and script)
> - try ./bztool valid_cookie, ./bztool logout, ./bztool valid_cookie
> - check that browser session is still valid after ./bztool logout
> - ./bztool login again
> - ./bztool regenerate_cookie
> - see that your browser session cookie is not valid any more

I am able to re-create the issue from your test case. Interesting that the cookies.txt file created by the script is not in the normal Firefox profile path. For example, I have it in ~/Perl/bugzilla. How is Firefox affected by the cookies.txt file in that location? Does Firefox search everywhere in your home directory for cookies.txt file(s) and use that before it uses the standard cookies.sqlite in the profile directory?

Dave

Comment 9 David Lawrence 2009-02-16 22:17:57 UTC
(In reply to comment #8)
> I am able to re-create the issue from your test case. 

> Interesting that the
> cookies.txt file created by the script is not in the normal Firefox profile
> path. For example, I have it in ~/Perl/bugzilla. How is Firefox affected by the
> cookies.txt file in that location? Does Firefox search everywhere in your home
> directory for cookies.txt file(s) and use that before it uses the standard
> cookies.sqlite in the profile directory?

Duh, disregard this part. I was missing what was really happening.

Dave

Comment 10 David Lawrence 2009-02-16 22:24:59 UTC
Ok, I have made a tweak on https://bz-web2-test.devel.redhat.com which seems to have helped this. I changed the bztool to point to that system and now the test case seems to work fine and does not logout my browser which is accessing the same system.

Please give it a try and let me know if it works better.

Dave

Comment 11 Tomas Hoger 2009-02-17 11:23:16 UTC
(In reply to comment #9)
> Duh, disregard this part. I was missing what was really happening.

Yeah, I was not trying to steal the cookie from firefox.  I know python-bugzilla tried to do that, but I gave up trying to use it once firefox 3 switched to using sqlite cookie store.


(In reply to comment #10)
> Ok, I have made a tweak on https://bz-web2-test.devel.redhat.com which seems to
> have helped this. I changed the bztool to point to that system and now the test
> case seems to work fine and does not logout my browser which is accessing the
> same system.

Tried against bz-web2-test with 3 sessions (firefox, konqueror, scipts).  Calling regenerate_cookie in script does not kill other two sessions any more.  Old cookie does no longer seem to be valid after regenerate_cookie.

So looks good to me, thank you!

Comment 15 David Lawrence 2009-02-17 16:19:16 UTC
Fix will be in the next BZ update.


Note You need to log in before you can comment on or make changes to this bug.