[php-src] PR #21808: phar: reject extractTo() when destination parent escapes via symlink
| From: | iliaal | Date: | Sat, 18 Apr 2026 19:10:26 +0000 |
| Subject: | [php-src] PR #21808: phar: reject extractTo() when destination parent escapes via symlink | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-35784@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/21808
Author: iliaal
Fixes destination-side symlink traversal in
Phar::extractTo().
extractTo() builds the target path as dest + "/" + entry_path.
CWD_EXPAND validates the entry path against .. traversal but doesn't
resolve symlinks. A pre-existing symlink in the destination (e.g., /dest/subdir ->
/etc) causes the extracted file to land outside the intended root.
After creating the parent directory, resolve it with VCWD_REALPATH and verify it stays
under dest. Return FAILURE if it escapes so the caller throws a
PharException.
The test skips on Windows only when SeCreateSymbolicLinkPrivilege is absent. Without
it, symlink() returns false without error, so no symlink exists in the destination,
extractTo() succeeds, and the test outputs EXTRACTED (unexpected) instead
of the PharException that --EXPECTF-- requires.