You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For years, the C session handler bundled with [phpredis](https://github.com/phpredis/phpredis) has been suffering
37
-
from a couple of bugs that I care about, namely the [lack of per-session locking](https://github.com/phpredis/phpredis/issues/37) and the [impossibility to run it in "strict" mode](https://github.com/phpredis/phpredis/issues/37).
36
+
The Redis session handler bundled with [phpredis](https://github.com/phpredis/phpredis) has had a couple of rather serious
37
+
bugs for years, namely the [lack of per-session locking](https://github.com/phpredis/phpredis/issues/37) and the [impossibility to protect against session fixation attacks](https://github.com/phpredis/phpredis/issues/37).
38
+
39
+
This package provides a session handler built on top of the Redis extension that is not affected by these issues.
38
40
39
41
40
42
### Session Locking explained
41
43
44
+
In the context of PHP, "session locking" means that when multiple requests with the same session ID hit the server roughly
45
+
at the same time, only one gets to run while the others get stuck waiting inside `session_start()`. Only when that first request
46
+
calls [`session_write_close()`](http://php.net/manual/en/function.session-write-close.php), one of the others can move on.
47
+
48
+
When a session handler does not implement session locking concurrency bugs might start to surface under
49
+
heavy traffic. I'll demonstrate the problem using the default phpredis handler and this simple script:
50
+
42
51
```
43
52
<?php
44
53
45
-
// test-project/web/visit-counter.php
54
+
// a script that returns the total number of
55
+
// requests made during a given session's lifecycle.
46
56
47
57
session_start();
48
58
@@ -55,7 +65,10 @@ $_SESSION['visits']++;
55
65
echo $_SESSION['visits'];
56
66
```
57
67
58
-
```
68
+
First, we send a single request that will setup a new session. Then we use the session ID returned in
69
+
the `Set-Cookie` header to send a burst of 200 concurrent, authenticated requests.
RedisSessionHandler solves this problem with a "lock" entry for every session that only one thread of execution can create at a time.
106
126
107
-
### Session Strict Mode explained
108
127
109
-
```
128
+
### Session fixation explained
129
+
130
+
[Session fixation](https://www.owasp.org/index.php/Session_fixation) is the ability to choose your own session ID as an HTTP client. When clients are allowed to choose their
131
+
session IDs, a malicious attacker might be able to trick other users into using an ID already known to him, then let them log in and hijack their session.
132
+
133
+
Starting from PHP 5.5.2, there's an INI directive called [`session.use_strict_mode`](http://php.net/manual/en/session.configuration.php#ini.session.use-strict-mode) to protect
134
+
PHP applications against such attacks. When "strict mode" is enabled and a random session ID is received, PHP should ignore it and generate a new
135
+
one, just as if it was not there at all. Unfortunately the phpredis handler ignores that directive and always trust whatever session ID is received from
0 commit comments