Skip to content

IPv6 support for multisite wp_registration_log - #9911

Open
dd32 wants to merge 5 commits into
WordPress:trunkfrom
dd32:patch/ipv6-registration_log
Open

IPv6 support for multisite wp_registration_log#9911
dd32 wants to merge 5 commits into
WordPress:trunkfrom
dd32:patch/ipv6-registration_log

Conversation

@dd32

@dd32 dd32 commented Sep 16, 2025

Copy link
Copy Markdown
Member

Trac ticket: https://core.trac.wordpress.org/ticket/63986#ticket


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions

github-actions Bot commented Sep 16, 2025

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. You can also manually ask me to refresh this list by adding the props-bot label.

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

Props dd32, wildworks, tobiasbg, georgestephanis, motylanogha.

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

Comment thread src/wp-includes/ms-functions.php Outdated
@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

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • 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.

@wppoland

Copy link
Copy Markdown

Since the description notes the change is "untested and only validated on a visual review", here's a regression test for the core behavior — an IPv6 REMOTE_ADDR being stored intact by wpmu_log_new_registrations(). It passes on this branch and fails on trunk, where the old /[^0-9., ]/ mask strips the colons and hex digits (e.g. 2001:0db8:…:7334 becomes 200108853…07334).

Goes in tests/phpunit/tests/multisite/wpmuLogNewRegistrations.php:

	/**
	 * Ensures an IPv6 remote address is preserved when logging a registration.
	 *
	 * @ticket 63986
	 */
	public function test_wpmu_log_new_registrations_preserves_ipv6_address() {
		global $wpdb;

		$ipv6                   = '2001:0db8:85a3:0000:0000:8a2e:0370:7334';
		$original_remote_addr   = isset( $_SERVER['REMOTE_ADDR'] ) ? $_SERVER['REMOTE_ADDR'] : null;
		$_SERVER['REMOTE_ADDR'] = $ipv6;

		try {
			wpmu_log_new_registrations( 1, 1 );

			$logged_ip = $wpdb->get_var( "SELECT IP FROM {$wpdb->registration_log} WHERE blog_id = 1 ORDER BY ID DESC LIMIT 1" );
		} finally {
			if ( null === $original_remote_addr ) {
				unset( $_SERVER['REMOTE_ADDR'] );
			} else {
				$_SERVER['REMOTE_ADDR'] = $original_remote_addr;
			}
		}

		$this->assertSame(
			$ipv6,
			$logged_ip,
			'The IPv6 remote address was not stored intact in the registration log.'
		);
	}

Run with -c tests/phpunit/multisite.xml. One note while here: the sanitizing regex only allows lowercase hex (a-f), so an uppercase-hex IPv6 literal would still be partly stripped — worth considering a-fA-F if that's a concern. Happy to push the test as a commit.

Copilot AI review requested due to automatic review settings July 27, 2026 12:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds IPv6 compatibility for multisite registration logging by expanding the stored IP format and updating the multisite schema/upgrade path accordingly.

Changes:

  • Allow IPv6 characters when storing $_SERVER['REMOTE_ADDR'] into wp_registration_log.
  • Expand registration_log.IP column width from varchar(30) to varchar(39) in the multisite schema.
  • Add a multisite upgrade step intended to widen the existing registration_log.IP column.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/wp-includes/ms-functions.php Updates IP sanitization for wpmu_log_new_registrations() to better accommodate IPv6.
src/wp-admin/includes/upgrade.php Adds a multisite schema upgrade step to widen the registration_log.IP column (version-gated).
src/wp-admin/includes/schema.php Updates the multisite schema definition so new installs create registration_log.IP as varchar(39).
Comments suppressed due to low confidence (1)

src/wp-admin/includes/upgrade.php:3775

  • Indentation of this query line is inconsistent with the surrounding block (extra tab), which makes the upgrade code harder to read and violates the file’s existing formatting.
				$wpdb->query( "ALTER TABLE $wpdb->registration_log MODIFY IP varchar(39) NOT NULL default ''" );

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

array(
'email' => $user->user_email,
'IP' => preg_replace( '/[^0-9., ]/', '', wp_unslash( $_SERVER['REMOTE_ADDR'] ) ),
'IP' => preg_replace( '/[^a-f0-9:.]/', '', wp_unslash( $_SERVER['REMOTE_ADDR'] ) ),

// Multisite schema upgrades.
if ( $wp_current_db_version < 60497 && is_multisite() && wp_should_upgrade_global_tables() ) {
if ( $wp_current_db_version < 60498 && is_multisite() && wp_should_upgrade_global_tables() ) { // TODO: Update with commit.
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.

6 participants