Changeset 56884 for branches/5.8/src/wp-admin/includes/user.php
- Timestamp:
- 10/12/2023 03:14:45 PM (14 months ago)
- Location:
- branches/5.8
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/5.8
- Property svn:mergeinfo changed
/trunk merged: 56833-56838
- Property svn:mergeinfo changed
-
branches/5.8/src/wp-admin/includes/user.php
r50981 r56884 600 600 * 601 601 * @since 5.6.0 602 * @since 6.2.0 Allow insecure HTTP connections for the local environment. 603 * @since 6.3.2 Validates the success and reject URLs to prevent javascript pseudo protocol being executed. 602 604 * 603 605 * @param array $request { … … 615 617 $error = new WP_Error(); 616 618 617 if ( ! empty( $request['success_url'] ) ) { 618 $scheme = wp_parse_url( $request['success_url'], PHP_URL_SCHEME ); 619 620 if ( 'http' === $scheme ) { 619 if ( isset( $request['success_url'] ) ) { 620 $validated_success_url = wp_is_authorize_application_redirect_url_valid( $request['success_url'] ); 621 if ( is_wp_error( $validated_success_url ) ) { 621 622 $error->add( 622 'invalid_redirect_scheme',623 __( 'The success url must be served over a secure connection.')623 $validated_success_url->get_error_code(), 624 $validated_success_url->get_error_message() 624 625 ); 625 626 } 626 627 } 627 628 628 if ( ! empty( $request['reject_url'] ) ) { 629 $scheme = wp_parse_url( $request['reject_url'], PHP_URL_SCHEME ); 630 631 if ( 'http' === $scheme ) { 629 if ( isset( $request['reject_url'] ) ) { 630 $validated_reject_url = wp_is_authorize_application_redirect_url_valid( $request['reject_url'] ); 631 if ( is_wp_error( $validated_reject_url ) ) { 632 632 $error->add( 633 'invalid_redirect_scheme',634 __( 'The rejection url must be served over a secure connection.')633 $validated_reject_url->get_error_code(), 634 $validated_reject_url->get_error_message() 635 635 ); 636 636 } … … 661 661 return true; 662 662 } 663 664 /** 665 * Validates the redirect URL protocol scheme. The protocol can be anything except http and javascript. 666 * 667 * @since 6.3.2 668 * 669 * @param string $url - The redirect URL to be validated. 670 * 671 * @return true|WP_Error True if the redirect URL is valid, a WP_Error object otherwise. 672 */ 673 function wp_is_authorize_application_redirect_url_valid( $url ) { 674 $bad_protocols = array( 'javascript', 'data' ); 675 if ( empty( $url ) ) { 676 return true; 677 } 678 679 // Based on https://www.rfc-editor.org/rfc/rfc2396#section-3.1 680 $valid_scheme_regex = '/^[a-zA-Z][a-zA-Z0-9+.-]*:/'; 681 if ( ! preg_match( $valid_scheme_regex, $url ) ) { 682 return new WP_Error( 683 'invalid_redirect_url_format', 684 __( 'Invalid URL format.' ) 685 ); 686 } 687 688 /** 689 * Filters the list of invalid protocols used in applications redirect URLs. 690 * 691 * @since 6.3.2 692 * 693 * @param string[] $bad_protocols Array of invalid protocols. 694 * @param string $url The redirect URL to be validated. 695 */ 696 $invalid_protocols = array_map( 'strtolower', apply_filters( 'wp_authorize_application_redirect_url_invalid_protocols', $bad_protocols, $url ) ); 697 698 $scheme = wp_parse_url( $url, PHP_URL_SCHEME ); 699 $host = wp_parse_url( $url, PHP_URL_HOST ); 700 $is_local = 'local' === wp_get_environment_type(); 701 702 // validates if the proper URI format is applied to the $url 703 if ( empty( $host ) || empty( $scheme ) || in_array( strtolower( $scheme ), $invalid_protocols, true ) ) { 704 return new WP_Error( 705 'invalid_redirect_url_format', 706 __( 'Invalid URL format.' ) 707 ); 708 } 709 710 if ( 'http' === $scheme && ! $is_local ) { 711 return new WP_Error( 712 'invalid_redirect_scheme', 713 __( 'The URL must be served over a secure connection.' ) 714 ); 715 } 716 717 return true; 718 }
Note: See TracChangeset
for help on using the changeset viewer.