iPhone Google Reader/Gmail/Facebook Cookie Fix

By | March 15, 2008

This post was going to be all about how I finally caved and bought an iPhone, but instead it is a treatise on open systems, and an explanation about how to fix an annoying bug with Safari on the iPhone.

I’ve had an iPhone for about 3 days, and am loving it. However, it had an extremely irritating bug whereby cookies wouldn’t seem to ‘stick’ in Safari. Symptoms:

  • I’d log into GMail, and my login details wouldn’t carry over to Google Reader
  • After logging into Google Reader, I’d be prompted again to login after about a minute of browsing stories
  • Same with Facebook. Sometimes login wouldn’t work, sometimes I’d be re-prompted for my login

I presumed this was an issues with a jailbroken phone, but then I saw others with the same issue. After hunting around in the iPhone filesystem for a bit, I found the location of the Cookies file: /var/mobile/Library/Cookies/Cookies.plist.

Looking inside that cookies file (cat it or something), I saw no sign of Facebook or Google accounts. On a whim, I checked the permissions, and they were very restrictive, so I did the old “open to all” chmod:

chmod 777 /var/mobile/Library/Cookies/
chmod 666 /var/mobile/Library/Cookies/Cookies.plist

(If you want to know all about chmod and what I’m doing with those commands, here is an explanation).

On further investigation, I’ve worked out that the ownership of the Cookies folder and file are wrong. On some phones, they seem to be owned by ‘root’, and need to be owned by ‘mobile’. Here’s the code to fix the ownership of the files:

chown -R mobile /var/mobile/

Et voila! It worked! After logging in to Facebook, I went back and looked at the Cookies.plist file, and there, plain as day, was a big fat Facebook cookie. GMail and Reader share an authentication cookie, and I’ve not been prompted for another login. At least one other reader over on the Apple forums confirms the fix works.

Ideally of course, I should find out the identity that Safari is running under, and provide access to that one identity, but for a quick and dirty fix, chmod 777 is fine. After all, your Cookies file is not particularly exciting if someone does manage to pwn your iPhone. Done! Chown mobile is a much tidier fix than chmod 777

Now here’s the deal kids: some people with pristine, locked iPhones are having this issue. They are completely outta luck and will have to live with this issue until Apple issue a fix. Those of us with ‘open’ hardware on the other hand (thanks to the help of myriad hackers), can diagnose, locate, and resolve our own issues. Just like the Maker’s Bill of Rights says.

Now do you understand why locked-down hardware and systems are bad? Did I just break the DMCA by fixing my iPhone?

Update: Madness. I had searched for ages to find a solution to my problem, but now that I’ve solved it, a Google search for the solution turns up tons of hits. Damn Google!!

52 thoughts on “iPhone Google Reader/Gmail/Facebook Cookie Fix

  1. Travis Washam

    Dude!!! found the link to here from your post on dermapthera.wordpress.com and I am seriously glad I did. I didnt realize how much i used the facebook app until I had to type my info in 40 times per session! I SSH’d into the phone and changed my permissions per your advice and it works perfect now! thanks!!!

    Reply
  2. Travis Washam

    edit edit edit
    apparently I have no clue what i am talking about.. if you can delete the previous edit then please do so. But I want to give props to the forum that you posted this link on and it was definitely on macworld.. sorry for the edits and thanks again for the advice

    Reply
  3. Ben Post author

    Hey thanks Travis. Yeah I cross-posted the fix on several forums. Note I’ve now worked out the *actual* problem (file ownership) which is a much nicer fix.

    Reply
  4. Travis Washam

    edit edit edit
    apparently I have no clue what i am talking about.. if you can delete the previous edit then please do so. But I want to give props to the forum that you posted this link on and it was definitely on macworld.. sorry for the edits and thanks again for the advice

    Reply
  5. JC

    Ben dude, it’s nice to see a *IHASIPHONE* post with actual, grunty nerd content.

    Good stuff *(now get back to the funk and post moar pics/stuff about the iPhone in your gloat thread)*

    Reply
  6. Phil Lavelle

    Thanks so much – this was a massive problem driving me mad and you appear to have helped me solve it!!!

    Got to ask though -j how do you get that great Vodafone logo at the top? Mine is onOrange but I’d love to do the same!!!!

    Reply
  7. Ben Post author

    Glad to help Phil.
    The vodafone logo came from the team at http://kiwi-ise.co.nz. I don’t think they have an Orange logo, but you could probably contact them to find out how they did it, so you can make your own.

    Reply
  8. Ben

    Glad to help Phil.
    The vodafone logo came from the team at http://kiwi-ise.co.nz. I don’t think they have an Orange logo, but you could probably contact them to find out how they did it, so you can make your own.

    Reply
  9. Pingback: iPhone in New Zealand « Ratnakar’s Weblog

  10. Pingback: Fix cookie problems with iPhone - MacTalk Forums

  11. Jason

    This all seems great!
    One problem I don’t understand where to place that line of code?
    You said it’s in the iPhone file system, but how do I access and manually edit that and know where to place it, can someone please help me with that part?

    Cheers.

    Reply
  12. Ben Post author

    Jason,

    You need to have a jailbroken iPhone. You also need to install the Term-vt100 package, which will give you a command line interface into the iPhone’s file system.

    Once you have that, open vt100, enter the password (usually ‘alpine’), then type in the commands.

    Reply
  13. Ben

    Jason,

    You need to have a jailbroken iPhone. You also need to install the Term-vt100 package, which will give you a command line interface into the iPhone’s file system.

    Once you have that, open vt100, enter the password (usually ‘alpine’), then type in the commands.

    Reply
  14. Ryu

    any other way you can do that? terminal doesnt seem to work when i tried to login

    Reply
  15. Ben Post author

    Sorry, if you’re running the 1.1.4 (or 1.1.3 I think) firmware, there’s also a “SUID Fix” installer package you need to install, otherwise the password won’t work. See here: http://osmethne.com/?q=node/9

    Reply
  16. Ben Post author

    Stu, once you use one for a couple of days, it you’ll get over it :)

    Nah seriously, the GPRS speed is the *only* annoying thing about the iPhone. Everything else is as damn near perfect as I’ve ever had on a phone, and lordy knows I’ve had a few phones.

    Reply
  17. Juan Perez

    Thanks for the solution,

    I just change the Cookies directory owner
    chown -R mobile /var/mobile/Library/Cookies

    That works for me,

    Anyone have the original permisions for
    /var/mobile/Library/Cookies/ and
    /var/mobile/Library/Cookies/Cookies.plist

    Reply
  18. Pingback: How to fix Safari cookies logout bug on iPhone firmware 1.1.4 | iPhone Passion

  19. Mas

    Ok… this might sound like a really slow question as I have not seen anyone ask it, but for those who DONT KNOW….

    How do you “change ownership” and enter:

    chown -R mobile /var/mobile/

    I can access my iPhone via SSH and WinScp and reach root and stuff and change CHMOD

    But what is this change ownership and can U just PLEASE excuse me and help simplify that? Thanks.

    Reply
  20. Ben Post author

    Mas, by typing that command (chown …) you are changing ownership of all files and directories inside /var/mobile.

    You don’t need to do anything else. No chmod or anything. Just type that chown command and it’s all fixed.

    Reply
  21. Dor

    hey,
    first of all thank for the post.
    i ran into a problem and I wonder if you guys can help.
    I installed terminal and typed in the “chown” command in order to change ownership
    and got “changing ownership is not permitted” .
    can anyone try helping me please ?
    thanks

    Reply
  22. Dor

    hey,
    first of all thank for the post.
    i ran into a problem and I wonder if you guys can help.
    I installed terminal and typed in the “chown” command in order to change ownership
    and got “changing ownership is not permitted” .
    can anyone try helping me please ?
    thanks

    Reply
  23. Michael McGlade (mcglaysia)

    Thanks for the help. There are indeed many other help sites, but yours is the most readable and useful. Though, I did have trouble trying to do this right on the phone and ended up using ssh from my Mac and that worked great. I guess because when I was on the phone, root and alpine were not working but by logging in via ssh I could specify a user (root) and alpine worked fine. The ssh tip that helped me was at http://www.tuaw.com/2007/07/23/ssh-on-iphone/
    I had already installed afpd on the phone so had already dealt with that.

    Thanks again.

    Reply
  24. Adam

    Thanks for your investigative work, dude. Saved me doing it too – as they say – Google first, ask questions later. :) Legend.

    Reply
  25. Mourad zaoui

    i have a lil probleme here each time i try to enter the fix i keep on getting “Operation Not permitted” am i doing something wrong here
    pls help
    thx

    Reply
  26. Blake

    Mourad Zaoui,
    I get the same thing when I try to do this fix. It hasn’t worked for me.

    Reply
  27. Blake

    Mourad Zaoui,
    I get the same thing when I try to do this fix. It hasn’t worked for me.

    Reply
  28. Ben Post author

    I’m not sure what the problem might be. Are you definitely logged in to SSH as root?

    Reply
  29. Mourad zaoui

    logged in how do i do that …and iam not using shh iam using that term?inal thing

    Reply
  30. Justin

    Okay, so after some searching (and inability to install OpenSSH via Installer.app) I found Cydia (which is available via Installer). Install Cydia and you can then install OpenSSH. Once I did this I was able to login to root on term. To do this type “login” enter “root” press return, for password type “alpine” (passwords do not show up, even dots, in terminal but it does take the password). Press return. You should now see root# rather than mobile$ which indicates successful login as root. Once you have done this enter the string listed in the article and you will ownership will be corrected. Of interest, I did not get an echo of all the files modified, but it seems to have successfully corrected ownership. If you have changed your root password Cydia will apparently help you change it but I have no experience with this feature. Hope this helps!

    Reply
  31. Yann

    I found another solution that should be suitable to people not having jailbreaked iPhone, and therefore not able to ssh into it.

    The culprit file is corrrupted into your backup, so no matter how many time you restore your iphone, it will be restored as-is, and wrong.

    The solution is to delete it from your iphone backup before restoring :

    Open a terminal window, and type :

    grep ?Library/Cookies/Cookies.plist? ~/Library/Application\ Support/MobileSync/Backup/*/*

    If you have one backup, as most people do, you should have only one line as a result. delete this file from the mentioned directory, and restore again.

    Reply
  32. Pingback: Reading Never Got So Busy…and Mobile | FINAL COLUMN

  33. Pingback: Ben.geek.nz » My Year in Review: Good News, Bad News

  34. Pingback: Facebook constantly logs out in Safari | Rick Tech

  35. Pingback: Anyone else have cookie issues with iPhone?

  36. Pingback: QuickPwn 2.2.5 Released for Windows - Page 6

  37. Brad Zimmerman

    My cookies file got horked after I upgraded to 2.2.1. I figured it was a permissions issue or something like that and sure enough… Besides chown’ing I also chgrp’d; the owner was set to root and the group was “507191” instead of mobile. Seems ok now.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *