I will try to analyze your options:
If the server is hacked using CustomMemoryStore
Consider the following scenario:
- 4 Users A, B, C, D are logged in.
- Your server is hacked. Hacker takes control of the server.
- D did some surgery.
- You have discovered that your server has been hacked and restored your system.
Using CustomMemoryStore, a hacker can receive passwords for all users. Its not too difficult to introduce some logic into the Rails process, or dump memory and analysis. Saving a password in ActiveRecord, MongoDB, Redis has a similar problem.
If the server is hacked CookieStore?
What if the previous script occurs and you use CookieStore?
Let's look at the cookiestore mechanism:
- The server has a secret key for signing and verifying the session.
- Each time the browser sends a request, the server decrypts the session, modifies the data, signs the session, and sends the session to the browser in a cookie.
In other words, a hacker cannot obtain a password from a cookie or from a private key. He needs both a cookie and a secret key to steal a password.
In this case, passwords A, B, C are safe. The hacker will be stolen only Ds password. You can minimize damage by repairing the system as soon as possible.
CustomMemoryStore Problem
Besides the security issue, I know that you know that CustomMemoryStore does not scale. However, the problem may be more than you think. You will send a request for other web services to your controller, it will block your entire server if the remote service is slow or down. This can be painful even if you only have 1 ~ 10 single-user users.
Even if you decide to run the application on one server, you can run several rails using Passenger or Unicorn. CustomMemoryStore negates these options.
Customer Security Advice
If the problem is that the cookie is stolen by the browser, you can consider EncryptedCookieStore . It encrypts the session and stores it in the client cookie. You cannot get a password if you only have a cookie or key. You need both a cookie and a password decryption key.
What is the main problem?
EncryptedCookieStore is more secure because it stores the encrypted password in the cookie of users, and the secret key is available only on the server. A hacker cannot get a password if he only has a cookie or secret key. He needs both.
Of course, you can implement similar logic using CustomMemoryStore. For example, store the encrypted password in the serverโs memory, and a separate key is in the cookie. If you still decide to keep the encrypted password on the server, I recommend using Redis for storage. It is simple and fast compared to MySQL and MongoDB. CustomMemoryStore is not offered due to scaling issue.
Other offers
The password of another system is very sensitive data, you must be very careful in solving the security problem. If this is a public service, you must write the service agreement and disclaimer very carefully. In addition, you must start your services using HTTPS.
TL DR
- Use OAuth if you can (well, I know you can't)
- EncryptedCookieStore should be simple and secure.
- If you decide to save the password on the server, encrypt it and save the secret key on the client side (cookie).