Skip to content

Networks and Sites: Return a 404 from ms-files.php when the file name contains a NUL byte - #16181

Open
AceMedia wants to merge 2 commits into
WordPress:trunkfrom
AceMedia:ticket/php86-ms-files-nul
Open

AceMedia wants to merge 2 commits into
WordPress:trunkfrom
AceMedia:ticket/php86-ms-files-nul

Conversation

@AceMedia

Copy link
Copy Markdown

wp-includes/ms-files.php passes the file query argument to is_file() after only removing ... PHP decodes %00 in a query argument to a NUL byte.

Up to PHP 8.5, is_file() returns false for a path containing a NUL byte, so such a request ends in the existing 404. As of PHP 8.6, is_file() throws a ValueError ("Argument #1 ($filename) must not contain any null bytes"), so the same request ends in an uncaught error and a 500 response.

This returns the existing 404 before the path reaches is_file(), in the same check that [65552] added for a missing or non-string value. Behaviour on PHP 8.5 and earlier is unchanged. It only affects networks that still use ms-files.php.

Testing

I ran the expression ms-files.php builds, with a NUL byte in the file name, on two PHP builds:

is_file()
PHP 8.5.12 Returns false, no warning
PHP 8.6.0 Throws ValueError

I have not run the script end to end on a multisite install. There are no unit tests in this change: the script ends in die(), and [65552] changed the same check without tests. PHPCS passes on the changed file.

Trac ticket: https://core.trac.wordpress.org/ticket/66793

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Used for: Tracing request input into the file functions that throw on NUL bytes as of PHP 8.6, writing the change and this description, and running the check above. The results are automated runs by the tool.

…me contains a NUL byte.

As of PHP 8.6, `is_file()` throws a `ValueError` for a path containing a NUL byte, where earlier versions returned `false`. A request to `ms-files.php` with `%00` in the `file` argument would then end in an uncaught error instead of the existing 404.

This returns the 404 before the path reaches `is_file()`.

Follow-up to [65552].

See #66793.
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props shanerounce.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant