Skip to content

ext/session: don't follow symlinked subdirectories in files GC - #25671

Closed
jorgsowa wants to merge 2 commits into
php:PHP-8.6from
jorgsowa:session-gc-no-follow-symlinks
Closed

jorgsowa wants to merge 2 commits into
php:PHP-8.6from
jorgsowa:session-gc-no-follow-symlinks

Conversation

@jorgsowa

Copy link
Copy Markdown
Contributor

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.

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.
@jorgsowa jorgsowa self-assigned this Nov 23, 2026
@jorgsowa
jorgsowa requested a review from Girgias as a code owner November 23, 2026 12:52

@iliaal iliaal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks right

if (PHP_OS_FAMILY === 'Windows') die('skip not for Windows');
?>
--INI--
session.gc_probability=0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you pin session.gc_maxlifetime=10 here? At 3600, the 2,000-second-old file survives even if GC follows the symlink.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in new commit

--SKIPIF--
<?php
include(__DIR__ . '/../skipif.inc');
if (PHP_OS_FAMILY === 'Windows') die('skip not for Windows');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we run this on Windows when the runner can create directory symlinks? The cleanup would need rmdir() for the directory symlink on Windows.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can, but the skip session is ugly. Would be nice to organize it properly, because skip functio is already present in standard/tests/file/windows_links/common.inc. But I think it's for another PR to clean it up.

@jorgsowa jorgsowa closed this in d09481d Nov 25, 2026
arnaud-lb added a commit to mihaliak/php-src that referenced this pull request Nov 25, 2026
* PHP-8.6:
  Fix float literals losing precision in AST export (phpGH-25461)
  ext/session: don't follow symlinked subdirectories in files GC (phpGH-25671)
arnaud-lb added a commit to prateekbhujel/php-src that referenced this pull request Nov 25, 2026
* PHP-8.6: (92 commits)
  Fix arrow functions not capturing variables in partial application args (php#25732)
  Fix float literals losing precision in AST export (phpGH-25461)
  ext/session: don't follow symlinked subdirectories in files GC (phpGH-25671)
  [skip ci] Skip automatic_worker_limit.phpt on few cores
  [skip ci] Fix Symfony test without USE_TRACKED_ALLOC
  [skip ci] Skip assign_dim_undef_op_data_008.phpt when JIT is unavailable
  ext/intl: Preserve the previous MessageFormatter pattern on failure (php#25642)
  Fix phpGH-25313: Assertion !EG(exception) in ZEND_FE_FREE when unpacking a generator into a by-ref parameter throws
  ext/opcache: Fix JIT register allocation for ASSIGN to traced reference
  Fix phpGH-25650: PDO::query() reports wrong argument numbers for ctor args
  Fix tracing JIT taking the wrong branch after a VM interrupt (php#25636)
  [skip ci] Add APP_DEBUG=0 for Symfony Preloading test
  streams: fix stale readbuflen after stream_filter_remove() on a read filter
  Update NEWS for phpGH-20920 LibreSSL build fix
  Fix phpGH-20920: do not use OPENSSL_strndup() for peer CN matching
  Simplify php_openssl_load_all_certs_from_file()
  Fix phpGH-20920: only register PKCS7_NO_DUAL_CONTENT when it is defined
  Fix phpGH-20920: guard ENGINE_cleanup() with OPENSSL_NO_ENGINE again
  ext/soap: Fix NULL dereference on empty Body with matching SOAPAction (phpGH-25661)
  ext/dom: Fix use-after-free in getElementById() after removing an ID attribute
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants