Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b5d03b7f81 | |||
| b81db2d302 |
5 changed files with 219 additions and 33 deletions
|
|
@ -1,5 +1,48 @@
|
|||
== 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_
|
||||
|
||||
**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_
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -259,14 +298,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 +320,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.
|
||||
*
|
||||
|
|
@ -357,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 ) );
|
||||
}
|
||||
|
||||
// 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 );
|
||||
?>
|
||||
<p class="robotstxt-2fa-login-field robotstxt-2fa-stage-field">
|
||||
|
|
@ -909,9 +1016,10 @@ class Login_Form_Manager {
|
|||
$stage_token = wp_create_nonce( self::STAGE_TOKEN_ACTION . '|' . $user->ID );
|
||||
|
||||
$query_args = array(
|
||||
self::QUERY_STAGE => self::STAGE_VERIFY,
|
||||
self::QUERY_METHOD => $method,
|
||||
self::QUERY_PENDING => $this->issue_pending_token( $user->ID ),
|
||||
self::QUERY_ACTION => self::STAGE_ACTION,
|
||||
self::QUERY_STAGE => self::STAGE_VERIFY,
|
||||
self::QUERY_METHOD => $method,
|
||||
self::QUERY_PENDING => $this->issue_pending_token( $user->ID ),
|
||||
self::QUERY_STAGE_TOKEN => $stage_token,
|
||||
);
|
||||
|
||||
|
|
@ -1543,16 +1651,53 @@ class Login_Form_Manager {
|
|||
/**
|
||||
* 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
|
||||
*/
|
||||
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.
|
||||
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 esc_url_raw( wp_unslash( $_REQUEST['redirect_to'] ) );
|
||||
// phpcs:enable WordPress.Security.NonceVerification.Recommended
|
||||
// Same-host URLs only (wp_validate_redirect applies the allowed hosts list).
|
||||
$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 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1567,6 +1712,7 @@ class Login_Form_Manager {
|
|||
$login_url = self::get_canonical_login_url( $redirect_to );
|
||||
|
||||
$args = array(
|
||||
self::QUERY_ACTION => self::STAGE_ACTION,
|
||||
self::QUERY_STAGE => self::STAGE_VERIFY,
|
||||
self::QUERY_METHOD => $this->get_requested_method(),
|
||||
);
|
||||
|
|
|
|||
39
readme.txt
39
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.11
|
||||
License: GPLv3 or later
|
||||
License URI: https://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
|
|
@ -59,6 +59,23 @@ Yes. Activate the plugin at the network level. Network administrators can set an
|
|||
|
||||
== 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 =
|
||||
|
||||
_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_
|
||||
|
|
@ -84,26 +101,6 @@ _Release date: 2026-11-03_
|
|||
* PHPCompatibility: 8.3-8.6 — 0 issues
|
||||
* 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.
|
||||
|
||||
= 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.
|
||||
|
|
|
|||
|
|
@ -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.11
|
||||
* 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.11' );
|
||||
}
|
||||
|
||||
if ( ! defined( 'ROBOTSTXT_2FA_FILE' ) ) {
|
||||
|
|
|
|||
4
vendor/composer/installed.php
vendored
4
vendor/composer/installed.php
vendored
|
|
@ -3,7 +3,7 @@
|
|||
'name' => 'robotstxt/robotstxt-2fa',
|
||||
'pretty_version' => 'dev-main',
|
||||
'version' => 'dev-main',
|
||||
'reference' => '540212fa49599418676da0d91e03bac2acb6c60a',
|
||||
'reference' => '6a33c6b7caaa03be52487856f8c82810992ac0f1',
|
||||
'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' => '6a33c6b7caaa03be52487856f8c82810992ac0f1',
|
||||
'type' => 'wordpress-plugin',
|
||||
'install_path' => __DIR__ . '/../../',
|
||||
'aliases' => array(),
|
||||
|
|
|
|||
Loading…
Reference in a new issue