-
+
@@ -222,8 +242,9 @@ public static function render_salt_notice(): void {
echo ' ';
echo wp_kses(
sprintf(
- /* translators: %s: salt generator URL */
- __( 'or generate them yourself at api.wordpress.org/secret-key and paste into wp-config.php.', 'magicauth' ),
+ /* translators: 1: documentation guide URL, 2: salt generator URL */
+ __( 'Read the step-by-step guide, or generate fresh salts at api.wordpress.org/secret-key and paste them into wp-config.php.', 'magicauth' ),
+ esc_url( self::DOCS_SALTS_URL ),
'https://api.wordpress.org/secret-key/1.1/salt/'
),
[
@@ -241,68 +262,21 @@ public static function render_salt_notice(): void {
value map for all eight constants,
- * or null on any failure so the caller can fall back to local generation.
- *
- * Values are rejected if they contain a single quote or backslash, preserving
- * the invariant that every salt is safe to splice into a single-quoted literal.
- *
- * @return array|null
- */
- private static function fetch_salts_from_api(): ?array {
- if ( ! function_exists( 'wp_remote_get' ) ) {
- return null;
- }
- $response = wp_remote_get(
- 'https://api.wordpress.org/secret-key/1.1/salt/',
- [ 'timeout' => 8 ]
- );
- if ( is_wp_error( $response ) || 200 !== (int) wp_remote_retrieve_response_code( $response ) ) {
- return null;
- }
- $body = wp_remote_retrieve_body( $response );
- if ( '' === $body ) {
- return null;
- }
-
- $values = [];
- foreach ( self::SALT_CONSTANTS as $name ) {
- if ( ! preg_match( self::define_pattern( $name ), $body, $matches ) ) {
- return null;
- }
- $value = $matches[3];
- if ( '' === trim( $value ) || false !== strpbrk( $value, "'\\" ) ) {
- return null;
- }
- foreach ( self::PLACEHOLDER_MARKERS as $marker ) {
- if ( false !== stripos( $value, $marker ) ) {
- return null;
- }
- }
- $values[ $name ] = $value;
- }
- return $values;
- }
-
- /**
- * The eight salt values to write: the WordPress API first, local generation
- * as a fallback (offline, firewalled, or air-gapped sites — common where
- * placeholder salts occur).
+ * The eight fresh salt values for the copy-and-paste block. Generated locally
+ * with random_bytes and never sent over the network, so the secrets the admin
+ * is about to paste are never transmitted, observed, or tampered with in
+ * transit. Local generation is strictly safer than fetching a remote endpoint
+ * for a value we only ever display for the admin to paste themselves.
*
* @return array
*/
private static function salt_values(): array {
- $api = self::fetch_salts_from_api();
- if ( null !== $api ) {
- return $api;
- }
$values = [];
foreach ( self::SALT_CONSTANTS as $name ) {
$values[ $name ] = self::generate_salt_value();
@@ -332,16 +306,6 @@ private static function define_pattern( string $name ): string {
return '/^[ \t]*define\(\s*([\'"])' . preg_quote( $name, '/' ) . '\1\s*,\s*([\'"])(.*?)\2\s*\)\s*;/m';
}
- /** True only when all eight salt defines are present in the given config text. */
- private static function defines_present( string $contents ): bool {
- foreach ( self::SALT_CONSTANTS as $name ) {
- if ( ! preg_match( self::define_pattern( $name ), $contents ) ) {
- return false;
- }
- }
- return true;
- }
-
/**
* File-based weak-salt detection (operates on wp-config text, not runtime
* constants). A salt is weak if missing, empty, or placeholder.
@@ -364,40 +328,6 @@ public static function config_has_weak_salts( string $contents ): bool {
return false;
}
- /**
- * Replace every salt define's value with the supplied one, preserving the
- * rest of the line verbatim. Pure string transform — returns null if any of
- * the eight defines is absent or has no value (caller falls back to paste).
- *
- * @param array $values Salt values keyed by constant name.
- */
- public static function rewrite_salt_defines( string $contents, array $values ): ?string {
- foreach ( self::SALT_CONSTANTS as $name ) {
- if ( ! isset( $values[ $name ] ) || '' === $values[ $name ] ) {
- return null;
- }
- $value = $values[ $name ];
- // Leading whitespace lives inside group 1 so indentation is preserved;
- // the line-start anchor (multiline) skips commented-out defines.
- $pattern = '/^([ \t]*define\(\s*([\'"])' . preg_quote( $name, '/' ) . '\2\s*,\s*)([\'"]).*?\3(\s*\)\s*;)/m';
- $count = 0;
- $result = preg_replace_callback(
- $pattern,
- static function ( array $matches ) use ( $value ): string {
- return (string) $matches[1] . "'" . $value . "'" . (string) $matches[4];
- },
- $contents,
- 1,
- $count
- );
- if ( ! is_string( $result ) || 1 !== $count ) {
- return null;
- }
- $contents = $result;
- }
- return $contents;
- }
-
/** Resolve wp-config.php the same way wp-load.php does (ABSPATH or one level up). */
public static function locate_wp_config(): ?string {
$candidate = ABSPATH . 'wp-config.php';
@@ -427,130 +357,45 @@ private static function filesystem(): ?\WP_Filesystem_Base {
}
/**
- * Can we rewrite wp-config.php in place? Requires the file located, the
- * direct filesystem method, write permission, and all eight defines present.
- */
- public static function salt_autofix_available(): bool {
- $path = self::locate_wp_config();
- if ( null === $path ) {
- return false;
- }
- $filesystem = self::filesystem();
- if ( null === $filesystem || ! $filesystem->is_writable( $path ) ) {
- return false;
- }
- $contents = $filesystem->get_contents( $path );
- return is_string( $contents ) && '' !== $contents && self::defines_present( $contents );
- }
-
- /**
- * Write fresh salts into wp-config.php via an atomic temp-file swap. No
- * backup file is left in the document root — a readable wp-config.php.bak
- * would expose DB credentials. Clears the weak-salt notice on success.
+ * Verify salts after a manual edit and clear the notice if they are now strong.
+ * The running AJAX request has already reloaded wp-config.php, so the runtime
+ * constants are authoritative and cover environment- or include-provided salts
+ * that never appear as a literal define(). The located wp-config.php text is a
+ * secondary signal only.
*
* @return array{ok:bool,message:string}
*/
- public static function apply_salt_fix(): array {
- $path = self::locate_wp_config();
- if ( null === $path ) {
- return [
- 'ok' => false,
- 'message' => __( 'Could not locate wp-config.php.', 'magicauth' ),
- ];
- }
- $filesystem = self::filesystem();
- if ( null === $filesystem || ! $filesystem->is_writable( $path ) ) {
- return [
- 'ok' => false,
- 'message' => __( 'wp-config.php is not writable on this server. Use the manual copy-and-paste option instead.', 'magicauth' ),
- ];
- }
- $original = $filesystem->get_contents( $path );
- if ( ! is_string( $original ) || '' === $original ) {
- return [
- 'ok' => false,
- 'message' => __( 'Could not read wp-config.php.', 'magicauth' ),
- ];
- }
- $updated = self::rewrite_salt_defines( $original, self::salt_values() );
- if ( null === $updated ) {
- return [
- 'ok' => false,
- 'message' => __( 'wp-config.php does not contain the expected salt definitions. Use the manual copy-and-paste option instead.', 'magicauth' ),
- ];
- }
- // Safety gate: result must still be PHP and must no longer look weak.
- if ( 0 !== strpos( ltrim( $updated ), ' false,
- 'message' => __( 'The generated configuration failed a safety check, so nothing was written.', 'magicauth' ),
- ];
- }
- // Preserve the original file mode across the swap: move() uses rename(),
- // so the destination would otherwise inherit the temp file's perms and
- // silently widen a hardened wp-config.php (e.g. 0600 -> 0644). Applying
- // the original mode to the temp before the move also keeps the brief
- // temp-file window no more readable than the file it replaces.
- $mode = $filesystem->getchmod( $path );
-
- $temp = dirname( $path ) . '/.magicauth-wpconfig-' . bin2hex( random_bytes( 8 ) ) . '.tmp';
- if ( ! $filesystem->put_contents( $temp, $updated, FS_CHMOD_FILE ) ) {
- return [
- 'ok' => false,
- 'message' => __( 'Could not write the new configuration. No changes were made.', 'magicauth' ),
- ];
- }
- if ( '' !== $mode ) {
- $filesystem->chmod( $temp, (int) octdec( $mode ) );
- }
- if ( ! $filesystem->move( $temp, $path, true ) ) {
- $filesystem->delete( $temp );
+ public static function recheck_salts_from_file(): array {
+ $ok_message = __( 'Salts look good now. You can enable the branded login replacement whenever you like.', 'magicauth' );
+
+ // Authoritative: runtime constants reflect the current file plus any
+ // environment/included salts. If they are strong, the salts are fixed.
+ if ( ! self::runtime_salts_weak() ) {
+ delete_transient( self::SALT_NOTICE_KEY );
return [
- 'ok' => false,
- 'message' => __( 'Could not replace wp-config.php. No changes were made.', 'magicauth' ),
+ 'ok' => true,
+ 'message' => $ok_message,
];
}
- delete_transient( self::SALT_NOTICE_KEY );
- magicauth_debug_log( sprintf( 'salt fix: rewrote %s by user_id=%d', $path, (int) get_current_user_id() ) );
- return [
- 'ok' => true,
- 'message' => __( 'Fresh salts written to wp-config.php. Everyone, including you, will be signed out — sign in again to continue.', 'magicauth' ),
- ];
- }
- /**
- * Re-read wp-config.php and clear the weak-salt notice if it is now clean.
- * Backs the manual copy-and-paste path, which we cannot verify from runtime
- * constants (those were loaded before the file was edited).
- *
- * @return array{ok:bool,message:string}
- */
- public static function recheck_salts_from_file(): array {
+ // Secondary: scan the located wp-config.php directly, in case this request
+ // did not pick up the edit.
$path = self::locate_wp_config();
- if ( null === $path ) {
- return [
- 'ok' => false,
- 'message' => __( 'Could not locate wp-config.php to verify.', 'magicauth' ),
- ];
- }
- $filesystem = self::filesystem();
- $contents = null !== $filesystem ? $filesystem->get_contents( $path ) : null;
- if ( ! is_string( $contents ) || '' === $contents ) {
- return [
- 'ok' => false,
- 'message' => __( 'Could not read wp-config.php to verify.', 'magicauth' ),
- ];
- }
- if ( self::config_has_weak_salts( $contents ) ) {
- return [
- 'ok' => false,
- 'message' => __( 'Still detecting placeholder or empty salts. Make sure you replaced all eight lines and saved wp-config.php.', 'magicauth' ),
- ];
+ if ( null !== $path ) {
+ $filesystem = self::filesystem();
+ $contents = null !== $filesystem ? $filesystem->get_contents( $path ) : null;
+ if ( is_string( $contents ) && '' !== $contents && ! self::config_has_weak_salts( $contents ) ) {
+ delete_transient( self::SALT_NOTICE_KEY );
+ return [
+ 'ok' => true,
+ 'message' => $ok_message,
+ ];
+ }
}
- delete_transient( self::SALT_NOTICE_KEY );
+
return [
- 'ok' => true,
- 'message' => __( 'Salts look good now. Branded login replacement is available again.', 'magicauth' ),
+ 'ok' => false,
+ 'message' => __( 'Still detecting placeholder or empty salts. Make sure you replaced all eight lines and saved wp-config.php.', 'magicauth' ),
];
}
}
diff --git a/includes/Plugin.php b/includes/Plugin.php
index d62c6a3..23d6134 100644
--- a/includes/Plugin.php
+++ b/includes/Plugin.php
@@ -45,6 +45,10 @@ public function boot(): void {
add_action( 'admin_notices', [ Installer::class, 'render_salt_notice' ] );
add_action( 'admin_notices', [ Installer::class, 'render_fpm_notice' ] );
+ // Re-evaluate salt strength on each admin load so the notice tracks reality
+ // (e.g. salts provided by the environment, or fixed by hand outside the wizard).
+ add_action( 'admin_init', [ Installer::class, 'check_salts' ] );
+
Auth\Controller::setup();
Frontend\Shortcode::setup();
Frontend\LoginScreen::setup();
diff --git a/magicauth.php b/magicauth.php
index 21db5cb..e1dd000 100644
--- a/magicauth.php
+++ b/magicauth.php
@@ -3,7 +3,7 @@
* Plugin Name: MagicAuth
* Plugin URI: https://github.com/EtticDevelopment/magicauth
* Description: Passwordless WordPress sign-in via email magic link or 6-character code.
- * Version: 1.0.0
+ * Version: 1.0.1
* Requires at least: 6.4
* Requires PHP: 8.0
* Author: Ettic
@@ -26,7 +26,7 @@
return;
}
-define( 'MAGICAUTH_VERSION', '1.0.0' );
+define( 'MAGICAUTH_VERSION', '1.0.1' );
define( 'MAGICAUTH_DB_VERSION', 1 );
define( 'MAGICAUTH_FILE', __FILE__ );
define( 'MAGICAUTH_DIR', plugin_dir_path( __FILE__ ) );
diff --git a/readme.txt b/readme.txt
index 905f51e..66289df 100644
--- a/readme.txt
+++ b/readme.txt
@@ -4,7 +4,7 @@ Tags: login, passwordless, magic link, authentication, security
Requires at least: 6.4
Tested up to: 7.0
Requires PHP: 8.0
-Stable tag: 1.0.0
+Stable tag: 1.0.1
License: GPL-2.0-or-later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
@@ -60,6 +60,10 @@ Three layers, in order of effort:
2. Append `?magicauth=off` to your `wp-login.php` URL.
3. Add `define('MAGICAUTH_DISABLE', true);` to `wp-config.php` (file-system access required).
+= MagicAuth says my WordPress salts (security keys) are weak. What do I do? =
+
+Generate fresh keys at https://api.wordpress.org/secret-key/1.1/salt/, paste the eight `define()` lines into `wp-config.php` (replacing the existing ones), save, and reload the MagicAuth settings page. The notice clears itself. It is advisory and does not block the branded login screen. Full guide: https://docs.ettic.nl/docs/magicauth/weak-salts
+
= Does MagicAuth replace passwords? =
By default, no. Passwords still work. Enable "Replace default sign-in" in Settings to make MagicAuth the primary sign-in surface; the password link remains visible for recovery.
@@ -71,3 +75,14 @@ Yes. Templates can be overridden by copying them into `your-theme/magicauth/`. F
== Privacy ==
MagicAuth registers a WordPress privacy exporter and eraser. Personal data stored is limited to: `user_id`, an HMAC of the user's email and IP, and timestamps for each sign-in attempt. Verifiers are not exportable; only metadata about issued/consumed tokens.
+
+== Changelog ==
+
+= 1.0.1 =
+* The weak-salt helper no longer edits `wp-config.php`. It generates a ready-to-paste block of fresh keys and links to a step-by-step guide; you paste and save. This removes any risk of the plugin corrupting your site configuration.
+* Fresh salts are generated locally with `random_bytes` and are never fetched over the network.
+* Weak-salt detection now reads your live security keys, so managed and environment-based hosts (Bedrock, WP Engine, Pantheon) are no longer falsely flagged, and the notice clears itself once the keys are strong.
+* The weak-salt notice is now advisory: the branded login screen can be enabled with an informed-consent warning instead of being hard-blocked.
+
+= 1.0.0 =
+* Initial release.
diff --git a/tests/phpunit/Model/SaltFixTest.php b/tests/phpunit/Model/SaltFixTest.php
index fd5aa69..a508fd5 100644
--- a/tests/phpunit/Model/SaltFixTest.php
+++ b/tests/phpunit/Model/SaltFixTest.php
@@ -1,9 +1,10 @@
assertFalse( Installer::config_has_weak_salts( $block ), 'A freshly generated block is not weak.' );
}
+ public function test_generated_block_is_locally_random(): void {
+ // Local generation only: two blocks must differ (no fixed or remote source).
+ $this->assertNotSame( Installer::generate_salt_block(), Installer::generate_salt_block() );
+ }
+
public function test_placeholder_config_reads_as_weak(): void {
$this->assertTrue( Installer::config_has_weak_salts( $this->placeholder_config() ) );
}
@@ -82,54 +79,32 @@ public function test_missing_define_reads_as_weak(): void {
$this->assertTrue( Installer::config_has_weak_salts( $config ) );
}
- public function test_rewrite_replaces_placeholders_with_strong_salts(): void {
- $original = $this->placeholder_config();
- $updated = Installer::rewrite_salt_defines( $original, $this->strong_values() );
-
- $this->assertIsString( $updated );
- $this->assertFalse( Installer::config_has_weak_salts( $updated ) );
- $this->assertStringNotContainsString( 'put your unique phrase here', $updated );
- // Unrelated lines survive untouched.
- $this->assertStringContainsString( "define( 'DB_NAME', 'wordpress' );", $updated );
- $this->assertStringContainsString( "\$table_prefix = 'wp_';", $updated );
- // Still eight defines for the salt constants.
+ public function test_strong_config_reads_as_clean(): void {
+ $lines = [ 'assertStringContainsString( "define( '" . $name . "',", $updated );
+ $lines[] = "define( '" . $name . "', '" . Installer::generate_salt_value() . "' );";
}
+ $this->assertFalse( Installer::config_has_weak_salts( implode( "\n", $lines ) ) );
}
- public function test_rewrite_returns_null_when_a_define_is_missing(): void {
- $config = "assertNull( Installer::rewrite_salt_defines( $config, $this->strong_values() ) );
- }
-
- public function test_rewrite_and_detection_ignore_commented_define_lines(): void {
- // A commented example sits above the real (placeholder) define. The first
- // match must be the active define, not the comment.
+ public function test_detection_ignores_commented_define_lines(): void {
+ // A commented, strong-looking define sits above the active placeholder
+ // defines. Detection must read the active defines (weak), not the comment.
$lines = [ 'assertTrue( Installer::config_has_weak_salts( $config ) );
-
- $updated = Installer::rewrite_salt_defines( $config, $this->strong_values() );
- $this->assertIsString( $updated );
- $this->assertFalse( Installer::config_has_weak_salts( $updated ) );
- // The commented line is left verbatim; the active define is what changed.
- $this->assertStringContainsString( "// define( 'AUTH_KEY', 'commented-old-value' );", $updated );
- $this->assertStringNotContainsString( 'put your unique phrase here', $updated );
+ $this->assertTrue( Installer::config_has_weak_salts( implode( "\n", $lines ) ) );
}
- public function test_rewrite_handles_double_quotes_and_tight_spacing(): void {
- $lines = [ 'strong_values() );
- $this->assertIsString( $updated );
- $this->assertFalse( Installer::config_has_weak_salts( $updated ) );
+ $this->assertTrue( Installer::config_has_weak_salts( implode( "\n", $weak ) ) );
+ $this->assertFalse( Installer::config_has_weak_salts( implode( "\n", $strong ) ) );
}
}
From cfef2e5963776c5e19c72edf28d00f8a8bfe8db5 Mon Sep 17 00:00:00 2001
From: Nol de Roos <108540791+nolderoos@users.noreply.github.com>
Date: Fri, 22 May 2026 01:59:48 +0200
Subject: [PATCH 2/2] chore: ship as 1.0.0 (initial release)
---
magicauth.php | 4 ++--
readme.txt | 8 +-------
2 files changed, 3 insertions(+), 9 deletions(-)
diff --git a/magicauth.php b/magicauth.php
index e1dd000..21db5cb 100644
--- a/magicauth.php
+++ b/magicauth.php
@@ -3,7 +3,7 @@
* Plugin Name: MagicAuth
* Plugin URI: https://github.com/EtticDevelopment/magicauth
* Description: Passwordless WordPress sign-in via email magic link or 6-character code.
- * Version: 1.0.1
+ * Version: 1.0.0
* Requires at least: 6.4
* Requires PHP: 8.0
* Author: Ettic
@@ -26,7 +26,7 @@
return;
}
-define( 'MAGICAUTH_VERSION', '1.0.1' );
+define( 'MAGICAUTH_VERSION', '1.0.0' );
define( 'MAGICAUTH_DB_VERSION', 1 );
define( 'MAGICAUTH_FILE', __FILE__ );
define( 'MAGICAUTH_DIR', plugin_dir_path( __FILE__ ) );
diff --git a/readme.txt b/readme.txt
index 66289df..fa6de92 100644
--- a/readme.txt
+++ b/readme.txt
@@ -4,7 +4,7 @@ Tags: login, passwordless, magic link, authentication, security
Requires at least: 6.4
Tested up to: 7.0
Requires PHP: 8.0
-Stable tag: 1.0.1
+Stable tag: 1.0.0
License: GPL-2.0-or-later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
@@ -78,11 +78,5 @@ MagicAuth registers a WordPress privacy exporter and eraser. Personal data store
== Changelog ==
-= 1.0.1 =
-* The weak-salt helper no longer edits `wp-config.php`. It generates a ready-to-paste block of fresh keys and links to a step-by-step guide; you paste and save. This removes any risk of the plugin corrupting your site configuration.
-* Fresh salts are generated locally with `random_bytes` and are never fetched over the network.
-* Weak-salt detection now reads your live security keys, so managed and environment-based hosts (Bedrock, WP Engine, Pantheon) are no longer falsely flagged, and the notice clears itself once the keys are strong.
-* The weak-salt notice is now advisory: the branded login screen can be enabled with an informed-consent warning instead of being hard-blocked.
-
= 1.0.0 =
* Initial release.