Today I implemented a session/token authentication system for my web api (http get/post rpc style), following this plan:
legend: action (param1, param2) : returnvalue1, returnvalue2
- login (username, password) : sessionkey, token
- requestA (sessionkey, token, paramA) : token
- requestB (sessionkey, token, paramB) : token
- logout (sessionkey, token) : void
The login action is sent over https, to protect the users data. You get a session/token combination, where one token is only valid for one request (you will always receive a new token on normal requests). My thoughts behind this were about reducing the risk for a man-in-the-middle attack, sniffing your session key: if you are "lucky", the sniffed token has already been invalidated through your own subsequent request.
My backend and its unittests are perfectly fine, but i didn't think far enough - i finally ran into issues with asynchronous ajax calls, which defeat this one-time-token idea.
Is the added security worth not being able to process asynchronous requests?
One idea was to introduce a request-queue inside my ajax application - did someone do anything like that, and would you recommend it?
A probably less secure, but more convenient way would imho be not to renew the token for every request - allowing asynchronous processing, but keeping the initial https auth and add a strict lifetime to a session. I should also save the IP to the session server-side.
Did i miss other valuable options?
I am bound to existing username/password values, which with no exception have to work without changes with the new ajax app.