From b81db2d302389de96b8d467bec2b105bdd6253db Mon Sep 17 00:00:00 2001 From: Javier Casares Date: Wed, 4 Nov 2026 14:38:18 +0000 Subject: [PATCH 1/2] v1.6.10 --- changelog.txt | 21 +++++++ includes/login/class-login-form-manager.php | 68 ++++++++++++++++++++- readme.txt | 18 +++--- robotstxt-2fa.php | 4 +- vendor/composer/installed.php | 4 +- 5 files changed, 100 insertions(+), 15 deletions(-) diff --git a/changelog.txt b/changelog.txt index d2abf8c..252f148 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,26 @@ == Changelog == += 1.6.10 = + +_Release date: 2026-11-03_ + +**Fixed** + +* The 2FA verification stage now stays on the login URL the visitor actually used. When wp-login.php executes through an alias or renamed slug (a `/login` rewrite, a "hidden login" setup that does not filter `site_url`), the post-password redirect previously always targeted the literal `/wp-login.php` — on sites where that URL is blocked or renamed away at server level, users were stranded on a 403/404 page right after a correct password. The stage base URL now preserves the executing login surface (path only; host and scheme still come from the site's canonical URL; traversal sequences rejected), while logins submitted from custom pages calling `wp_signon()` keep landing on the real wp-login.php as before (the 1.6.4 Restrict Content Pro guarantee). Full root-cause analysis in `docs/report-login-surface-urls.md`. + +**Compatibility** + +* WordPress: 7.0 - 7.2 +* PHP: 8.3 - 8.6 + +**Tests** + +* PHP Coding Standards: PHP_CodeSniffer 3.13.6 / WPCS 3.4.1 — 0 errors +* PHPStan: level max (10), no baseline — 0 errors +* PHPCompatibility: 8.3-8.6 — 0 issues +* PHPUnit: 9.6.38 — 119 tests, 229 assertions (PHP 8.6.0RC3 and 8.3.36) +* Live surface probes: WordPress 7.2-beta4 (single site) and WordPress 7.0 (multisite) on PHP 8.6.0RC3, MariaDB 11.8.9 + = 1.6.9 = _Release date: 2026-11-03_ diff --git a/includes/login/class-login-form-manager.php b/includes/login/class-login-form-manager.php index 80c2bbd..d43e783 100644 --- a/includes/login/class-login-form-manager.php +++ b/includes/login/class-login-form-manager.php @@ -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. * diff --git a/readme.txt b/readme.txt index 77c56fb..52b5571 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: security, two-factor authentication, login, otp Requires at least: 7.0 Tested up to: 7.2 Requires PHP: 8.3 -Stable tag: 1.6.9 +Stable tag: 1.6.10 License: GPLv3 or later License URI: https://www.gnu.org/licenses/gpl-3.0.html @@ -59,6 +59,14 @@ Yes. Activate the plugin at the network level. Network administrators can set an == Changelog == += 1.6.10 = + +_Release date: 2026-11-03_ + +**Fixed** + +* The 2FA verification stage now stays on the login URL the visitor actually used. When wp-login.php executes through an alias or renamed slug (a `/login` rewrite, a "hidden login" setup that does not filter `site_url`), the post-password redirect previously always targeted the literal `/wp-login.php` — on sites where that URL is blocked or renamed away at server level, users were stranded on a 403/404 page right after a correct password. Logins submitted from custom pages keep landing on the real wp-login.php as before. + = 1.6.9 = _Release date: 2026-11-03_ @@ -96,14 +104,6 @@ _Release date: 2026-09-21_ * "We could not determine which account you are trying to access" during verification: the pending-stage token was stored in a transient, which external object caches (Redis/Memcached) can evict at any time, killing live verification sessions. Tokens now live in a persistent option map and the error message asks the user to sign in again. -= 1.6.7 = - -_Release date: 2026-09-17_ - -**Fixed** - -* The forced-setup wizard felt like a broken redirect loop: the wizard redirect bounced users to the profile with no explanation (it now carries a flag that renders a clear "activate at least one verification method, then save" warning), and saving with an expired form nonce silently did nothing (it now raises a visible "form session expired" error so users know to try again). - = Previous versions = For the full changelog see the [changelog](https://www.robotstxt.software/plugins/robotstxt-2fa/) page. diff --git a/robotstxt-2fa.php b/robotstxt-2fa.php index 5f16264..a738497 100644 --- a/robotstxt-2fa.php +++ b/robotstxt-2fa.php @@ -4,7 +4,7 @@ * Plugin URI: https://www.robotstxt.software/plugins/robotstxt-2fa/ * Update URI: https://www.robotstxt.software/plugins/robotstxt-2fa/ * Description: Adds two-factor authentication to the WordPress login flow. - * Version: 1.6.9 + * Version: 1.6.10 * Author: ROBOTSTXT * Author URI: https://www.robotstxt.software/ * Text Domain: robotstxt-2fa @@ -25,7 +25,7 @@ if ( ! defined( 'ABSPATH' ) ) { } if ( ! defined( 'ROBOTSTXT_2FA_VERSION' ) ) { - define( 'ROBOTSTXT_2FA_VERSION', '1.6.9' ); + define( 'ROBOTSTXT_2FA_VERSION', '1.6.10' ); } if ( ! defined( 'ROBOTSTXT_2FA_FILE' ) ) { diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index 2ceb754..bbb7cc7 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -3,7 +3,7 @@ 'name' => 'robotstxt/robotstxt-2fa', 'pretty_version' => 'dev-main', 'version' => 'dev-main', - 'reference' => '540212fa49599418676da0d91e03bac2acb6c60a', + 'reference' => '75d6bdce967002e99e4a4c21df2088277a905e90', 'type' => 'wordpress-plugin', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -40,7 +40,7 @@ 'robotstxt/robotstxt-2fa' => array( 'pretty_version' => 'dev-main', 'version' => 'dev-main', - 'reference' => '540212fa49599418676da0d91e03bac2acb6c60a', + 'reference' => '75d6bdce967002e99e4a4c21df2088277a905e90', 'type' => 'wordpress-plugin', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), From b5d03b7f81024aaacdb7d5bfff45577344b158b3 Mon Sep 17 00:00:00 2001 From: Javier Casares Date: Wed, 4 Nov 2026 18:43:02 +0000 Subject: [PATCH 2/2] v1.6.11 --- changelog.txt | 22 +++++ includes/login/class-login-form-manager.php | 94 +++++++++++++++++++-- readme.txt | 23 +++-- robotstxt-2fa.php | 4 +- vendor/composer/installed.php | 4 +- 5 files changed, 124 insertions(+), 23 deletions(-) diff --git a/changelog.txt b/changelog.txt index 252f148..849c0d6 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,27 @@ == Changelog == += 1.6.11 = + +_Release date: 2026-11-04_ + +**Fixed** + +* The 2FA verification screen is no longer hijacked on membership sites that redirect the WordPress login away from wp-login.php (confirmed live on Restrict Content Pro 4.0.9 with "Hijack Login URL" enabled and the login at a custom account page such as /mi-cuenta/). RCP implements the hijack twice: through the login_url filter (already handled since 1.6.4) and — new finding — through a `login_form_login` redirect that bounces every default-action wp-login.php request to the membership page, dropping the 2FA query arguments. Stage requests now carry a dedicated `action=robotstxt-2fa-verify` (declared to WordPress via a registered `login_form_` hook, preserved on submission through a hidden field), so they run core's login branch without firing `login_form_login`, out of reach of that redirect pattern in any plugin. Verified end to end on the reported replica: password at the membership page → verification screen renders → valid code → user lands back on the membership page, logged in. +* Users logging in from front-end forms (membership/account pages) now return to the page they logged in from after completing 2FA instead of landing in wp-admin: when the request carries no core `redirect_to`, the challenge falls back to the raw HTTP referer, validated to be same-host and not an admin or login URL (foreign and admin referers are ignored). + +**Compatibility** + +* WordPress: 7.0 - 7.2 +* PHP: 8.3 - 8.6 + +**Tests** + +* PHP Coding Standards: PHP_CodeSniffer 3.13.6 / WPCS 3.4.1 — 0 errors +* PHPStan: level max (10), no baseline — 0 errors +* PHPCompatibility: 8.3-8.6 — 0 issues +* PHPUnit: 9.6.38 — 125 tests, 236 assertions (PHP 8.6.0RC3 and 8.3.36) +* Live end-to-end on the reported site replica (WordPress 7.1.4 + Restrict Content Pro 4.0.9): full login → 2FA → return-to-page cycle, MariaDB 11.8.9 + = 1.6.10 = _Release date: 2026-11-03_ diff --git a/includes/login/class-login-form-manager.php b/includes/login/class-login-form-manager.php index d43e783..e9ad577 100644 --- a/includes/login/class-login-form-manager.php +++ b/includes/login/class-login-form-manager.php @@ -111,6 +111,26 @@ class Login_Form_Manager { */ private const FIELD_STAGE_TOKEN = 'robotstxt_2fa_stage_token'; + /** + * Core login action used for verification-stage requests. + * + * The wp-login.php script validates the `action` parameter against its + * known actions plus any with a registered `login_form_{action}` hook, + * and resets unknown ones to `login`. Membership plugins (Restrict + * Content Pro's "Hijack Login URL", and others with the same pattern) hook + * `login_form_login` to bounce the default login action to their own + * page — which would prevent the verification screen from ever rendering. + * A dedicated action keeps stage requests out of that hook while still + * running core's default login branch (form rendering + credential + * processing). + */ + private const STAGE_ACTION = 'robotstxt-2fa-verify'; + + /** + * Query parameter carrying the core login action. + */ + private const QUERY_ACTION = 'action'; + /** * Identifier for the verification stage. */ @@ -246,6 +266,25 @@ class Login_Form_Manager { add_filter( 'authenticate', array( $this, 'maybe_complete_verification' ), 5, 3 ); add_filter( 'authenticate', array( $this, 'enforce_verification_challenge' ), 30, 3 ); add_action( 'init', array( $this, 'maybe_remove_altcha_interceptor' ), 0 ); + add_action( 'login_form_' . self::STAGE_ACTION, array( $this, 'stage_action_noop' ) ); + } + + /** + * No-op callback for the dedicated verification-stage login action. + * + * Core only accepts non-default `action` values that have a + * `login_form_{action}` hook registered; registering this callback + * declares the stage action so stage requests are not reset to the + * default `login` action — and therefore are not hijacked by + * third-party `login_form_login` redirects (membership plugins that + * move the login form to their own page). + * + * @since 1.6.11 + * + * @return void + */ + public function stage_action_noop(): void { + // Intentionally empty; registration alone declares the action. } /** @@ -421,6 +460,10 @@ class Login_Form_Manager { printf( '', esc_attr( self::FIELD_STAGE_TOKEN ), esc_attr( $stage_token ) ); } + // Keep the dedicated stage action on submission so third-party + // login_form_login redirects cannot bounce the verification POST. + printf( '', esc_attr( self::QUERY_ACTION ), esc_attr( self::STAGE_ACTION ) ); + wp_nonce_field( self::LOGIN_NONCE_ACTION, self::LOGIN_NONCE_FIELD ); ?>