Skip to content

Fix GH-25093: Phar::webPhar() redirect reads past the request URI - #25102

Closed
lazerg wants to merge 2 commits into
php:PHP-8.4from
lazerg:fix/gh-25093-webphar-redirect-oob
Closed

lazerg wants to merge 2 commits into
php:PHP-8.4from
lazerg:fix/gh-25093-webphar-redirect-oob

Conversation

@lazerg

@lazerg lazerg commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

On non-CGI SAPIs the 301 redirect for a direct request cut the request URI at strstr(path_info, basename) + fname_len, but fname_len is the length of the full phar path, not of its basename. That pointer lands past the end of the URI (or in the wrong place when a rewrite callback returns /), so it now advances by the basename length like the code that builds pt already does.

Fixes #25093

@ndossche ndossche 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.

Thanks

@dhrupo

dhrupo commented Nov 2, 2026

Copy link
Copy Markdown

Independent confirmation that this fixes GH-25093. Built PHP-8.4 (base 7091e5b), added the test, and ran it unpatched vs. with this change.

Base (unpatched) — FAIL, the redirect keeps the request path that was written past the file name:

Location: /gh25093.phar/aaaaaaaa…/index.php

With the fix (+ (fname_len - (basename - fname))) — PASS:

Location: /gh25093.phar/index.php

That matches the report: the terminator advanced by the full on-disk fname_len instead of the basename length, so the redirect target ran past the request URI.

Full suites on the patched build (NTS, --disable-all --enable-cli --enable-phar):

  • ext/phar/tests: 469 passed, 0 failed (112 skipped)
  • sapi/cli/tests: 98 passed, 0 failed (19 skipped)

Drafted with an LLM; I ran and verified the commands myself.

@LamentXU123 LamentXU123 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.

Thank you.

opensource-fork-sync Bot pushed a commit to cla7aye15I4nd/opensource-php__php-src that referenced this pull request Nov 2, 2026
* PHP-8.4:
  Fix phpGH-25093: Phar::webPhar() redirect reads past the request URI (php#25102)
arnaud-lb added a commit to marc-mabe/php-src that referenced this pull request Nov 2, 2026
* PHP-8.6: (158 commits)
  Fix ZEND_LONG_UINT_OVFL() accepting negative values on 32-bit platforms (php#24778)
  Don't use static closure cache when called_scope diverges
  ext/com_dotnet: Fix phpGH-25008 event source typelib crash
  Fix phpGH-25093: Phar::webPhar() redirect reads past the request URI (php#25102)
  Fix the WSAPoll backend of Io\Poll accepting handles that are not sockets
  Fix phpGH-25086: Io\Poll kqueue backend leaks memory on every modifyEvents() (php#25087)
  openssl: Fix heap buffer overflow in TLS PSK callbacks
  openssl: Fix use-after-free in TLS session remove callback
  [`%pS` migration] Use `%pS` in ext/standard/var.c
  [`%pS` migration] Use `%pS` in ext/standard/var_unserializer.re
  [`%pS` migration] Use `%pS` in ext/standard/string.c
  [`%pS` migration] Use `%pS` in ext/standard/streamsfuncs.c
  [`%pS` migration] Use `%pS` in ext/standard/proc_open.c
  [`%pS` migration] Use `%pS` in ext/standard/mail.c
  [`%pS` migration] Use `%pS` in ext/standard/info.c
  [`%pS` migration] Use `%pS` in ext/standard/http.c
  [`%pS` migration] Use `%pS` in ext/standard/http_fopen_wrapper.c
  [`%pS` migration] Use `%pS` in ext/standard/head.c
  [`%pS` migration] Use `%pS` in ext/standard/ftp_fopen_wrapper.c
  [`%pS` migration] Use `%pS` in ext/standard/fsock.c
  ...
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.

4 participants