--
Alex Payne
http://twitter.com/al3x
Do you really have to store the username and pass in the cookie? Hahlo
is, if I remember, a web app, so you should be able to just store the
username and pass server-side in the session data. The cookie would
only need to store a session ID.
If you really *have* to store your data in the cookie, you should be
able to encrypt your cookie data with a two-way hash. It's not optimal
(you should never store authentication data in the cookie, encrypted
or not), but it will make stealing the data significantly harder.
Does Safari on the iPhone support HTTPS-only cookies? If so, I would
be using those as well (again, if you really HAVE to store usernames
and passwords in the cookie).
Remember that *lots* of (most?) people only use a handful of usernames
and passwords for numerous accounts. A lost iPhone or an unknown XSS
exploit in Hahlo or Twitter could cause big, embarrassing trouble.
You can ping me offlist if you wanted to discuss this further, since
the issues are a bit outside scope.
--
Ed Finkler
http://funkatron.com
AIM: funka7ron
ICQ: 3922133
Skype: funka7ron
> Once I get this out Hahlo should be the only third party mobile
> twitter client/webapp not storing raw auth details in a cookie.
Good for you... and also fairly sad for them.
--
Ed Finkler
Works for me. Thanks for taking the security seriously; best to do
the right thing the first time. I wish https was used for the login
screen, but at least the potential for assuming someone's social
identity (say by a top100 Twitterer) and broadcasting a tinyurl
pointing towards a driveby-malware-serving site has been minimized.
Hopefully others will follow your lead.
Regards,
Randal Hicks
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)
iEYEARECAAYFAkgh8pIACgkQHXnD0tz+/vyVnACdEcdI7P8ejlkyt0ro1Y+tXHGp
2ccAn1ieDvbgBUuqpiwPKjOkCbfw+msW
=h59J
-----END PGP SIGNATURE-----
If *any* server is rooted, the attacker can do *whatever they want.*
Stealing data out of session caches is the least of your problems.
SSL is a good idea, yes, but you should *not* be storing this data in
a cookie, period. Dean's current approach has significantly fewer
attack vectors. In addition, if the server is rooted, the attacker
will be able to pull data out of cookies just as easily as cached
session data, as it can simply be examined at the point of decryption
in the web app. No amount of SSL or app-level encryption will mitigate
this.
I'll repeat what I stated before: authentication data should *never*
be stored in cookies.
--
Ed Finkler
> Sure, an attacker can do whatever they want with the server. But as a
> user of Hahlo I would much prefer highjacking my twitter account not
> be one of them. If the credentials aren't there, they can't do that.
> (unless the intrusion managed to go undetected for an extended period
> of time and they altered the code.)
How exactly do you know they aren't? you can't confirm anything that's
being done with the cookie data on the intermediary's server (in this
case, Hahlo). The data has to be decrypted and sent to Twitter by the
intermediary, and even without some kind of attacker involved, the
data could be stored or mishandled in any number of ways. You've
gained nothing by storing data in the cookie, and made the cookie a
more valuable target for XSS attacks -- which are far more common than
rooted servers.
> The point being, storing personal information (this includes account
> information) is a serious liability that should not be taken lightly.
Agreed.
> Completely true. But security is all about risk mitigation. It's
> simply more risky (by many factors I would claim since it increases
> the attack surfaces so greatly) to have sensitive data stored on a
> server than to just have sensitive data pass through a server.
Well, keep in mind that (unless overridden) the session data in PHP
has a max lifetime on the server of just a few hours, and will get
destroyed even if it is not explicitly erased. That's not failsafe, of
course, but it isn't the quite the same as a permanent store in a DB.
And, that's assuming the server-side app really is passing the data
without recording it in any way. We're still having to trust that the
Right Thing is being done, either way.
> This method is no more vulnerable to XSS attacks than having a cookie
> with a session id. The encrypted cookie is worthless for anything
> except hijacking the session. Let me know if I'm wrong (I certainly
> could be).
I think encrypted data on the client side is more problematic for a
couple reasons:
1. a session ID will expire (typically -- you can obviously set up a
non-expiring session), but the auth data in the cookie will not until
the user changes his or her password.
2. we're relying on the strength of the two-way hash as our *only*
line of defense. I don't like this because a. it assumes a lot about
the strength of the hash and the current state of technology to decode
the hash, and b. attackers have a potentially unlimited amount of time
to work on breaking the hash. My assumption is that, given enough time
and direct access, any 2-way hash can be broken. By storing the data
on the client side, we're dramatically increasing the likelyhood that
they'll have that time and access.
All that being said, I'm very reluctant to use 3rd-party web sites to
post onto Twitter (or access my gmail account, etc.) for the very
reasons we're describing.
Yeah, that is defeated if you keep yourself logged-in. I've moved
mostly to using 1Password for that sort of thing so the login process
isn't as much of a bear, but tons of people want that feature.
> Right, what I left out of my explanation is a timestamp is also stored
> as part of the marshalled data. This is used to limit the lifetime so
> this isn't an issue.
Gotcha. That would definitely help a lot.
> Blowfish with a 197-bit key (what I'm using) has been calculated to
> require the entire energy output of the sun to break. This is what
> the military uses to encrypt stuff. I don't think we need to worry
> about it. :-)
*Probably* not. 8) I like to err on the side of paranoia in these
kinds of things, though.
In the end, the devil's in the details with things like this, and it's
easy to construct hypothetical scenarios where things go horribly
wrong, or things are very secure. A lot of my tendencies come from a
"first-party" web app background, but the use of an intermediary
service complicates the issue.
Ultimately, I think you're limited by only having HTTP Basic Auth
available. It works well for things that connect directly, but doesn't
"scale" well if you start having to pass credentials through an
intermediary. A token-passing system that generated temporary
"tickets" after a single auth check at the centralized server would
likely work better, but we go with what we have for now.
(apologies for drawing this out so long -- sometimes I get a little
more excited than I should be about things like this.)
--
Ed Finkler
We store user passwords as BCrypt hashes in our database, and I'm
confident in that approach.
--
Alex Payne
http://twitter.com/al3x