Skip to content

Commit 27b27ef

Browse files
committed
adding design stateless session
1 parent 0d74fd8 commit 27b27ef

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Problem Solving
22

3+
[![Analytics](https://ga-beacon.appspot.com/UA-1187941-16/ps)](https://github.com/sangupta/ps)
4+
35
`ps` is a collection of various computing problems and their corresponding solutions
46
that I could think of. The problems range in various categories such as design,
57
algorithms, performance optimizations, and more.
@@ -30,7 +32,7 @@ The following is a list of the various problems and their solutions:
3032
* [Find degrees of separation in a social graph](https://github.com/sangupta/ps/blob/master/solutions/2016/degrees-of-separation-social-graph.md)
3133
* Design a scalable user authentication system
3234
* Design a rate-limited web-scraper
33-
* Design a stateless user-session mechanism
35+
* [Design a stateless user-session mechanism](https://github.com/sangupta/ps/blob/master/solutions/2016/stateless-user-session.md)
3436

3537
### Others
3638

@@ -64,5 +66,3 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
6466
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
6567
SOFTWARE.
6668
```
67-
68-
[![Analytics](https://ga-beacon.appspot.com/UA-1187941-16/ps)](https://github.com/sangupta/ps)

solutions/2016/stateless-user-session.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,31 @@ token before using the same information. As checking HMAC signature is inexpensi
9898
it does not slow down the request processing. A malicious user trying to fudge the
9999
request will not be able to generate the same signature (due to missing signing
100100
key).
101+
102+
Before you think that the above token can be brute forced, consider that someone
103+
was able to generate a concatenated token that passes the sigining key check. But
104+
the same brute forced string also representing a valid JSON in the first part, and
105+
containing valid user details is too high a coincidence.
106+
107+
### Prevent session hijacking
108+
109+
Apart from usual security measures like usage of SSL, generating a very-long session
110+
key, the following are the few key things to prevent session hijacking:
111+
112+
* Store the IP of the incoming request when the JSON token is created first. For
113+
every subsequent request, check that the IP of the next request is the same IP as
114+
mentioned in the JSON token. However, do note that this may break users accessing
115+
your service over the [TOR](https://www.torproject.org/) network. Also, this may
116+
not prevent malicious users using the same egress IP or on the same network.
117+
118+
* An alternate mechanism to bind the request to the IP, is to bind the request to
119+
a [browser fingerprint](https://en.wikipedia.org/wiki/Device_fingerprint). This
120+
makes it difficult for a malicious user to have the exact same browser, machine and plugin
121+
configuration as the host, to have the same browser fingerprint being generated.
122+
123+
* Using a [nonce](https://en.wikipedia.org/wiki/Cryptographic_nonce) token with
124+
every request and changing that on server side with every subsequent request. This
125+
ensures that the malicious user has a very small window to align himself with the
126+
server. This will invalidate the session of the actual user immediately, which would
127+
force him/her to sign-in again. Thus, effectively invalidating the malicious user
128+
session.

0 commit comments

Comments
 (0)