Skip to content

fix: replace salt auto-write with guided paste + docs (1.0.1) - #13

Merged
r00bbert merged 2 commits into
mainfrom
fix/remove-salt-autowrite
May 22, 2026
Merged

r00bbert merged 2 commits into
mainfrom
fix/remove-salt-autowrite

Conversation

@r00bbert

@r00bbert r00bbert commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

What

Removes the salt auto-write (the code that rewrote wp-config.php for the user) and replaces it with a guided copy-and-paste flow plus a dedicated documentation guide. Ships as 1.0.1 and supersedes #12.

Why

The wizard rewrote the site's master config file. The shipped 1.0.0 path used an atomic temp-swap; #12 proposed an in-place put_contents fallback for locked-directory hosts. A security review (and a follow-up advisory council) concluded that an auth plugin rewriting wp-config.php is the wrong risk/reward for a single-site v1: a mid-write failure can truncate the file and fatal the whole site, with no backup and no rollback. The manual paste path already existed and is the safe contract.

The review also found two adjacent issues, both fixed here:

  • Network provenance: salts were fetched API-first from api.wordpress.org with no length floor (a tampered response could write weak salts). Now generated locally with random_bytes only.
  • False positives: env/managed hosts (Bedrock, WP Engine, Pantheon) were falsely flagged weak and locked out of the branded-login toggle.

Changes

  • Remove the auto-write. Drop apply_salt_fix, salt_autofix_available, rewrite_salt_defines, defines_present, fetch_salts_from_api. Keep detection, the admin notice, the paste block, and recheck.
  • Local-only salts. salt_values() generates with random_bytes; nothing is sent over the network.
  • Runtime-authoritative detection. runtime_salts_weak() reads the loaded constants; check_salts() runs on admin_init and self-heals the notice. Env/managed hosts are no longer falsely flagged.
  • Informed-consent gate. replace_default is allowed with a non-blocking warning instead of a hard block (a known salt can't forge a MagicAuth link/code, and the toggle is never re-checked at runtime).
  • Docs. Notice/wizard/tooltip link to docs.ettic.nl/docs/magicauth/weak-salts (added in the docs repo).
  • Tests updated; 1.0.1; readme changelog + FAQ; _dev/decisions.md updated.

Verification

  • php -l clean on all changed files; JS node --check clean.
  • Pure salt-generation/detection logic re-validated (15/15 assertions) against the real Installer.php. PHPUnit/PHPStan can't run on this local PHP 8.5 box (they bail silently); CI runs them on a supported PHP.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Manual copy/paste salt-fix wizard flow for WordPress configuration
  • Improvements

    • Settings remain available when salts are weak; warnings provided instead of blocking functionality
    • Enhanced salt detection based on actual runtime environment values
    • Updated wizard instructions and guidance text
  • Documentation

    • Added FAQ entry addressing weak WordPress salt remediation
    • Improved documentation links in admin interface

Review Change Stack

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

coderabbitai Bot commented May 21, 2026 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 55223d3f-b54c-4659-99c0-f524e33da56e

📥 Commits

Reviewing files that changed from the base of the PR and between 1075730 and cfef2e5.

📒 Files selected for processing (1)
  • readme.txt

📝 Walkthrough

Walkthrough

This PR shifts the WordPress salts security fix workflow from automatic wp-config.php rewriting to a runtime-first verification approach with advisory notices and manual copy/paste. Detection now validates the actual WordPress constants at each admin load, settings forms offer warnings instead of blocking, and the wizard always displays locally-generated salts for manual insertion.

Changes

WordPress Salts Advisory & Manual Fix

Layer / File(s) Summary
Runtime Salt Detection Foundation
includes/Installer.php, includes/Plugin.php
New runtime_salts_weak() validates all eight WordPress salt constants for undefined/empty/placeholder values. check_salts() uses this to set/delete weak-salt transient. Plugin::boot() registers admin_init hook to re-evaluate salts on every admin page load.
Weak-Salt Notice & User Documentation
includes/Installer.php, readme.txt
Updated admin notice with documentation link from new DOCS_SALTS_URL constant. Added FAQ entry explaining weak-salt detection and manual fix steps. Added changelog entry for initial release.
Settings Form & AJAX Handler Updates
includes/Admin/Settings.php
replace_default option now saves user choice with warning when weak salts detected, instead of disabling the setting. Login-screen checkbox enabled when salts weak. Updated AJAX handler doc comments and preview response to always return generated salt block instead of conditionally returning empty.
Manual Salt Generation & Wizard UI
includes/Installer.php, assets/js/magicauth-admin.js
salt_values() simplified to local-only generation via random_bytes and base64, removing remote API fallback. Wizard instruction text updated for branded login and manual paste guidance. openWizard() now always opens manual copy/paste modal instead of conditionally choosing auto-write path.
Removed Auto-Write Capabilities
includes/Installer.php
Deleted defines_present() file-scanning helper and rewrite_salt_defines() public method that previously rewrote wp-config.php. Rewrote recheck_salts_from_file() to prioritize runtime verification, optionally reading wp-config.php only if runtime still appears weak.
Test Coverage Realignment
tests/phpunit/Model/SaltFixTest.php
Updated file documentation to emphasize file-I/O-free architecture. Removed test cases for salt rewriting. Added tests validating generation randomness, strong-config detection, and robust weak-salt detection across commented-out and double-quoted define() formats.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • EtticDevelopment/magicauth#10: Directly overlaps with the same wizard rework, AJAX handler modes, and Installer salt-fix/detection refactoring from file-scanning + auto-write to runtime verification + manual paste.

Poem

🐰 Salts once locked the settings tight,
Auto-writes that felt not quite right.
Now we peek at runtime truth,
And guide with gentle, patient proof—
Copy, paste, and the admin sees the light. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% 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 pull request title directly and specifically summarizes the main change: removing auto-write functionality and replacing it with a guided copy-paste flow plus documentation links, with the version bump clearly indicated.
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 unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/remove-salt-autowrite

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

@r00bbert
r00bbert merged commit aa1c978 into main May 22, 2026
13 checks passed
@r00bbert
r00bbert deleted the fix/remove-salt-autowrite branch May 22, 2026 00:00
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