From 10757304d09eaaff3e3ab25beee977d7ebb744d1 Mon Sep 17 00:00:00 2001 From: Nol de Roos <108540791+nolderoos@users.noreply.github.com> Date: Fri, 22 May 2026 01:53:44 +0200 Subject: [PATCH 1/2] fix: replace salt auto-write with guided paste + docs (1.0.1) The "Fix WordPress salts" wizard previously rewrote wp-config.php directly (atomic temp-swap, plus a 1.0.1-era in-place fallback). Rewriting the site's master config file is too high blast-radius for a login plugin: a mid-write failure could fatal the whole site with no backup. Remove the auto-write entirely and keep the safe parts. - Installer: drop apply_salt_fix, salt_autofix_available, rewrite_salt_defines, defines_present and fetch_salts_from_api. Salts are now generated locally with random_bytes only (never fetched over the network) and shown for the admin to paste. The notice, paste block and recheck remain. - Detection is now runtime-authoritative: runtime_salts_weak() reads the loaded constants and check_salts() runs on admin_init, so environment/managed hosts (Bedrock, WP Engine, Pantheon) are no longer falsely flagged and the notice self-heals once the salts are strong. - Branded-login gate softened from a hard block to an informed-consent warning: a known salt cannot forge a MagicAuth link/code (the verifier plaintext is random 256-bit) and the toggle is never re-checked at runtime, so the block only locked correctly-configured sites out of the feature. - Notice, wizard and the toggle tooltip link to a new guide at docs.ettic.nl/docs/magicauth/weak-salts. - Tests updated for the removed methods (logic re-validated); version -> 1.0.1; readme changelog and FAQ entry added; decisions.md updated. Supersedes #12. --- assets/js/magicauth-admin.js | 35 +--- includes/Admin/Settings.php | 55 +++--- includes/Installer.php | 293 +++++++--------------------- includes/Plugin.php | 4 + magicauth.php | 4 +- readme.txt | 17 +- tests/phpunit/Model/SaltFixTest.php | 73 +++---- 7 files changed, 142 insertions(+), 339 deletions(-) diff --git a/assets/js/magicauth-admin.js b/assets/js/magicauth-admin.js index faa9a12..4681f4b 100644 --- a/assets/js/magicauth-admin.js +++ b/assets/js/magicauth-admin.js @@ -720,37 +720,14 @@ ''; - // Open the wizard for the writable (auto-write) case. - function openAutoWrite() { - showConfirm( { - title: 'Fix WordPress salts', - lede: 'wp-config.php is writable, so MagicAuth can update it for you.', - body: effects + '

A backup is not left in the web root (it would expose your database credentials); the file is replaced atomically instead.

', - confirmText: 'Generate & write salts', - cancelText: 'Cancel', - onConfirm: function () { - return post( 'apply' ).then( function ( payload ) { - if ( ! payload || ! payload.success ) { - showToast( { type: 'error', message: ( payload && payload.data && payload.data.message ) || 'Could not write wp-config.php.' } ); - return; - } - showToast( { type: 'success', message: payload.data.message || 'Salts updated. Signing you out…' } ); - setTimeout( function () { window.location.reload(); }, 1800 ); - } ).catch( function () { - showToast( { type: 'error', message: 'Network error. Please try again.' } ); - } ); - } - } ); - } - - // Open the wizard for the manual (copy-and-paste) case. + // Open the salt-fix wizard: hand the admin fresh salts to paste in. function openManual( block ) { var body = effects + - '

wp-config.php is not writable from PHP on this server, so copy these lines and replace the matching salt lines in wp-config.php, then save it:

' + + '

Copy these freshly generated salts and replace the matching define() lines in wp-config.php, then save the file. Need a hand? Read the step-by-step guide.

' + '' + ''; @@ -801,11 +778,7 @@ showToast( { type: 'error', message: ( payload && payload.data && payload.data.message ) || 'Could not start the wizard.' } ); return; } - if ( payload.data.writable ) { - openAutoWrite(); - } else { - openManual( payload.data.block || '' ); - } + openManual( payload.data.block || '' ); } ).catch( function () { setLoading( btn, false ); showToast( { type: 'error', message: 'Network error. Please try again.' } ); diff --git a/includes/Admin/Settings.php b/includes/Admin/Settings.php index 769d6bb..75a500f 100644 --- a/includes/Admin/Settings.php +++ b/includes/Admin/Settings.php @@ -250,13 +250,14 @@ private static function render_section_diagnostics(): void {
+ data-nonce="" + data-docs="">

-

+

+

@@ -553,7 +556,7 @@ public static function field_replace_default( bool $weak_salts = false ): void {
@@ -822,13 +825,12 @@ public static function ajax_reset_throttle(): void { } /** - * AJAX: salt-fix wizard ("Fix WordPress salts"). Three modes: - * - preview: report whether wp-config.php is auto-writable; if not, return a - * ready-to-paste block of fresh salts for the manual path. - * - apply: rewrite wp-config.php in place with fresh salts. - * - recheck: re-read wp-config.php and clear the notice if it is now clean - * (used after the admin pastes salts manually). - * Never auto-enables the branded login replacement — only clears the block. + * AJAX: salt-fix helper ("Fix WordPress salts"). Two modes: + * - preview: return a ready-to-paste block of freshly generated salts. + * - recheck: re-evaluate the salts and clear the notice once they are strong + * (used after the admin pastes the salts into wp-config.php). + * MagicAuth never writes wp-config.php itself, and never auto-enables the + * branded login replacement. */ public static function ajax_fix_salts(): void { check_ajax_referer( 'magicauth-admin-recovery' ); @@ -841,15 +843,6 @@ public static function ajax_fix_salts(): void { $mode = sanitize_key( wp_unslash( $_POST['mode'] ) ); } - if ( 'apply' === $mode ) { - $result = Installer::apply_salt_fix(); - if ( ! $result['ok'] ) { - wp_send_json_error( [ 'message' => $result['message'] ] ); - } - magicauth_debug_log( sprintf( 'admin recovery: fix_salts apply by user_id=%d', (int) get_current_user_id() ) ); - wp_send_json_success( [ 'message' => $result['message'] ] ); - } - if ( 'recheck' === $mode ) { $result = Installer::recheck_salts_from_file(); if ( ! $result['ok'] ) { @@ -858,13 +851,11 @@ public static function ajax_fix_salts(): void { wp_send_json_success( [ 'message' => $result['message'] ] ); } - // Default: preview. - $writable = Installer::salt_autofix_available(); + // Default: preview. MagicAuth never edits wp-config.php; it generates a + // fresh block of salts for the admin to paste in themselves. wp_send_json_success( [ - 'writable' => $writable, - // Only hand the browser fresh salts when it actually needs them to paste. - 'block' => $writable ? '' : Installer::generate_salt_block(), + 'block' => Installer::generate_salt_block(), ] ); } diff --git a/includes/Installer.php b/includes/Installer.php index 4c508bb..8d3796c 100644 --- a/includes/Installer.php +++ b/includes/Installer.php @@ -28,6 +28,9 @@ final class Installer { /** Substrings that mark a salt as the shipped wp-config-sample placeholder. */ private const PLACEHOLDER_MARKERS = [ 'put your unique phrase here' ]; + /** Canonical documentation page that walks an admin through fixing weak salts. */ + public const DOCS_SALTS_URL = 'https://docs.ettic.nl/docs/magicauth/weak-salts'; + /** Activation: schema, defaults, cron, salt check. Order matters. */ public static function activate(): void { self::install_schema(); @@ -141,28 +144,45 @@ public static function default_settings(): array { } /** - * Detect placeholder salts in wp-config. Sets transient picked up by admin - * notice. Never blocks activation; only refuses replace_default. + * True when the live wp_salt() inputs are weak: any of the eight constants is + * undefined, empty, or still the shipped placeholder. Reads the runtime + * constants, so it reflects whatever wp-config.php (plus any environment- or + * include-provided salts) actually loaded for this request — the authoritative + * source of truth, and correct for managed hosts (Bedrock, WP Engine, Pantheon) + * that define salts outside a literal wp-config.php define(). */ - public static function check_salts(): void { + private static function runtime_salts_weak(): bool { foreach ( self::SALT_CONSTANTS as $constant ) { $value = defined( $constant ) ? constant( $constant ) : ''; if ( ! is_string( $value ) || '' === $value ) { - set_transient( self::SALT_NOTICE_KEY, 1, WEEK_IN_SECONDS ); - return; + return true; } foreach ( self::PLACEHOLDER_MARKERS as $marker ) { if ( false !== stripos( $value, $marker ) ) { - set_transient( self::SALT_NOTICE_KEY, 1, WEEK_IN_SECONDS ); - return; + return true; } } } + return false; + } - delete_transient( self::SALT_NOTICE_KEY ); + /** + * Keep the weak-salt admin-notice transient in sync with runtime reality. + * Runs on activation and on every admin_init, so a site whose salts are + * provided by the environment, or fixed outside the wizard, clears the notice + * on its own without a false "still weak" nag. Writes only on a state change. + */ + public static function check_salts(): void { + $weak = self::runtime_salts_weak(); + $flagged = (bool) get_transient( self::SALT_NOTICE_KEY ); + if ( $weak && ! $flagged ) { + set_transient( self::SALT_NOTICE_KEY, 1, WEEK_IN_SECONDS ); + } elseif ( ! $weak && $flagged ) { + delete_transient( self::SALT_NOTICE_KEY ); + } } - /** Settings::sanitize uses this to refuse replace_default=true. */ + /** Whether the weak-salt notice is raised. Drives the notice and the toggle warning. */ public static function has_weak_salts(): bool { return (bool) get_transient( self::SALT_NOTICE_KEY ); } @@ -211,10 +231,10 @@ public static function render_salt_notice(): void { admin_url( 'options-general.php' ) ); ?> -
+

- +

@@ -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.