If you have security issues, they are not unique to ajax, but there are simple ways to make things more difficult to communicate with.
1) As Diodeus says - absolutely do not let people use your services without authentication through the session. Same as any other page on a website that requires you to be logged in.
2) Strengthen session capture by inserting client information into the session key (cookie) and checking it on the server, for example. IP address, browser version. However, it can be faked.
3) If a particular session makes more than x requests in a certain period of time (for example, 10 per minute), log out and block them for an hour. Set a higher limit to prevent them from being restored by the administrator. Ask the code to send yourself an email when this happens so you know if you have a problem.
4) If you are really worried, use SSL. This is really the only way to completely prevent session hijacking (apart from introducing your own private key encryption mechanism for session data).
5) If you do not use SSL, you cannot stop the possibility of capturing a session, but you can easily protect your user passwords from unauthorized access. For authentication, do the following:
- Client script requests salt from server (random string)
- The server sends salt to the client and remembers it using a session
- The client hashes the password using Sha-256 , for example, with salt, and authenticates with their username and hashed password. The server hash password associated with the user at its own end using the same salt is authenticated if it matches the hash sent by the client. The server forgets that he used it once.
This way, someone watching the session can only see the hashed password, and since the hash is different every time, they cannot log back in using this hash against your service. You still cannot stop them from capturing a session, but you can stop them from viewing your users passwords or the ability to log in on their own.
In fact, capturing a session is not so important, although a full implementation is, of course, facebook via Wi-Fi. If someone comes out with a Firefox plugin to hack your social network, then you should be thrilled because you know you did it.