v1.6.10
This commit is contained in:
parent
7379505d20
commit
b81db2d302
1 changed files with 100 additions and 15 deletions
|
|
@ -259,14 +259,20 @@ class Login_Form_Manager {
|
|||
* login_init hook when wp-login.php itself loads. This mirrors the URL
|
||||
* construction wp_login_url() performs before its filter runs.
|
||||
*
|
||||
* When wp-login.php executes through a different URL (a /login rewrite,
|
||||
* a renamed "hidden login" slug), the stage keeps using that same URL so
|
||||
* the verification screen stays reachable on sites that block the literal
|
||||
* wp-login.php address. See get_stage_base_url().
|
||||
*
|
||||
* @since 1.6.4
|
||||
* @since 1.6.10 Preserves the login surface currently in use when wp-login.php executes through an alias.
|
||||
*
|
||||
* @param string $redirect_to Optional redirect_to value to carry over.
|
||||
*
|
||||
* @return string Absolute wp-login.php URL with optional redirect_to parameter.
|
||||
* @return string Absolute login URL with optional redirect_to parameter.
|
||||
*/
|
||||
public static function get_canonical_login_url( string $redirect_to = '' ): string {
|
||||
$url = site_url( 'wp-login.php', 'login' );
|
||||
$url = self::get_stage_base_url();
|
||||
|
||||
if ( '' !== $redirect_to ) {
|
||||
$url = add_query_arg( 'redirect_to', urlencode( $redirect_to ), $url );
|
||||
|
|
@ -275,6 +281,64 @@ class Login_Form_Manager {
|
|||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the base login URL the 2FA stage should navigate on.
|
||||
*
|
||||
* Priority order:
|
||||
*
|
||||
* 1. The URL the visitor actually used, when wp-login.php is the executing
|
||||
* script but was reached through an alias or renamed slug (server
|
||||
* rewrites such as /login, "hide login" plugins). Keeping the stage on
|
||||
* the reachable surface avoids redirecting users to a blocked or
|
||||
* rewritten-away wp-login.php URL after a correct password.
|
||||
* 2. The canonical wp-login.php URL (site_url), which remains filterable
|
||||
* by plugins that rewrite it, and which is always used when credentials
|
||||
* were submitted from a custom page calling wp_signon() — the
|
||||
* login_init hook does not fire there, and the verification form only
|
||||
* renders on wp-login.php.
|
||||
*
|
||||
* The path from the current request is only trusted when wp-login.php is
|
||||
* actually executing (login_init fired), traversal sequences are
|
||||
* rejected, and only the path is reused — host and scheme always come
|
||||
* from the site's own canonical URL.
|
||||
*
|
||||
* @since 1.6.10
|
||||
*
|
||||
* @return string Absolute login URL without any 2FA query arguments.
|
||||
*/
|
||||
private static function get_stage_base_url(): string {
|
||||
$canonical = site_url( 'wp-login.php', 'login' );
|
||||
|
||||
if ( ! did_action( 'login_init' ) ) {
|
||||
return $canonical;
|
||||
}
|
||||
|
||||
$request_uri = isset( $_SERVER['REQUEST_URI'] ) && is_string( $_SERVER['REQUEST_URI'] )
|
||||
? $_SERVER['REQUEST_URI']
|
||||
: '';
|
||||
|
||||
$request_path = wp_parse_url( $request_uri, PHP_URL_PATH );
|
||||
|
||||
if ( ! is_string( $request_path ) ) {
|
||||
return $canonical;
|
||||
}
|
||||
|
||||
$request_path = rawurldecode( $request_path );
|
||||
|
||||
// Reject traversal attempts in both raw and percent-encoded form.
|
||||
if ( str_contains( $request_path, '..' ) ) {
|
||||
return $canonical;
|
||||
}
|
||||
|
||||
$canonical_path = wp_parse_url( $canonical, PHP_URL_PATH );
|
||||
|
||||
if ( ! is_string( $canonical_path ) || '' === $canonical_path || $request_path === $canonical_path ) {
|
||||
return $canonical;
|
||||
}
|
||||
|
||||
return str_replace( $canonical_path, $request_path, $canonical );
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the ALTCHA Spam Protection login interceptor during the 2FA stage.
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in a new issue