Client side sessions

后端 未结 6 1518
灰色年华
灰色年华 2020-12-17 00:32

I want the clients of several related web apps to hold their own authentication state. This improves scalability, because no session replication between cluster nodes is nee

相关标签:
6条回答
  • 2020-12-17 01:09

    I disagree with the posters saying this approach is not secure. Variants of it are used in a number of well respected frameworks, such as Rails and Play!, for precisely the reasons you outline, and it's perfectly secure when implemented correctly.

    0 讨论(0)
  • 2020-12-17 01:10

    As Pekka said, not a good idea. One can intercept your cookie with sensitive session data. Even with SSL, by using fiddler2 one can decrypt the traffic

    0 讨论(0)
  • 2020-12-17 01:13

    Not a good idea. Storing vital data like session expiry and user name entirely on client side is too dangerous IMO, encrypted or not. Even if the concept is technically safe in itself (I can't answer that in depth, I'm no encryption expert), a break-in could be facilitated without compromising your server, just by acquiring your encryption key.

    Somebody who gets hold of the key could generate session cookies at will, impersonating any user for any length of time, something the classical session concept is designed to prevent.

    There are better and scalable solutions for this problem. Why not, for instance, set up a central session verification instance that all associated servers and services can poll? Look around on the web, I am 100% sure there are ready-made solutions addressing your needs.

    0 讨论(0)
  • 2020-12-17 01:15

    You can avoid duplication of data in a clustered environment by using a state server - a server that is well known by all the nodes in the clusters and maintains the session data for all the users. Every time a user performs a request, it send a cookie with session id to the applications server; this one should retrieve the session from the state server. This is possible for asp.net development, but I'm not sure how easy Java supports this approach.

    0 讨论(0)
  • 2020-12-17 01:26

    This improves scalability, because no session replication between cluster nodes is needed.

    First, using HTTP Session doesn't really prevent you from scaling, even when using HTTP Session State replication (some mechanisms are smarter than others by the way, for example WebLogic's in-memory replication doesn't have a big overhead). Second, do you really need it? Most applications (the majority) don't need Session replication. Third, am I understanding right: do you plan to not use HTTP Session at all?

    (...) Set a signed and encrypted cookie with the user name and session expiration time after client authentication.

    Don't do this! Don't store a username and other sensible data used by the server in a cookie, this is a very bad idea! You actually need to admit that it's just a matter of time before someone figures out how your system works and breaks it (especially if your cookie is candidate for crib attacks). Sor, really, you should store data in the Session on the server-side and only an ID in the cookie, like things are actually working. This is much more secure.

    Is this approach ok?

    No. And you don't need this for interoperable single-sign on (if this is what you are trying to build). Just use a centralized authentication solution like CASJasig which has libraries for various technologies.

    0 讨论(0)
  • 2020-12-17 01:26

    This is not really how Sessions are implemented. The cookie itself doesn't need to carry any data of the session itself, it's just a reference to it.

    What the Cookie holds is usually a Session ID which is then linked to the data on the server.

    If you don't have a central data session server for the other servers to access, I suggest to get one :).

    0 讨论(0)
提交回复
热议问题