Make WordPress Core

Opened 8 weeks ago

Last modified 3 weeks ago

#66148 new enhancement

Protect wp-content/upgrade-temp-backup (and wp-content/upgrade) from being served over HTTP

Reported by: MythThrazz Owned by:
Priority: normal Milestone: Awaiting Review
Component: Upgrade/Install Version: 6.3
Severity: normal Keywords: has-patch has-unit-tests
Cc: Focuses:

Description (last modified by SergeyBiryukov)

I reported this to the WordPress security team as HackerOne #3993590. John closed it as N/A — not a vulnerability — and said I was welcome to open it here, with the caveat that even a bug report might not really apply, and that a Site Health check could help. So this is a hardening request. Rollback stays.

What happens

Since 6.3, every plugin/theme update moves the previous copy into wp-content/upgrade-temp-backup/{plugins,themes}/<slug>/ (WP_Upgrader::move_to_temp_backup_dir(), @since 6.3.0). Unpack staging lives in wp-content/upgrade/. Both directories sit in the docroot. mkdir() does not drop an index.php stub or an .htaccess. Core already writes index.php (// Silence is golden.) into wp-content/, wp-content/plugins/, wp-content/themes/, and wp-content/uploads/.

Site Health only checks that the temp-backup directory is writable (update_temp_backup_writable). It does not check whether leftovers are web-reachable.

Related: #51857, [55720] (path moved from upgrade/temp-backup/ to upgrade-temp-backup/). See also #64510 (open) — leftovers not deleted when the filesystem is used without WP_Filesystem credentials. That ticket is about cleanup. This one is about the copy being HTTP-reachable while it exists.

What I measured

  • Healthy update, not a crash: Query Monitor 3.20.2 → 4.0.7. The complete previous version (165 files) was HTTP-reachable for about 2.5 seconds, then deleted on shutdown. The weekly cleanup cron cannot cover this window — it exists on every update.
  • Leftovers when cleanup does not run: a failed Forminator auto-update left the previous version (1.35.0) answering HTTP 200 for nine days (forminator.php + readme.txt). WP-Cron was not firing on that site. readme.txt discloses the exact vintage.
  • Direct PHP execution: on an nginx + php-fpm origin, a planted .php under that path returned 200 and ran. Plugin bootstraps that guard on ABSPATH no-op on a direct hit; self-contained handlers (file managers, sanitizers, uploaders) do run. Path-keyed WAF rules aimed at /wp-content/plugins/<slug>/ miss this URL.

I am not claiming a CVE. Execution is conditional. Version/source disclosure of the previous copy is the thing that always happens while the copy exists.

What I'd like core to consider

Cheapest first:

  1. Drop the same index.php stub core already uses, when these directories are created. Stops listing. Does not stop a direct file request.
  2. Drop an .htaccess deny (Require all denied / RedirectMatch 404) next to it, for Apache and LiteSpeed. nginx still needs a vhost rule.
  3. A Site Health check for leftover copies in upgrade-temp-backup/ — the idea John floated.

I already deny both paths at nginx on my own sites (location ^~). Default installs get nothing.

Happy to write a patch for (1) and (3) if this is wanted.

Change History (3)

#1 @MythThrazz
8 weeks ago

  • Description modified (diff)

Fixing wiki: needs-patch got glued to the last sentence (it belongs in keywords), and a few identifiers lost underscores to italic markup. cc johnbillion — he closed HackerOne #3993590 and suggested opening this here.

#2 @SergeyBiryukov
8 weeks ago

  • Description modified (diff)

This ticket was mentioned in ​PR #14879 on ​WordPress/wordpress-develop by ​@devansh2002.


3 weeks ago
#3

  • Keywords has-patch has-unit-tests added

What

  • Adds WP_Upgrader::add_index_file(), which writes the standard "Silence is golden" index.php into a directory if it doesn't already have one.
  • unpack_package(): creates wp-content/upgrade/ if it's missing, adds the index file, and no longer deletes it during cleanup.
  • move_to_temp_backup_dir(): adds the index file to upgrade-temp-backup/ and its plugins//themes/ subdirectory.
  • wp_delete_all_temp_backups(): keeps the top-level index.php.

Not in this PR

Stops directory listing only; files can still be requested by direct URL. An .htaccess deny and a Site Health check (also suggested on the ticket) could be follow-ups.

Testing

  • vendor/bin/phpunit --group 66148 (3 new tests)
  • vendor/bin/phpunit --group upgrade,update passes

AI disclosure

Code and tests were written with help from Claude Code. I reviewed and tested them.

Note: See TracTickets for help on using tickets.