Skip to content

Salt notice: detection-only, dismissible, links to docs - #14

Merged
r00bbert merged 1 commit into
mainfrom
chore/salt-detection-only-notice
May 22, 2026
Merged

r00bbert merged 1 commit into
mainfrom
chore/salt-detection-only-notice

Conversation

@r00bbert

@r00bbert r00bbert commented May 22, 2026 •

Copy link
Copy Markdown
Contributor

What

Reworks the weak-salt handling to be detection-only. Removes all salt generation and the in-plugin fix wizard; keeps detection and turns the admin notice into a site-wide dismissible advisory that links to the docs.

Why

A login plugin should not be in the business of minting the site's master secrets or rewriting/parsing wp-config.php. WordPress already ships a salt generator at api.wordpress.org/secret-key. The 1.0.0 auto-write was already removed; this removes the interim copy-paste wizard (local generation + file-scan recheck) too, leaving a purely advisory contract.

Changes

  • Installer: removed generate_salt_value / salt_values / generate_salt_block, recheck_salts_from_file, config_has_weak_salts / define_pattern, locate_wp_config / filesystem. Reworked render_salt_notice() to a single "Learn how to fix this" link → DOCS_SALTS_URL, is-dismissible, with a self-contained dismiss script (the notice renders on screens where the admin bundle isn't enqueued). Added ajax_dismiss_salt_notice(); check_salts() re-arms the dismissal if salts ever regress.
  • Settings: removed ajax_fix_salts() + its registration and the "Fix WordPress salts" diagnostics card. Informed-consent gate on the branded-login toggle is unchanged.
  • Admin JS/CSS: removed initSaltFix() and orphaned wizard styles.
  • Tests: deleted SaltFixTest (exercised the removed methods).

Dismissal model

Site-wide, not per-user: one admin dismissing sets the magicauth_salt_notice_dismissed site option and hides the notice for everyone; check_salts() clears it when salts test strong, so a future regression re-arms it.

Out of scope / untouched

Token and login-code generation (TokenManager, Crockford) are not touched. Version stays 1.0.0.

Verification

php -l on all changed PHP, node --check on the admin JS and the inline dismiss script, a reflection surface check (removed methods gone, kept methods present), and a grep sweep for dangling references — all clean. PHPUnit/PHPStan run in CI.

Summary by CodeRabbit

  • Refactor
    • Removed the automated "Fix WordPress salts" admin action; manual wp-config.php updates are required for salt remediation.
    • Weak salt warning notices are now dismissible for a cleaner admin experience.

Review Change Stack

Remove all salt generation and the in-plugin fix wizard. The plugin no
longer generates salts, reads or scans wp-config.php, or offers a "Fix
it for me" path — WordPress already ships a generator, and rewriting or
parsing the site's master config is too high blast-radius for a login
plugin.

Keep weak-salt detection (runtime constants are authoritative) and
rework the admin notice: link to the docs guide (DOCS_SALTS_URL) rather
than api.wordpress.org directly, drop the "Fix it for me" button, and
make it site-wide dismissible. One admin dismissing hides it for all,
persisted in the magicauth_salt_notice_dismissed site option and
re-armed by check_salts() if salts ever regress to weak.

Removed:
- Installer: generate_salt_value / salt_values / generate_salt_block,
  recheck_salts_from_file, config_has_weak_salts / define_pattern,
  locate_wp_config / filesystem
- Settings: ajax_fix_salts + its wp_ajax registration, and the
  "Fix WordPress salts" diagnostics card
- admin JS: initSaltFix() wizard, plus orphaned wizard CSS
- tests: SaltFixTest (exercised the now-removed methods)

Token and login-code generation are untouched; the informed-consent
gate on the branded-login toggle is unchanged. Version stays 1.0.0.
@coderabbitai

coderabbitai Bot commented May 22, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The PR removes the automatic "Fix WordPress salts" wizard and replaces it with a simpler dismissible admin notice. This involves removing wizard handlers, UI, and JavaScript; implementing weak-salt notice dismissal via AJAX; registering the new handler; and removing related test coverage.

Changes

Replace salt-fix wizard with dismissible notice

Layer / File(s) Summary
Remove automatic salt-fix wizard UI and handlers
includes/Admin/Settings.php, assets/js/magicauth-admin.js, assets/css/magicauth-admin.css
The wp_ajax_magicauth_admin_fix_salts handler registration, weak-salts action row UI, and ajax_fix_salts() method are removed from Settings. Admin JavaScript removes salt-fix wizard initialization and its entire AJAX flow/modal/clipboard implementation. CSS rules for alert action rows and salt-block modal display are deleted.
Implement dismissible weak-salt notice with AJAX dismissal
includes/Installer.php
Two new private constants track the dismissal option key and AJAX nonce action. check_salts() clears dismissal when salts are strong again. render_salt_notice() renders a conditional, dismissible admin notice with inline JavaScript to post AJAX requests. New ajax_dismiss_salt_notice() handler validates the nonce, enforces manage_options, and persists dismissal state.
Wire dismissal handler via admin-ajax
includes/Plugin.php
Plugin::boot() registers wp_ajax_magicauth_dismiss_salt_notice action to route dismissal requests from any admin screen to Installer::ajax_dismiss_salt_notice.
Remove salt-fix test coverage
tests/phpunit/Model/SaltFixTest.php
Entire SaltFixTest class is deleted, removing tests for salt value generation, block completeness, randomness, and weak-salt detection (placeholders, empty/missing defines, comments, double-quoted formats).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • EtticDevelopment/magicauth#10: Introduced the automatic salt-fix wizard feature that this PR removes and replaces with a simpler dismissible notice pattern.

Poem

A wizard once fixed salts with flair,
But simplicity called from the air—
Now dismiss with a click,
The solution more slick,
A notice so light, lean, and fair! 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Salt notice: detection-only, dismissible, links to docs' accurately describes the main change—converting the salt-fix feature from an in-plugin wizard to a dismissible notice that links to documentation.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/salt-detection-only-notice

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@includes/Installer.php`:
- Around line 237-289: The site-wide salt warning rendered by
Installer::render_salt_notice() is suppressed on the MagicAuth settings page
because Settings::suppress_foreign_notices() removes all admin_notices on
settings_page_magicauth; to fix, either update suppress_foreign_notices() to
skip/remain notices that include a unique marker (e.g.
data-magicauth-salt-notice or a specific CSS class like magicauth-salt-notice)
so render_salt_notice() still runs on that admin screen, or change
render_salt_notice() to detect the current admin page (settings_page_magicauth)
and output an inline version of the same dismissible notice there (preserving
the nonce, AJAX route magicauth_dismiss_salt_notice and data attributes) so
admins can see/dismiss it on the settings page.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ec5a1582-e6c9-465c-9ed1-4ef40820b359

📥 Commits

Reviewing files that changed from the base of the PR and between aa1c978 and 9fe694f.

📒 Files selected for processing (6)
  • assets/css/magicauth-admin.css
  • assets/js/magicauth-admin.js
  • includes/Admin/Settings.php
  • includes/Installer.php
  • includes/Plugin.php
  • tests/phpunit/Model/SaltFixTest.php
💤 Files with no reviewable changes (3)
  • tests/phpunit/Model/SaltFixTest.php
  • assets/css/magicauth-admin.css
  • assets/js/magicauth-admin.js

Comment thread includes/Installer.php
Comment on lines +237 to +289
/**
* Admin notice for weak salts. Shown to manage_options users on every admin
* screen until the salts are fixed or an admin dismisses it. MagicAuth does
* not generate salts or edit wp-config.php; the notice points to the docs,
* where the fix is "generate at api.wordpress.org, paste into wp-config.php,
* reload". Dismissal is site-wide (one option) and persisted via the AJAX
* handler below; check_salts() re-arms it if salts ever regress. The notice
* carries a small self-contained dismiss script because it renders on admin
* screens where magicauth-admin.js is not enqueued.
*/
public static function render_salt_notice(): void {
if ( ! self::has_weak_salts() ) {
return;
}
if ( get_option( self::SALT_NOTICE_DISMISSED_OPTION ) ) {
return;
}
if ( ! function_exists( 'current_user_can' ) || ! current_user_can( 'manage_options' ) ) {
return;
}
$fix_url = add_query_arg(
[
'page' => 'magicauth',
'magicauth-fix-salts' => '1',
],
admin_url( 'options-general.php' )
);
$nonce = wp_create_nonce( self::SALT_NOTICE_DISMISS_NONCE );
?>
<div class="notice notice-warning">
<div class="notice notice-warning is-dismissible magicauth-salt-notice"
data-magicauth-salt-notice
data-nonce="<?php echo esc_attr( $nonce ); ?>"
data-ajaxurl="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>">
<p>
<strong><?php esc_html_e( 'MagicAuth: weak WordPress salts detected.', 'magicauth' ); ?></strong>
<?php esc_html_e( 'Your security keys still hold placeholder or empty values, so token and session secrets are not unique to this site. Your magic links stay safe (each carries its own random secret), but fixing this is recommended — especially before turning on the branded login replacement.', 'magicauth' ); ?>
</p>
<p>
<a href="<?php echo esc_url( $fix_url ); ?>" class="button button-primary"><?php esc_html_e( 'Fix it for me', 'magicauth' ); ?></a>
<?php
echo ' ';
echo wp_kses(
sprintf(
/* translators: 1: documentation guide URL, 2: salt generator URL */
__( 'Read the <a href="%1$s" target="_blank" rel="noopener">step-by-step guide</a>, or generate fresh salts at <a href="%2$s" target="_blank" rel="noopener">api.wordpress.org/secret-key</a> and paste them into <code>wp-config.php</code>.', 'magicauth' ),
esc_url( self::DOCS_SALTS_URL ),
'https://api.wordpress.org/secret-key/1.1/salt/'
),
[
'a' => [
'href' => true,
'target' => true,
'rel' => true,
],
'code' => [],
]
);
?>
<a href="<?php echo esc_url( self::DOCS_SALTS_URL ); ?>" class="button button-primary" target="_blank" rel="noopener"><?php esc_html_e( 'Learn how to fix this', 'magicauth' ); ?></a>
</p>
</div>
<script>
( function () {
document.addEventListener( 'click', function ( ev ) {
var dismiss = ev.target.closest ? ev.target.closest( '.notice-dismiss' ) : null;
if ( ! dismiss ) { return; }
var notice = dismiss.closest( '[data-magicauth-salt-notice]' );
if ( ! notice ) { return; }
fetch( notice.getAttribute( 'data-ajaxurl' ), {
method: 'POST',
credentials: 'same-origin',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: new URLSearchParams( {
action: 'magicauth_dismiss_salt_notice',
_ajax_nonce: notice.getAttribute( 'data-nonce' )
} )
} );
} );
} )();
</script>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

This notice is suppressed on the MagicAuth settings screen.

Settings::suppress_foreign_notices() removes all admin_notices callbacks on settings_page_magicauth, so this "site-wide" notice never renders on the page where admins are most likely to fix or dismiss it. That leaves only the inline branding tooltip there, with no dismiss control. Please either exempt MagicAuth’s own notices from that suppression or render this notice inline on the settings page too.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@includes/Installer.php` around lines 237 - 289, The site-wide salt warning
rendered by Installer::render_salt_notice() is suppressed on the MagicAuth
settings page because Settings::suppress_foreign_notices() removes all
admin_notices on settings_page_magicauth; to fix, either update
suppress_foreign_notices() to skip/remain notices that include a unique marker
(e.g. data-magicauth-salt-notice or a specific CSS class like
magicauth-salt-notice) so render_salt_notice() still runs on that admin screen,
or change render_salt_notice() to detect the current admin page
(settings_page_magicauth) and output an inline version of the same dismissible
notice there (preserving the nonce, AJAX route magicauth_dismiss_salt_notice and
data attributes) so admins can see/dismiss it on the settings page.

@r00bbert
r00bbert merged commit eb3f087 into main May 22, 2026
14 checks passed
@r00bbert
r00bbert deleted the chore/salt-detection-only-notice branch May 22, 2026 00:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants