This commit is contained in:
Javier Casares 2026-11-04 18:43:02 +00:00
commit b5d03b7f81
5 changed files with 124 additions and 23 deletions

View file

@ -1,5 +1,27 @@
== Changelog == == 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 = = 1.6.10 =
_Release date: 2026-11-03_ _Release date: 2026-11-03_

View file

@ -111,6 +111,26 @@ class Login_Form_Manager {
*/ */
private const FIELD_STAGE_TOKEN = 'robotstxt_2fa_stage_token'; 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. * 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, 'maybe_complete_verification' ), 5, 3 );
add_filter( 'authenticate', array( $this, 'enforce_verification_challenge' ), 30, 3 ); add_filter( 'authenticate', array( $this, 'enforce_verification_challenge' ), 30, 3 );
add_action( 'init', array( $this, 'maybe_remove_altcha_interceptor' ), 0 ); 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( '<input type="hidden" name="%1$s" value="%2$s" />', esc_attr( self::FIELD_STAGE_TOKEN ), esc_attr( $stage_token ) ); printf( '<input type="hidden" name="%1$s" value="%2$s" />', 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( '<input type="hidden" name="%1$s" value="%2$s" />', esc_attr( self::QUERY_ACTION ), esc_attr( self::STAGE_ACTION ) );
wp_nonce_field( self::LOGIN_NONCE_ACTION, self::LOGIN_NONCE_FIELD ); wp_nonce_field( self::LOGIN_NONCE_ACTION, self::LOGIN_NONCE_FIELD );
?> ?>
<p class="robotstxt-2fa-login-field robotstxt-2fa-stage-field"> <p class="robotstxt-2fa-login-field robotstxt-2fa-stage-field">
@ -973,6 +1016,7 @@ class Login_Form_Manager {
$stage_token = wp_create_nonce( self::STAGE_TOKEN_ACTION . '|' . $user->ID ); $stage_token = wp_create_nonce( self::STAGE_TOKEN_ACTION . '|' . $user->ID );
$query_args = array( $query_args = array(
self::QUERY_ACTION => self::STAGE_ACTION,
self::QUERY_STAGE => self::STAGE_VERIFY, self::QUERY_STAGE => self::STAGE_VERIFY,
self::QUERY_METHOD => $method, self::QUERY_METHOD => $method,
self::QUERY_PENDING => $this->issue_pending_token( $user->ID ), self::QUERY_PENDING => $this->issue_pending_token( $user->ID ),
@ -1607,16 +1651,53 @@ class Login_Form_Manager {
/** /**
* Retrieve the sanitized redirect_to parameter from the current request. * Retrieve the sanitized redirect_to parameter from the current request.
* *
* Falls back to the referring front-end page when the request carries no
* core redirect_to value: membership and custom login pages rarely post
* one, and their own post-login redirects are bypassed by the challenge,
* so without this the user would land in wp-admin after verifying instead
* of returning to the page they logged in from. Only same-site, non-admin
* referers are honored.
*
* @since 1.0.0
* @since 1.6.11 Added the same-site front-end referer fallback.
*
* @return string * @return string
*/ */
private function get_requested_redirect(): string { private function get_requested_redirect(): string {
// phpcs:disable WordPress.Security.NonceVerification.Recommended -- redirect_to is a standard WP login parameter; value is passed through esc_url_raw. // phpcs:disable WordPress.Security.NonceVerification.Recommended -- redirect_to is a standard WP login parameter; value is passed through esc_url_raw.
if ( ! isset( $_REQUEST['redirect_to'] ) || ! is_string( $_REQUEST['redirect_to'] ) ) { if ( isset( $_REQUEST['redirect_to'] ) && is_string( $_REQUEST['redirect_to'] ) ) {
return esc_url_raw( wp_unslash( $_REQUEST['redirect_to'] ) );
}
// phpcs:enable WordPress.Security.NonceVerification.Recommended
// The raw referer is used (not wp_get_referer()): login forms posted
// from their own page are self-referrals, which wp_get_referer()
// discards, and the form page is precisely the return target needed.
$raw_referer = wp_get_raw_referer();
if ( ! is_string( $raw_referer ) || '' === $raw_referer ) {
return ''; return '';
} }
return esc_url_raw( wp_unslash( $_REQUEST['redirect_to'] ) ); // Same-host URLs only (wp_validate_redirect applies the allowed hosts list).
// phpcs:enable WordPress.Security.NonceVerification.Recommended $validated = wp_validate_redirect( wp_unslash( $raw_referer ), '' );
if ( '' === $validated ) {
return '';
}
$path = wp_parse_url( $validated, PHP_URL_PATH );
if ( ! is_string( $path ) || '' === $path ) {
return '';
}
// Never bounce back into admin or the login screen itself.
if ( '/wp-admin' === $path || str_starts_with( $path, '/wp-admin/' ) || '/wp-login.php' === $path || str_ends_with( $path, '/wp-login.php' ) ) {
return '';
}
return esc_url_raw( $validated );
} }
/** /**
@ -1631,6 +1712,7 @@ class Login_Form_Manager {
$login_url = self::get_canonical_login_url( $redirect_to ); $login_url = self::get_canonical_login_url( $redirect_to );
$args = array( $args = array(
self::QUERY_ACTION => self::STAGE_ACTION,
self::QUERY_STAGE => self::STAGE_VERIFY, self::QUERY_STAGE => self::STAGE_VERIFY,
self::QUERY_METHOD => $this->get_requested_method(), self::QUERY_METHOD => $this->get_requested_method(),
); );

View file

@ -4,7 +4,7 @@ Tags: security, two-factor authentication, login, otp
Requires at least: 7.0 Requires at least: 7.0
Tested up to: 7.2 Tested up to: 7.2
Requires PHP: 8.3 Requires PHP: 8.3
Stable tag: 1.6.10 Stable tag: 1.6.11
License: GPLv3 or later License: GPLv3 or later
License URI: https://www.gnu.org/licenses/gpl-3.0.html License URI: https://www.gnu.org/licenses/gpl-3.0.html
@ -59,6 +59,15 @@ Yes. Activate the plugin at the network level. Network administrators can set an
== Changelog == == 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 (Restrict Content Pro's "Hijack Login URL" and any plugin using the same `login_form_login` redirect pattern). Stage requests now carry a dedicated login action that such redirects cannot intercept, verified end to end on the reported replica: password at the membership page → verification screen → valid code → back on the membership page, logged in.
* Users logging in from front-end forms now return to the page they logged in from after completing 2FA instead of landing in wp-admin.
= 1.6.10 = = 1.6.10 =
_Release date: 2026-11-03_ _Release date: 2026-11-03_
@ -92,18 +101,6 @@ _Release date: 2026-11-03_
* PHPCompatibility: 8.3-8.6 — 0 issues * PHPCompatibility: 8.3-8.6 — 0 issues
* PHPUnit: 9.6.38 — 110 tests, 220 assertions * PHPUnit: 9.6.38 — 110 tests, 220 assertions
= 1.6.8 =
_Release date: 2026-09-21_
**Added**
* Administrator visibility when email delivery fails: failed verification-code deliveries record a marker and administrators see a persistent, self-clearing notice ("2FA: email delivery is failing…") in wp-admin and the network admin, since forced-email users cannot sign in while delivery is broken.
**Fixed**
* "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.
= Previous versions = = Previous versions =
For the full changelog see the [changelog](https://www.robotstxt.software/plugins/robotstxt-2fa/) page. For the full changelog see the [changelog](https://www.robotstxt.software/plugins/robotstxt-2fa/) page.

View file

@ -4,7 +4,7 @@
* Plugin URI: https://www.robotstxt.software/plugins/robotstxt-2fa/ * Plugin URI: https://www.robotstxt.software/plugins/robotstxt-2fa/
* Update 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. * Description: Adds two-factor authentication to the WordPress login flow.
* Version: 1.6.10 * Version: 1.6.11
* Author: ROBOTSTXT * Author: ROBOTSTXT
* Author URI: https://www.robotstxt.software/ * Author URI: https://www.robotstxt.software/
* Text Domain: robotstxt-2fa * Text Domain: robotstxt-2fa
@ -25,7 +25,7 @@ if ( ! defined( 'ABSPATH' ) ) {
} }
if ( ! defined( 'ROBOTSTXT_2FA_VERSION' ) ) { if ( ! defined( 'ROBOTSTXT_2FA_VERSION' ) ) {
define( 'ROBOTSTXT_2FA_VERSION', '1.6.10' ); define( 'ROBOTSTXT_2FA_VERSION', '1.6.11' );
} }
if ( ! defined( 'ROBOTSTXT_2FA_FILE' ) ) { if ( ! defined( 'ROBOTSTXT_2FA_FILE' ) ) {

View file

@ -3,7 +3,7 @@
'name' => 'robotstxt/robotstxt-2fa', 'name' => 'robotstxt/robotstxt-2fa',
'pretty_version' => 'dev-main', 'pretty_version' => 'dev-main',
'version' => 'dev-main', 'version' => 'dev-main',
'reference' => '75d6bdce967002e99e4a4c21df2088277a905e90', 'reference' => '6a33c6b7caaa03be52487856f8c82810992ac0f1',
'type' => 'wordpress-plugin', 'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../', 'install_path' => __DIR__ . '/../../',
'aliases' => array(), 'aliases' => array(),
@ -40,7 +40,7 @@
'robotstxt/robotstxt-2fa' => array( 'robotstxt/robotstxt-2fa' => array(
'pretty_version' => 'dev-main', 'pretty_version' => 'dev-main',
'version' => 'dev-main', 'version' => 'dev-main',
'reference' => '75d6bdce967002e99e4a4c21df2088277a905e90', 'reference' => '6a33c6b7caaa03be52487856f8c82810992ac0f1',
'type' => 'wordpress-plugin', 'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../', 'install_path' => __DIR__ . '/../../',
'aliases' => array(), 'aliases' => array(),