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!!
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!!!
Posted by Travis Washam | March 15, 2008, 7:15 amedit 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
Posted by Travis Washam | March 15, 2008, 7:18 amHey 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.
Posted by Ben | March 15, 2008, 7:29 amedit 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
Posted by Travis Washam | March 15, 2008, 3:18 pmBen 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)*
Posted by JC | March 16, 2008, 12:13 pmThanks 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!!!!
Posted by Phil Lavelle | March 17, 2008, 2:42 amGlad 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.
Posted by Ben | March 17, 2008, 5:28 amGlad 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.
Posted by Ben | March 17, 2008, 1:28 pmThanx heaps, this fix was an easy life saver
Posted by Dannystarr | March 17, 2008, 10:01 amThis 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.
Posted by Jason | March 17, 2008, 5:48 pmJason,
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.
Posted by Ben | March 18, 2008, 8:18 amJason,
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.
Posted by Ben | March 18, 2008, 4:18 pmany other way you can do that? terminal doesnt seem to work when i tried to login
Posted by Ryu | March 18, 2008, 6:13 pmSorry, 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
Posted by Ben | March 19, 2008, 12:25 pmDude…an iPhone? They’re not even 3G for goodness sakes!
Posted by Stu | March 27, 2008, 8:24 amStu, 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.
Posted by Ben | March 27, 2008, 8:32 amThanks 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
Posted by Juan Perez | April 2, 2008, 6:11 amThanks a million !
Posted by Chris | April 11, 2008, 3:03 pmOk… 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.
Posted by Mas | April 22, 2008, 5:57 pmMas, 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.
Posted by Ben | April 22, 2008, 6:13 pmthanks man. So great!!! =)
Posted by Alex | April 23, 2008, 8:19 amThanks a lot Ben,
But WHERE do I type that exactly?
Posted by Mas | April 23, 2008, 3:08 pmThanks a lot Ben,
But WHERE do I type that exactly?
Posted by Mas | April 23, 2008, 11:08 pmThanks a lot !!
Posted by francksau | April 28, 2008, 10:56 pmhey,
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
Posted by Dor | May 2, 2008, 8:04 pmhey,
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
Posted by Dor | May 3, 2008, 4:04 amThis worked for me also. Thanks for the tips!
Posted by John H. | May 5, 2008, 8:49 amThanks 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.
Posted by Michael McGlade (mcglaysia) | May 6, 2008, 1:45 amThanks for your investigative work, dude. Saved me doing it too – as they say – Google first, ask questions later.
Legend.
Posted by Adam | May 19, 2008, 3:24 pmi 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
Posted by Mourad zaoui | June 9, 2008, 4:51 amMourad Zaoui,
I get the same thing when I try to do this fix. It hasn’t worked for me.
Posted by Blake | June 10, 2008, 4:14 pmMourad Zaoui,
I get the same thing when I try to do this fix. It hasn’t worked for me.
Posted by Blake | June 11, 2008, 12:14 amSNIF SNIF
Posted by Mourad zaoui | June 11, 2008, 5:31 amGuess no ones around to help
Posted by Blake | June 16, 2008, 4:04 pmI’m not sure what the problem might be. Are you definitely logged in to SSH as root?
Posted by Ben | June 16, 2008, 4:11 pmlogged in how do i do that …and iam not using shh iam using that term?inal thing
Posted by Mourad zaoui | June 17, 2008, 10:52 amOkay, 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!
Posted by Justin | June 22, 2008, 6:22 pmI 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.
Posted by Yann | June 24, 2008, 7:45 amWorked a treat – thanks!
Posted by Alex | July 25, 2008, 7:52 pmthanks dude…. it worked… u rock
Posted by adhyetha | October 13, 2008, 5:35 pmYou are awesome!!!!!
Posted by paz | November 13, 2008, 1:19 amWorked for me!THANXX
Posted by akiss | November 24, 2008, 10:30 pmThanks!! Worked using winscp and open ssh’d my phone
Posted by Ravi | February 9, 2009, 12:03 pmMy 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.
Posted by Brad Zimmerman | February 14, 2009, 1:47 pm