From d6ee40e46a6819a87f08f75501d7cbe5880fc1fb Mon Sep 17 00:00:00 2001 From: Jorg Sowa Date: Mon, 23 Nov 2026 13:10:56 +0100 Subject: [PATCH 1/2] ext/session: don't follow symlinked subdirectories in files GC With dirdepth > 0, GC used stat() to descend, so a symlink in save_path made it delete expired sess_* files in the directory it points to. --- NEWS | 2 + ext/session/mod_files.c | 4 +- .../tests/mod_files/gc_dirdepth_symlink.phpt | 39 +++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 ext/session/tests/mod_files/gc_dirdepth_symlink.phpt diff --git a/NEWS b/NEWS index e45546348807..0204cc99f64c 100644 --- a/NEWS +++ b/NEWS @@ -184,6 +184,8 @@ PHP NEWS - Session: . Fixed session upload progress to respect session.use_only_cookies. (jorgsowa) + . Fixed files save handler GC following symlinked subdirectories when + session.save_path sets a directory depth. (Jorg Sowa) - SimpleXML: . Fixed a crash with opcache when simplexml_load_string(), diff --git a/ext/session/mod_files.c b/ext/session/mod_files.c index 15214c215d11..c569584a68d3 100644 --- a/ext/session/mod_files.c +++ b/ext/session/mod_files.c @@ -332,8 +332,8 @@ static int ps_files_cleanup_dir(const zend_string *dirname, zend_long maxlifetim nrdels++; } } else { - /* intermediate depth: recurse into subdirectories */ - if (VCWD_STAT(buf, &sbuf) != 0) { + /* intermediate depth: recurse into subdirectories, never through symlinks */ + if (VCWD_LSTAT(buf, &sbuf) != 0) { continue; } if (S_ISDIR(sbuf.st_mode)) { diff --git a/ext/session/tests/mod_files/gc_dirdepth_symlink.phpt b/ext/session/tests/mod_files/gc_dirdepth_symlink.phpt new file mode 100644 index 000000000000..6a7fbed81d01 --- /dev/null +++ b/ext/session/tests/mod_files/gc_dirdepth_symlink.phpt @@ -0,0 +1,39 @@ +--TEST-- +session GC with save_path dirdepth does not follow symlinked subdirectories +--EXTENSIONS-- +session +--SKIPIF-- + +--INI-- +session.gc_probability=0 +session.use_strict_mode=0 +--FILE-- + +--CLEAN-- + +--EXPECT-- +int(0) +bool(true) From 1b6bdd73290e03aaeaf134115394daee797fc85f Mon Sep 17 00:00:00 2001 From: Jorg Sowa Date: Tue, 24 Nov 2026 22:13:28 +0100 Subject: [PATCH 2/2] Pin gc_maxlifetime and run symlink GC test on Windows --- ext/session/tests/mod_files/gc_dirdepth_symlink.phpt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ext/session/tests/mod_files/gc_dirdepth_symlink.phpt b/ext/session/tests/mod_files/gc_dirdepth_symlink.phpt index 6a7fbed81d01..532bc3b77963 100644 --- a/ext/session/tests/mod_files/gc_dirdepth_symlink.phpt +++ b/ext/session/tests/mod_files/gc_dirdepth_symlink.phpt @@ -5,10 +5,16 @@ session --SKIPIF-- --INI-- session.gc_probability=0 +session.gc_maxlifetime=10 session.use_strict_mode=0 --FILE--