Last modified: 2014-01-03 15:50:50 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T43586, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 41586 - On wikidata.org, api login returns wrong lgtoken (object replacement character) in response body; correct in HTTP header
On wikidata.org, api login returns wrong lgtoken (object replacement characte...
Status: VERIFIED FIXED
Product: Wikimedia
Classification: Unclassified
Wikidata (Other open bugs)
unspecified
All All
: Normal normal with 1 vote (vote)
: ---
Assigned To: Sam Reed (reedy)
: shell, testme
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-10-31 14:04 UTC by merl
Modified: 2014-01-03 15:50 UTC (History)
17 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments
bash script for testing the API response (800 bytes, text/plain)
2013-01-04 14:01 UTC, Daniel Kinzler
Details
bash script for testing the API response (860 bytes, text/plain)
2013-03-08 21:09 UTC, Daniel Kinzler
Details

Description merl 2012-10-31 14:04:51 UTC
the lgtoken attribute (which is need to create a valid cookie for future requests) is invalid after successful login.

request (POST):
action=login&lgpassword=xxx&lgname=MerlIwBot

response:
<api><login result="NeedToken"
 token="087cb80705ed9564d18c3309fae1ec"
 cookieprefix=wikidatawiki
 sessionid="9b4c867c526e06f0e55ee395287ff0"
/></api>

request (POST):
action=login&lgtoken=087cb80705ed9564d18c3309fae1ec&lgpassword=xxx&lgname=MerlIwBot

response:
<api><login result="Success"
 lguserid="3280"
 lgusername="MerlIwBot"
 lgtoken="��������������������������������"
 cookieprefix=wikidatawiki
 sessionid="9b4c867c526e06af0e55ee39f287ff0"
/></api>

password, sessionid and first token is a bit modified for this paste of course. The problem is that the lgtoken is invalid because it only contains character hex:EF BF BD (which is "object replacement character" according to unicode table)

Login on all other wmf wikis and wikidata-test-repo.wikimedia.de work for me.
Comment 1 Sam Reed (reedy) 2012-10-31 16:32:09 UTC
WFM

"<?xml version=\"1.0\"?><api><login result=\"Success\" lguserid=\"2\" lgusername=\"Reedy\" lgtoken=\"3e07eb6f2406cf44c5f222884aa0ac83\" cookieprefix=\"wikidatawiki\" sessionid=\"09cdced66371121d024c7082f8a0c0f4\" /></api>"
Comment 2 merl 2012-10-31 18:09:03 UTC
If i am additionally using centralauth cookie (read from header instead builded from api response) it works for me, too. But not without centralauth cookie as it is described at http://www.mediawiki.org/wiki/API:Login#How_to_log_in
Comment 3 Daniel Kinzler 2012-10-31 20:06:16 UTC
Using the API sandbox, I can request a token without any problems: 

http://www.wikidata.org/wiki/Special:ApiSandbox#action=login&format=json&lgname=Foo&lgpassword=Bar

(no, that's not my password. It will generate a valid token anyway).

Closing WFM. Please supply a minimal test case to reproduce the issue if you want to reopoen it.
Comment 4 Lydia Pintscher 2012-12-14 11:19:44 UTC
reopening based on comments at http://www.wikidata.org/wiki/Wikidata:Contact_the_development_team#API:_Login_doesn.27t_work.3F
Comment 5 Daniel Kinzler 2012-12-14 11:40:45 UTC
I can reproduce the problem now for wikidata.org. The token is returned correctly as an HTTP header it seems, but not in the response body. The same request works fine on en.wikipedia.org and also with my local install with wikibase enabled. 

There must be something odd going on during token creation, but I have no idea what.
Comment 6 merl 2012-12-14 11:42:54 UTC
Test script:

#!/bin/bash
#FILENAME: login.sh
#USAGE: login.sh USERNAME PASSWORD DOMAIN
USERNAME="$1"
PASSWD="$2"
DOMAIN="${3:-www.wikidata.org}"
 
RESP1=`wget -qO- --no-cookies --user-agent=LOGIN --post-data "action=login&lgname=${USERNAME}&lgpassword=${PASSWD}&format=xml" http://${DOMAIN}/w/api.php`
echo "${RESP1}"
TOKEN=`echo "${RESP1}" | sed -ne '/<login/ { s/.*token="\([^"]*\)".*/\1/; p }'`
SESSIONID=`echo "${RESP1}" | sed -ne '/<login/ { s/.*sessionid="\([^"]*\)".*/\1/; p }'`
COOKIEPREFIX=`echo "${RESP1}" | sed -ne '/<login/ { s/.*cookieprefix="\([^"]*\)".*/\1/; p }'`
 
wget -qO- --no-cookies --user-agent=LOGIN --post-data "action=login&lgname=${USERNAME}&lgpassword=${PASSWD}&lgtoken=${TOKEN}&format=xml" --header "Cookie: ${COOKIEPREFIX}_session=${SESSIONID}" http://${DOMAIN}/w/api.php


----
works on dewiki:
 $ bash login.sh MerlIwBot XXX de.wikipedia.org
 <?xml version="1.0"?><api><login result="NeedToken" token="1b0e04d8ec9cd7f28210e2fe8c1cad86" cookieprefix="dewiki" sessionid="67c2c8150e3fa887e86d3e9b19722449" /></api>
 <?xml version="1.0"?><api><login result="Success" lguserid="1234" lgusername="MerlIwBot" lgtoken="7874ac3a1851e9f93af3912bf4b00d6b" cookieprefix="dewiki" sessionid="67c2c8150e3fa887e86d3e9b19722449" /></api>
 
invalid lgtoken on wikidata.org:
 $ bash login.sh MerlIwBot XXX www.wikidata.org
 <?xml version="1.0"?><api><login result="NeedToken" token="da90161c74826a5629029fc857970660" cookieprefix="wikidatawiki" sessionid="92b3e5f5e6cdd7145516732b79ca5845" /></api>
 <?xml version="1.0"?><api><login result="Success" lguserid="1234" lgusername="MerlIwBot" lgtoken="��������������������������������" cookieprefix="wikidatawiki" sessionid="92b3e5f5e6cdd7145516732b79ca5845" /></api>
Comment 7 Daniel Kinzler 2012-12-17 08:54:53 UTC
@andre: assigning this to wikidata-bugs is not helpful, since it doesn't seem to be a problem with the Wikibase software. This issue is not present on any other system running Wikibase, and Wikibase doesn't mess with the login process or tokens. This seems to be a configuration issue, or some oddity related to having a wiki with no subdomain.

In any case, we at the very least need help from someone with shell access for debugging this. So I think it makes sense to keep this on wikibugs-l.
Comment 8 Andre Klapper 2012-12-17 11:45:12 UTC
Daniel: I didn't assign it on purpose, it's just the default assignee.
If it's a config issue I'll move it to "Site requests".
Comment 9 jeblad 2012-12-17 13:53:05 UTC
I wonder if we in the beginning asked for a new token as we used a special itemtoken. That would reset the other tokens to. I think the code is gone now as we use the edittoken, but I'm not completly sure.

After checking the code I'm pretty sure its gone.
Comment 10 Daniel Kinzler 2012-12-17 14:25:08 UTC
(In reply to comment #9)
> I wonder if we in the beginning asked for a new token as we used a special
> itemtoken. 

Even then, the token would change, but it would not suddenly consist of invalid characters.
Comment 11 Daniel Kinzler 2012-12-17 14:27:39 UTC
(In reply to comment #8)
> Daniel: I didn't assign it on purpose, it's just the default assignee.

Ah, you changed the component, now I see.

> If it's a config issue I'll move it to "Site requests".

*If* it's a config issue - but I'm afraid we'll need some life-site-debugging to find that out.
Comment 12 Daniel Kinzler 2013-01-04 14:01:37 UTC
Created attachment 11586 [details]
bash script for testing the API response

Provide any name and password as first and second parameters to check the token.
Comment 13 Daniel Kinzler 2013-01-04 14:03:47 UTC
I have attached the test script provided by merl at https://www.wikidata.org/wiki/Wikidata:Contact_the_development_team/Archive/2012/12#API:_Login_doesn.27t_work.3F

Running it now, it seems to work:

bash ~/src/bug-41586.sh foo bar
<?xml version="1.0"?><api><login result="NeedToken" token="cd3f7d845bef68f23fd4f9f37f1c1fc7" cookieprefix="wikidatawiki" sessionid="8181ac1523df3d24ec18d1be4fec8153" /></api>

<?xml version="1.0"?><api><login result="NotExists" /></api> 


Please check whether it works for you now. Otherwise, we can close the bug. Would be nice to understand what was going on, though...
Comment 14 Andre Klapper 2013-01-10 10:58:08 UTC
Merl:
Please check whether it works for you now.

Decreasing priority for the time being, as it's currently not reproducible as per comment 9 and 13.
Comment 15 Daniel Kinzler 2013-01-10 11:11:49 UTC
Sorry, I was wrong, I *can* reproduce it: if I run the test script with a valid user name and password, I get back a broken lgtoken.
Comment 16 Andre Klapper 2013-01-10 11:31:41 UTC
RT #4304.
Comment 17 Sam Reed (reedy) 2013-01-10 22:28:16 UTC
WFM (with Daniels script)...
Comment 18 Daniel Kinzler 2013-01-11 12:54:29 UTC
(In reply to comment #17)
> WFM (with Daniels script)...

with a valid name & password? can you post the output, please?
Comment 19 Andre Klapper 2013-02-18 14:50:18 UTC
Reedy: Could you answer comment 18?
Comment 20 Andre Klapper 2013-02-26 15:07:52 UTC
Comment in the RT ticket is:
"I think this rather needs attention from wikidata dev people, which would be Wikimedia Deutschland people almost entirely, afaik"


I get the same results as in comment 6, using the Bash script in https://www.wikidata.org/wiki/Wikidata:Contact_the_development_team/Archive/2012/12#API:_Login_doesn.27t_work.3F

$:andre\> ./login.sh Malyacko xxxxxxxx de.wikipedia.org
<?xml version="1.0"?><api><login result="NeedToken" token="48dc7df07df9d9b6529c7d56f33c2eb5" cookieprefix="dewiki" sessionid="392cc0b55fe5b7594d3fd41536421c89" /></api>

<?xml version="1.0"?><api><login result="Success" lguserid="1220085" lgusername="Malyacko" lgtoken="f409b84cd9049810ecf8db70eac8e9f4" cookieprefix="dewiki" sessionid="392cc0b55fe5b7594d3fd41536421c89" /></api> 

$:andre\> ./login.sh Malyacko xxxxxxxx www.wikidata.org
<?xml version="1.0"?><api><login result="NeedToken" token="aa8e747286dc98018d750cac5ee62b6b" cookieprefix="wikidatawiki" sessionid="b54e252498f7c97280965e4736c4035b" /></api>

<?xml version="1.0"?><api><login result="Success" lguserid="37514" lgusername="Malyacko" lgtoken="��������������������������������" cookieprefix="wikidatawiki" sessionid="b54e252498f7c97280965e4736c4035b" /></api>
Comment 21 Daniel Kinzler 2013-02-26 20:29:03 UTC
(In reply to comment #20)
> Comment in the RT ticket is:
> "I think this rather needs attention from wikidata dev people, which would be
> Wikimedia Deutschland people almost entirely, afaik"

I do not see how the Wikidata team can do anything about this.

* We do not deal with login code or token generation at all. The problem occurs with a core API call that has nothing to do with the Wikibase extension.

* The problem is exclusive to wikidata.org. We can not reproduce it on any of our test systems.

* Nobody in the Wikidata team has the access level necessary to investigate the issue.

So, what do you suggest the Wikidata team can do about the problem?
Comment 22 Daniel Kinzler 2013-02-27 01:46:12 UTC
An extended debugging session by Aaron and Tim unearthed bad tokens appearing in the database due to issues with a schema change. Fixes are on gerrit, see I92f1645d4 and I3529fe8af
Comment 23 jeremyb 2013-03-04 05:56:01 UTC
FIXED?

https://wikitech.wikimedia.org/w/index.php?title=Server_Admin_Log&diff=61872&oldid=61871 says:

> * 21:31 Tim: running resetUserTokens.php on all wikis, in screen on hume, to fix user_token field corruption ([[bugzilla:41586|bug 41586]])
Comment 24 Daniel Kinzler 2013-03-08 21:05:54 UTC
I am still getting the broken token.
Comment 25 Daniel Kinzler 2013-03-08 21:09:37 UTC
Created attachment 11899 [details]
bash script for testing the API response

Improved test script: no password on the command line, runs output through hexdump.
Comment 26 Daniel Kinzler 2013-03-08 21:13:33 UTC
Still open. Corrupt tokens are still in the database:

[22:07] <AaronSchulz> Tim was running a script but it stalled out and needed to be batched
[22:07] <AaronSchulz> I don't think he ever rewrote it, so the rows are probably still broken
Comment 27 Andre Klapper 2013-04-03 08:47:00 UTC
Tim / Aaron: How can we get some progress here in order to get this fixed?
Comment 28 Andre Klapper 2013-05-30 13:32:10 UTC
Works for me now with the script in comment 25, token seems to be correct.

Daniel Kinzler: Can you confirm?
Comment 29 Andre Klapper 2013-06-13 19:11:14 UTC
Works for me now with the script in comment 25, token seems to be correct.

Daniel Kinzler: Can you confirm?
Comment 30 Andre Klapper 2013-06-19 07:11:18 UTC
No answer => Closing.
Comment 31 Daniel Kinzler 2013-06-19 09:48:24 UTC
I do not know whether this is fixed for all users. The issue is rooted in a corrupt entry in the user table (ask Aaron or Tim for details). So, this issue would affect some users but not others, until all user entries in the database have been fixed. I do not have a way to check this.
Comment 32 Andre Klapper 2013-06-19 23:22:55 UTC
Reopening as per last comment.
Comment 33 Chris Steipp 2013-06-27 16:18:03 UTC
I'll take a look at making resetUserTokens.php more efficient, and then we can find someone to run it for the affected wikis.

Aaron, could you find out which wikis had the wrong column definition?
Comment 34 Aaron Schulz 2013-06-27 16:38:06 UTC
(In reply to comment #33)
> I'll take a look at making resetUserTokens.php more efficient, and then we
> can
> find someone to run it for the affected wikis.
> 
> Aaron, could you find out which wikis had the wrong column definition?

It really should just be run on all wikis.

The script can be made faster by:
(a) Batching the SELECT by user_id
(b) Avoiding the User function to update the token and doing it directly
(c) Batching these token updates
(d) A script option can be added to skip rows with valid tokens (the bad ones are all \0, good ones should have the right length and hex chars)
Comment 35 Gerrit Notification Bot 2013-08-01 15:50:43 UTC
Change 77136 had a related patch set uploaded by CSteipp:
Efficiently reset null user tokens

https://gerrit.wikimedia.org/r/77136
Comment 36 Gerrit Notification Bot 2013-08-29 00:20:54 UTC
Change 77136 merged by jenkins-bot:
Efficiently reset null user tokens

https://gerrit.wikimedia.org/r/77136
Comment 37 Chris Steipp 2013-09-19 16:09:43 UTC
Patch has been merged. Reedy, can you run maintenance/resetUserTokens.php on the cluster at some point?
Comment 38 Andre Klapper 2013-10-18 18:42:16 UTC
Reedy, can you run maintenance/resetUserTokens.php on the cluster at some point?
Comment 39 Greg Grossmeier 2013-10-18 22:31:20 UTC
This should actually be done, as a consequence of the fun potential data breach response (all tokens were reset on affected wikis, and wikidata was one).

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


Navigation
Links