Sending username and password in every request from iPhone app

iphoneSecurityweb services

I'm writing a mobile app & web service combo that requires user to login. The web service will be using SSL, so are there any reasons against sending the user name and password in every web request?

I know some sites generate a token after the user logs in, that they can use for authentication, but the token seems equivalent to the username/password pair – so I'm not sure there's much point in doing that.

Am I about to make a big mistake in terms of security?

Best Answer

The major mistake you are doing is increasing the opportunity to grab that username/password pair. Even the way SSL works, once authentication has been established, you negotiate a session key for the current collaboration.

The session key is a very important concept, as it can help determine what is a valid session or not. Take the following scenario for example:

  • User logs in on one machine, does some stuff and then has to leave it. Stupid him, he forgot to lock the terminal and the session is still active.
  • User then logs in on a second machine, and does some more stuff.
  • Nefarious user stumbles upon the first machine, and tries to do stuff.

If you use the username/password combo for every request the server can't detect which machine is which--particularly if they are behind the same firewall/gateway. Using a session key that is negotiated each time the user logs in the server can detect which session is which. In fact, when it is properly implemented, the old session key is invalidated so that any future requests using that session key fail.

For your session keys make sure that the following apply:

  • It is unique for every username/password combination
  • It is unique for each authenticated session
  • Old session keys are invalidated and no longer used. (recycling is only OK when the client session mechanisms will fail anyway. I.e. the cookie expires and the server session expires).

This allows a user to move from one machine to another (logging in fresh on each machine), while doing your diligence to prevent someone stealing their session.

Related Topic