Commit 67ab41afe7 for wordpress.org

commit 67ab41afe713688ee72b9496abc9ef80eaf5ab2d
Author: gziolo <gziolo@git.wordpress.org>
Date:   Mon Nov 23 09:39:08 2026 +0000

    Abilities API: Reject input that sanitization makes invalid

    `WP_Ability::prepare_input()` validated input before sanitizing it, but did not validate the sanitized value. Sanitization can turn accepted input into a value that breaks the schema. For example, whitespace or markup can become an empty string below `minLength`, and an infinite number can become `0` when cast to an integer with `minimum: 1`. Callbacks could then receive input that does not match the schema.

    When sanitization changes the value, `prepare_input()` now validates it again with `validate_input()`, including the `wp_ability_validate_input` filter. Unchanged input is validated only once. Validation errors are returned before the permission and execute callbacks run.

    Developed in https://github.com/WordPress/wordpress-develop/pull/15911.
    Follow-up to r65044, r65370.

    Reviewed by jorgefilipecosta.

    Props aryanjasala, avinashzala01, gziolo, jorgefilipecosta.
    Fixes #66665.


    Built from https://develop.svn.wordpress.org/trunk@65739


    git-svn-id: http://core.svn.wordpress.org/trunk@64769 1a063a9b-81f0-0310-95a4-ce76da25c4cd

diff --git a/wp-includes/abilities-api/class-wp-ability.php b/wp-includes/abilities-api/class-wp-ability.php
index 6903f66d66..3e9dc2c18f 100644
--- a/wp-includes/abilities-api/class-wp-ability.php
+++ b/wp-includes/abilities-api/class-wp-ability.php
@@ -682,7 +682,11 @@ class WP_Ability {
 		 * override it. If default validation passed, the filter can add additional
 		 * validation checks and return a WP_Error if those checks fail.
 		 *
+		 * During input preparation, this filter runs again with sanitized input if
+		 * sanitization changes the value and completes without an error.
+		 *
 		 * @since 7.1.0
+		 * @since 7.2.0 Also runs with sanitized input when sanitization changes the value.
 		 *
 		 * @param true|WP_Error $is_valid     The validation result from default validation.
 		 * @param mixed         $input        The input data being validated.
@@ -704,7 +708,8 @@ class WP_Ability {
 	 * Normalizes the input, validates it against the input schema, and then sanitizes
 	 * it. `execute()` passes the result to the permission and execute callbacks.
 	 * Validation runs before sanitization, so sanitization cannot make invalid input
-	 * valid.
+	 * valid. Changed input is validated again after sanitization, including the
+	 * `wp_ability_validate_input` filter, before it reaches the callbacks.
 	 *
 	 * @since 7.2.0
 	 *
@@ -726,7 +731,25 @@ class WP_Ability {
 			return $is_valid;
 		}

-		return $this->sanitize_input( $input );
+		$sanitized = $this->sanitize_input( $input );
+		if ( is_wp_error( $sanitized ) ) {
+			return $sanitized;
+		}
+
+		/*
+		 * Sanitization can make valid input invalid, for example by trimming a string
+		 * below its `minLength` or casting an out-of-range number to a different integer.
+		 * Validate changed input again so validation filters also evaluate the value
+		 * callbacks will receive.
+		 */
+		if ( $sanitized !== $input ) {
+			$is_valid = $this->validate_input( $sanitized );
+			if ( is_wp_error( $is_valid ) ) {
+				return $is_valid;
+			}
+		}
+
+		return $sanitized;
 	}

 	/**
diff --git a/wp-includes/version.php b/wp-includes/version.php
index d6d846d1ac..6b116df583 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
  *
  * @global string $wp_version
  */
-$wp_version = '7.2-RC2-65738';
+$wp_version = '7.2-RC2-65739';

 /**
  * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.