Skip to content

Commit d9c2cf7

Browse files
authored
session: Remove PS_EXTRA_RAND_BYTES (#10394)
This was introduced in 3467526 and the corresponding RFC gives some reasoning. However the CSPRNG being “not secure enough” is not a thing and reading these extra bytes is just security theater: If the CSPRNG would hypothetically be broken, then PHP’s session IDs are the least of one’s concerns, because we already trust it in `random_bytes()` and might generate long-term secrets using that.
1 parent bf5fdbd commit d9c2cf7

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

ext/session/session.c

+2-5
Original file line numberDiff line numberDiff line change
@@ -306,17 +306,14 @@ static void bin_to_readable(unsigned char *in, size_t inlen, char *out, size_t o
306306
}
307307
/* }}} */
308308

309-
#define PS_EXTRA_RAND_BYTES 60
310-
311309
PHPAPI zend_string *php_session_create_id(PS_CREATE_SID_ARGS) /* {{{ */
312310
{
313-
unsigned char rbuf[PS_MAX_SID_LENGTH + PS_EXTRA_RAND_BYTES];
311+
unsigned char rbuf[PS_MAX_SID_LENGTH];
314312
zend_string *outid;
315313

316314
/* It would be enough to read ceil(sid_length * sid_bits_per_character / 8) bytes here.
317315
* We read sid_length bytes instead for simplicity. */
318-
/* Read additional PS_EXTRA_RAND_BYTES just in case CSPRNG is not safe enough */
319-
if (php_random_bytes_throw(rbuf, PS(sid_length) + PS_EXTRA_RAND_BYTES) == FAILURE) {
316+
if (php_random_bytes_throw(rbuf, PS(sid_length)) == FAILURE) {
320317
return NULL;
321318
}
322319

0 commit comments

Comments
 (0)