Skip to content

About

Small MU plugin to enforce two-factor in wordpress site

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Require Two-Factor

A WordPress mu-plugin that enforces two-factor authentication for all users by falling back to email-based 2FA.

The Two-Factor plugin is opt-in per user and has no enforcement setting. This package uses a filter to ensure at least one 2FA provider is available (enabled and configured), and if not, it enables the email provider.

Originally based on this WordPress.org support thread, but has been expanded to cover a bypass path for users with a provider enabled but not usable: a provider enabled without being configured (possible in user meta written by older Two-Factor versions), or backup codes that have all been used.

Note: While this plugin is installed, email cannot be disabled as a provider. Any user will always be able to select email as a 2FA provider. We need email since it's the only 2FA that is automatically enforceable without requiring user setup.

Requirements

  • Two-Factor plugin 0.17 or newer, installed and active
  • PHP 8.4 or newer
  • Bedrock or another Composer-managed WordPress setup with composer/installers (handles the wordpress-muplugin install type)
  • Bedrock's mu-plugin autoloader or equivalent (WordPress only auto-loads .php files directly in mu-plugins/, not subdirectories)

Install

Add the VCS repository to your composer.json and require both the Two-Factor plugin and this package:

{
  "repositories": [
    {
      "type": "composer",
      "url": "https://repo.wp-packages.org"
    },
    {
      "type": "vcs",
      "url": "https://github.com/oBusk/wp-plugin-require-two-factor"
    }
  ],
  "require": {
    "wp-plugin/two-factor": "^0.17",
    "obusk/wp-plugin-require-two-factor": "^1.1"
  }
}

No configuration needed. Once installed, every user without an available 2FA provider will be prompted for an email code on login.

Caveats

  • Email deliverability becomes an auth dependency. Every user without an available provider will receive a one-time code by email on login. If your mail path is broken, those users are locked out. Recovery: remove the Composer requirement and deploy. Renaming the file in mu-plugins/ works as an emergency stop, but will not survive a rebuild if the site runs from a built image.
  • Email is a weaker second factor than TOTP. This is a baseline enforcement measure, not a replacement for encouraging users to set up TOTP.
  • Application passwords bypass the 2FA flow. Application password logins over the REST API and XML-RPC are allowed by default for users with 2FA enabled. Since Two-Factor 0.17 this is limited to the user who authenticated with the application password; regular passwords are blocked for API requests. Return false from two_factor_user_api_login_enable, or disable application passwords, if this is a concern.
  • two_factor_is_required_for_user bypasses enforcement. Since Two-Factor 0.17, any code returning false from this filter skips the 2FA flow for that user entirely, including the email fallback. Audit other plugins and themes for it.
  • wp two-factor disable <user> reports an error. Without a provider argument, the command wipes the user's 2FA data (TOTP secret, backup codes, provider settings), then fails with "2FA is still active for user … manual inspection required" because this plugin re-adds email. The data is already wiped and the user falls back to email as intended, but the command exits before destroying the user's sessions. Run wp user session destroy <user> --all afterwards.

About

Small MU plugin to enforce two-factor in wordpress site

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages