Commit graph

987 commits

Author SHA1 Message Date
Christoph M. Becker
217ea732fc
Use php_error_docref() instead of zend_error() in session.c (GH-15505)
Using `php_error_docref()` is preferable since it outputs additional
details (which function has been called and whether it is a startup or
shutdown error), uses HTML markup, and also provides a link to the
documentation, if configured.

Since these deprecation warnings have been introduced recently[1][2],
i.e. for PHP 8.4, there are no BC concerns.

[1] <e8ff7c70f9>
[2] <b36eac94d2>

Co-authored-by: Máté Kocsis <kocsismate90@gmail.com>
2024-09-04 16:00:28 +02:00
Kamil Tekiela
c5bce0d8a2
Deprecate disabling use_only_cookies (#13578) 2024-08-24 16:33:45 +02:00
Jorg Adam Sowa
ff69f334f1
ext/session: Warn when providing invalid values for session.gc_probability and session.gc_divisor 2024-08-22 01:29:40 +01:00
Jorg Adam Sowa
21fa5e15f9
ext/session: session_create_id() now throws a ValueError for large prefix (#15338) 2024-08-15 11:10:18 +01:00
Jorg Adam Sowa
6bf7b7220d
ValueError on null byte in session_name() (#15286) 2024-08-11 13:26:54 +01:00
Tim Düsterhus
e8ff7c70f9
session: Deprecate session.sid_length and session.sid_bits_per_character (#15213)
RFC: https://wiki.php.net/rfc/deprecations_php_8_4
2024-08-04 18:25:31 +02:00
Levi Morrison
9d25296723
Merge branch 'PHP-8.3' 2024-07-23 16:34:16 -06:00
Levi Morrison
e43d9c7469
Merge branch 'PHP-8.2' into PHP-8.3 2024-07-23 16:33:40 -06:00
Levi Morrison
0956267c08
Fix warnings in session/spl
This fixes -Winline errors where the functions are not ever inlined.

Also fixes some signature mismatches which were fixed previously but
for whatever reason were not ported to all maintained branches:

/usr/local/src/php/ext/session/session.c:1299:20:
warning:conflicting types for 'php_session_send_cookie' due to enum/integer mismatch;
have 'zend_result(void)' {aka 'ZEND_RESULT_CODE(void)'} [-Wenum-int-mismatch]
 1299 | static zend_result php_session_send_cookie(void) /* {{{ */
      |                    ^~~~~~~~~~~~~~~~~~~~~~~
/usr/local/src/php/ext/session/session.c💯12:
note: previous declaration of 'php_session_send_cookie' with type 'int(void)'
  100 | static int php_session_send_cookie(void);
      |            ^~~~~~~~~~~~~~~~~~~~~~~
2024-07-23 16:25:11 -06:00
Jorg Adam Sowa
8e1561cdbe
Check session_create_id() input for null byte (#14728) 2024-07-06 21:18:35 +01:00
Arnaud Le Blanc
11accb5cdf
Preferably include from build dir (#13516)
* Include from build dir first

This fixes out of tree builds by ensuring that configure artifacts are included
from the build dir.

Before, out of tree builds would preferably include files from the src dir, as
the include path was defined as follows (ignoring includes from ext/ and sapi/) :

    -I$(top_builddir)/main
    -I$(top_srcdir)
    -I$(top_builddir)/TSRM
    -I$(top_builddir)/Zend
    -I$(top_srcdir)/main
    -I$(top_srcdir)/Zend
    -I$(top_srcdir)/TSRM
    -I$(top_builddir)/

As a result, an out of tree build would include configure artifacts such as
`main/php_config.h` from the src dir.

After this change, the include path is defined as follows:

    -I$(top_builddir)/main
    -I$(top_builddir)
    -I$(top_srcdir)/main
    -I$(top_srcdir)
    -I$(top_builddir)/TSRM
    -I$(top_builddir)/Zend
    -I$(top_srcdir)/Zend
    -I$(top_srcdir)/TSRM

* Fix extension include path for out of tree builds

* Include config.h with the brackets form

`#include "config.h"` searches in the directory containing the including-file
before any other include path. This can include the wrong config.h when building
out of tree and a config.h exists in the source tree.

Using `#include <config.h>` uses exclusively the include path, and gives
priority to the build dir.
2024-06-26 00:26:43 +02:00
Gina Peter Banyard
fd2d869642
Clean-up some more headers (#14416)
Remove unused headers (such as php_ini.h for extensions that don't define INI settings)
Use more specific headers when possible
2024-06-08 17:15:36 +01:00
Peter Kokot
ec50b178f1
Update ext/session spl dependency (#14410)
The spl dependency is configured so the spl_autoload_register is
available when session_start() is used, meaning the spl extension needs
to be loaded before the session. It is marked as optional to be more
explicit as spl is not directly used nor required in the session
extension.
2024-06-01 19:13:54 +02:00
Peter Kokot
f69c55b5b6
Remove hash dependency from session extension (#14409)
The session extension once depended on the hash extension for having
hash functions available when using the `session.hash_function` INI
directive. This directive was removed in PHP-7.1 via
3467526a65. At the time it could be marked
as optional dependency, because it only needed to be loaded before the
session in that case.

The removed ext/hash/php_hash.h in the ext/session/php_session.h might
cause BC break for PHP extensions if they rely on transitive include and
use hash extension in the code without explicitly including the
ext/hash/php_hash.h header. Solution is to include the
ext/hash/php_hash.h separately.
2024-06-01 17:06:17 +01:00
Niels Dossche
c7797fc8c0
Fix bug GH-11941: soap with session persistence will silently fails when "seession" built as a shared object (#14362)
This adds an optional dependency on the session extension and adds the
necessary APIs to make the functionality work with lazy binding.

This can be tested by configuring PHP with `--enable-session=shared` and
`--enable-soap=shared` and running the test suite, in particular the
buggy behaviour can be observed by the existing test `server009.phpt`.
2024-05-29 19:51:49 +02:00
Jorg Adam Sowa
f69d540541
Removed impossible paths from session_decode and session_encode (#13796) 2024-03-24 20:20:42 +01:00
Tim Düsterhus
81744d6cf7
random: Improve the output quality of RANDOM_SEED() (#13730)
* random: Improve the output quality of RANDOM_SEED()

Previously 4 consecutive calls to `RANDOM_SEED()` each for 4 different CLI
requests resulted in:

    $ sapi/cli/php test.php
    2c13e9fde9caa
    2c13e9fd1d6b0
    2c13e9fd4de34
    2c13e9fd1610e
    $ sapi/cli/php test.php
    2c1436764fe07
    2c14367621770
    2c143676c0bf6
    2c143676e02f5
    $ sapi/cli/php test.php
    2c144995a0626
    2c14499590fe2
    2c144995c65db
    2c14499536833
    $ sapi/cli/php test.php
    2c145cb30860b
    2c145cb3ec027
    2c145cb33b4ca
    2c145cb38ff63

Now they result in:

    $ sapi/cli/php test.php
    6796973ace1b5f3d
    1913daf5c158cb4b
    255dbf24237bc8c9
    7c3ba22e60f35196
    $ sapi/cli/php test.php
    afb7cc9ba9819cd2
    3e01a71b91ad020c
    6b718364d3ef108
    bdcd17beeb4b31d2
    $ sapi/cli/php test.php
    53d36eb9b83f8788
    4381c85e816187aa
    2e9b32ee9898e71e
    31d15c946842bddb
    $ sapi/cli/php test.php
    2037a3cba88114b4
    ba0b0d93a9bb43aa
    e13d82d2421269e2
    191de474f3292240

* tree-wide: Replace GENERATE_SEED() by php_random_generate_fallback_seed()

* random: Fix NTS build

* random: Fix Windows build
2024-03-18 16:08:23 +01:00
Niels Dossche
8793f9938b Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-13680: Segfault with session_decode and compilation error
2024-03-13 17:59:43 +01:00
Niels Dossche
b58dc6fd1a Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-13680: Segfault with session_decode and compilation error
2024-03-13 17:49:31 +01:00
Niels Dossche
6985aff7c3 Fix GH-13680: Segfault with session_decode and compilation error
It's illegal to return from a bailout because that doesn't restore the
original bailout data. Return outside of it.

Test by YuanchengJiang

Closes GH-13689.
2024-03-13 17:47:25 +01:00
Tim Düsterhus
f6c38fc952 session: Stop using php_combined_lcg()
The CombinedLCG is a terrible RNG with a questionable API and should ideally
not be used anymore. While in the case of ext/session it is only used for
probabilistic garbage collection where the quality of the RNG is not of
particular importance, there are better choices.

Replace the RNG used for garbage collection by an ext/session specific instance
of PcgOneseq128XslRr64. Its 16 Byte state nicely fits into the memory freed up
by the previous reordering of the session globals struct, even allowing to the
storage of the php_random_algo_with_state struct, making using the RNG a little
nicer.

Instead multiplying the float returned by the CombinedLCG by the GC Divisor to
obtain an integer between 0 and the divisor we can just use `php_random_range`
to directly generate an appropriate integer, completely avoiding the floating
point maths, making it easier to verify the code for correctness.
2024-03-02 11:29:15 +00:00
Tim Düsterhus
97b3b4552d
random: Move CSPRNG API into php_random_csprng.h (#13290)
This allows consumers of just the CSPRNG to include a much smaller header. It
also allows to verify at a glance whether a source file might use non-secure
randomness.

This commit includes the new header wherever the CSPRNG is used, possibly
replacing the inclusion of php_random.h if nothing else is used, but also
includes it in the main php_random.h header for compatibility.

Somewhat related to 45f8cfaf10,
2b30f18708, and
b14dd85dca.
2024-02-01 19:09:35 +01:00
Niels Dossche
2c4534a5b9 Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-12504: Corrupted session written when there's a fatal error in autoloader
2024-01-22 22:04:20 +01:00
Niels Dossche
d50393e242 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-12504: Corrupted session written when there's a fatal error in autoloader
2024-01-22 22:02:28 +01:00
Niels Dossche
7f7031eb72 Fix GH-12504: Corrupted session written when there's a fatal error in autoloader
For details and reasoning, see [1] and following.

[1] https://github.com/php/php-src/issues/12504#issuecomment-1790870399

Closes GH-13207.
2024-01-22 21:59:11 +01:00
Máté Kocsis
b36eac94d2 Deprecate calling session_set_save_handler() with more than 2 arguments 2023-12-04 22:35:30 +01:00
nielsdos
c0147a0588 Fix GH-11529: Crash after dealing with an Apache request
In an MPM worker scenario we have 1 module, N threads. Each thread must
have their globals initialised. If we only initialise the filename
fields in MINIT, then the threads have an uninitialized value. If the
uninitialized value is not NULL, this leads to segfaults upon access.

Closes GH-11530.
2023-06-26 19:43:56 +02:00
Ilija Tovilo
2b3dbe0054
Merge branch 'PHP-8.2'
* PHP-8.2:
  Remove session ID set through REQUEST_URI
2023-06-22 12:36:58 +02:00
Ilija Tovilo
1441f30a8d
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Remove session ID set through REQUEST_URI
2023-06-22 12:36:52 +02:00
Ilija Tovilo
f160eff441
Remove session ID set through REQUEST_URI 2023-06-22 12:35:55 +02:00
George Peter Banyard
d5ad75108e
More usage of known zend_str instead of C string (#11381) 2023-06-08 13:03:29 +01:00
Ilija Tovilo
6f63d4b274
Fix -Wenum-int-mismatch warnings on gcc 13
Closes GH-11103
2023-04-20 16:04:59 +02:00
Calvin Buckley
180f785404
Note where a session was already started (#10736)
* Note where a session was already started

Duplicated session starts can be annoying to debug. The error that
occurs when a session is already active doesn't tell you where it
was initialized, so figuring out the callsite involves manual
debugging to find it out.

This keeps track of the call site of session_start as a request
global, and frees at the end of the request. It should make it
easier to find these instances for PHP users.

The resulting message can look like:
Notice: session_start(): Ignoring session_start() because a session is already active (started from /home/calvin/src/php-src/inc.php on line 4) in /home/calvin/src/php-src/index.php on line 9

Fixes GH-10721

* Convert to using zend_string for session start location

* Fix leak with session start callsite filename

If this was already initialized, we'd forget it. Have shared free
between session_start and RSHUTDOWN.

* For sessions that are automatically started, note that

Easy to forget that you have this set, in which case, session start
is done at RINIT outside of user code. Because this config option
can't change at runtime, we can check for it and make the error
more specific if that's the case.
2023-03-28 15:14:21 +01:00
Ilija Tovilo
9d5f2f1343
Use new ZSTR_INIT_LITERAL macro (#10879) 2023-03-20 16:19:05 +01:00
Niels Dossche
4177257178
3 minor cleanups in ext/session (#10722)
* sid can never be NULL because it was NULL-checked earlier

* Change namelen to size_t because it is always unsigned and less in size than size_t

* Remove redundant check on ser

It can't be NULL, and even if it could, the ser++ would be UB.
2023-02-28 12:29:40 +01:00
Tim Düsterhus
d9c2cf7e3d
session: Remove PS_EXTRA_RAND_BYTES (#10394)
This was introduced in 3467526a65 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.
2023-01-23 14:42:32 +01:00
Máté Kocsis
7936c8085e
Fix GH-8329 Print true/false instead of bool in error and debug messages (#8385) 2023-01-23 10:52:14 +01:00
David Carlier
da47547809 Merge branch 'PHP-8.2' 2022-11-15 12:31:33 +00:00
David Carlier
65782fbbe8 Merge branch 'PHP-8.1' into PHP-8.2 2022-11-15 12:30:04 +00:00
David Carlier
a4298c14c1 Fix GH-9932: Discards further characters for session name.
As those are converted, it s better to make aware of the code caller of the naming inadequacy.
Closes GH-9940.
2022-11-15 12:27:44 +00:00
George Peter Banyard
51888425da Drop struct union as access is now always named 2022-10-22 12:47:34 +01:00
George Peter Banyard
2ddd68aa20 Free handles by name directly 2022-10-22 12:47:34 +01:00
George Peter Banyard
5b40d06680 Refactor session_set_save_handler()
Use proper ZPP callables with FCI/FCC
2022-10-22 12:47:34 +01:00
George Peter Banyard
7d5ce1c483
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Actually fix GH-9583
2022-10-06 14:31:29 +01:00
George Peter Banyard
09a57d385d
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Actually fix GH-9583
2022-10-06 14:29:53 +01:00
George Peter Banyard
499fbcd679
Actually fix GH-9583
The issue is that PS(mod)->s_validate_sid is always defined for user modules, thus we need to check that the actual callable is set
Add another regression test to ensure current working behaviour is not broken (which was by the previous incorrect fix)

Closes GH-9638
2022-10-06 14:29:13 +01:00
George Peter Banyard
3579ddaace
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-9583: session_create_id() fails with user defined save handler that doesn't have a validateId() method
2022-09-27 15:58:30 +01:00
George Peter Banyard
72cb47338e
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix GH-9583: session_create_id() fails with user defined save handler that doesn't have a validateId() method
2022-09-27 15:54:37 +01:00
George Peter Banyard
8b115254c0
Fix GH-9583: session_create_id() fails with user defined save handler that doesn't have a validateId() method 2022-09-27 15:52:21 +01:00
Ilija Tovilo
3071d85a6b
PS(mod_user_class_name) must not leak into next request
Fixes GH-9584
2022-09-22 11:37:37 +02:00