Repository navigation
Keep reset links working in Send to me copies - #219
Conversation
1.11.0 replaced every key= and confirm_key= link value with [redacted] before saving, so a copy of a password reset, "set your password" or privacy confirmation email had a dead link, and flows for test customers could not be tested from a copy. - The message is still stored masked, so the list, search, popup, Raw and JSON never show a key. The original values are stored apart, in a new secrets column, and are never shown, searched or logged. - Send to me puts them back, in order, only for users who can already set any user's password: edit_users on a single site, super admins on multisite. Any mismatch sends the masked copy. - Keys are never stored for emails to administrators: anyone can request an administrator's reset, which Safety Net lets through, and the administrators got the email itself. - DB_VERSION 2 adds the column to 1.11.0 tables with ALTER TABLE, once, and logs without keys if that fails. Old entries stay masked. Refs #126. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
🔱 Poseidon started reviewing this PR — central run. |
| ); | ||
|
|
||
| // Anyone can request an administrator's password reset, so a stored key would let whoever reads the database take over that account. | ||
| $secrets = $has_secrets && $keys && ! is_sent_to_an_admin( $args ) ? wp_json_encode( $keys ) : false; |
There was a problem hiding this comment.
The new guard ! is_sent_to_an_admin( $args ) keeps keys out of the table only for administrators, so reset and set-password keys for other privileged accounts are still stored, e.g. WooCommerce's shop_manager (which can manage orders and edit customers) or an editor created on the staging site. Anyone can request a reset for those users from the login page too, so the threat this guard is written for applies to them in the same way: whoever can read the database (a vulnerable plugin, a backup, a copy) can take over that account until the key expires. Consider storing keys only when no recipient has elevated capabilities, e.g. by checking each recipient's user with user_can( $user, 'edit_posts' ) or 'manage_woocommerce' next to the administrator check. Or narrow the README's guarantee so it says that only administrators' keys are left out.
🤖 Fix prompt for AI agents
Verify each finding against the current code and only fix it if
needed.
In `includes/email-log.php`:
- Line 288: The assignment `$secrets = $has_secrets && $keys &&
! is_sent_to_an_admin( $args ) ? wp_json_encode( $keys ) : false;`
in `log_email()` skips storing keys only when a To, Cc or Bcc
recipient is an administrator, so reset keys for other privileged
users (WooCommerce shop_manager, editor, any role with edit_users or
manage_woocommerce created on staging) are still saved in the
secrets column; anyone can request their reset on the login page,
so a database reader can take over those accounts until the key
expires. Extend the check, e.g. a helper next to
`is_sent_to_an_admin()` in includes/admin.php that looks up each
address from `get_all_recipients()` with `get_user_by( 'email' )`
and returns true when the user has elevated capabilities. Keep the
existing administrator check, the TEXT_BYTES length guard and the
separate UPDATE after the insert unchanged. If you keep the current
behaviour on purpose, update README.md so it says that only
administrators' keys are left out.
There was a problem hiding this comment.
🔱 Poseidon Review
Summary: Saves the key= and confirm_key= values apart from the redacted message, in a new secrets column, so Send to me can put them back for users who can already set passwords. It also adds a DB_VERSION 2 migration. Risk is low: every path I traced keeps the keys out of the list, the search, JSON, Raw and the AJAX output, and the migration fails closed.
Walkthrough
- ✨ New:
secretscolumn (DB_VERSION 2) andrestore_keys()/can_restore_keys(), so Send to me copies can have working reset and confirmation links; asent-with-keysnotice and a per-entrycopy_note(). - ♻️ Refactor:
get_all_recipients()is pulled out ofis_sent_only_to_admins()and shared with the newis_sent_to_an_admin();KEY_PATTERNandREDACTEDconstants. - 🧪 Tests: E34/E34b key storage and restore, E3d–E3g upgrade and failure paths, M15 on multisite.
- 📝 Docs: README and AGENTS.md describe the stored keys, who gets them back and the migration.
🟡 Suggestions
- includes/email-log.php:L288: Only administrator recipients are kept out of key storage, so reset keys for other privileged users created on staging (WooCommerce
shop_manager,editor) are stored and can be read from the database. Those users face the same takeover risk the guard is written for. Extend the check to other elevated capabilities, or narrow the README's guarantee so it covers administrators only.
🤖 Prompt for AI agents — fix all findings
Verify each finding against the current code and only fix it if
needed.
Suggestions:
In `includes/email-log.php`:
- Line 288: The assignment `$secrets = $has_secrets && $keys &&
! is_sent_to_an_admin( $args ) ? wp_json_encode( $keys ) : false;`
in `log_email()` skips storing keys only when a To, Cc or Bcc
recipient is an administrator, so reset keys for other privileged
users (WooCommerce shop_manager, editor, any role with edit_users or
manage_woocommerce created on staging) are still saved in the
secrets column; anyone can request their reset on the login page,
so a database reader can take over those accounts until the key
expires. Extend the check, e.g. a helper next to
`is_sent_to_an_admin()` in includes/admin.php that looks up each
address from `get_all_recipients()` with `get_user_by( 'email' )`
and returns true when the user has elevated capabilities. Keep the
existing administrator check, the TEXT_BYTES length guard and the
separate UPDATE after the insert unchanged. If you keep the current
behaviour on purpose, update README.md so it says that only
administrators' keys are left out.
ℹ️ Review info
- Commit: bdbf81e
- Files reviewed: includes/email-log.php, includes/admin.php, README.md, AGENTS.md
- Files skipped: tests/smoke/fixtures/mu-plugins/00-sn-test-helper.php, tests/smoke/fixtures/php/seed.php, tests/smoke/scenarios.mjs, tests/smoke/scenarios/email-log.test.mjs, tests/smoke/scenarios/multisite-main-first.test.mjs (test fixtures and scenarios, not shipped; skimmed only for what they cover)
- Model: claude-opus-5-5
Keys were left out only for administrators. Anyone can request a password reset for an editor or a shop manager created on the staging site too, so a stored key would let a database reader take over those accounts until it expires. Keys are now left out when any recipient is an administrator or can edit_posts or manage_woocommerce; customers' and subscribers' emails still keep them. Refs #126. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🔱 Poseidon Review
Summary: Stores key= and confirm_key= values apart from the redacted message so Send to me can restore them for users who can already set passwords. The latest push extends the no-store rule from administrators to every staff account (edit_posts or manage_woocommerce). Risk is low; the only things left are two small wording issues.
Walkthrough
- ✨ New:
secretscolumn (DB_VERSION 2),restore_keys()/can_restore_keys(), asent-with-keysnotice and a per-entrycopy_note(). - 🐛 Fix:
is_sent_to_an_admin()→is_sent_to_staff(), so keys are no longer stored for emails to editors, contributors, authors or shop managers. - 🧪 Tests: E34/E34b/E34c key storage and restore, E3d–E3g upgrade and failure paths, M15 on multisite.
- 📝 Docs: README and AGENTS.md describe the staff rule.
💡 Nitpicks (2)
- includes/email-log.php:L1813: The
copy_note()text says staff accounts "got the email itself". That is only true for administrators. WhileSAFETY_NET_DELETE_DATAkeeps data,stop_emails()blocks a Password Reset whenever any recipient is not an administrator, so an editor or shop manager never received it. Reword it so it doesn't claim delivery for non-admin staff. - includes/email-log.php:L287: The comment above the
$secretsassignment still mentions only "an administrator's password reset", but the guard now covers every staff account. Update it to matchis_sent_to_staff().
🤖 Prompt for AI agents — fix all findings
Verify each finding against the current code and only fix it if
needed.
Nitpicks:
In `includes/email-log.php`:
- Line 1813: In `copy_note()`, the string returned when
`null === $restored && is_entry_to_staff( $entry )` ends with "keys
are not stored for emails to administrators or other staff
accounts, who got the email itself." Only administrators are
guaranteed delivery: `stop_emails()` in includes/admin.php blocks a
Password Reset with status `blocked_recipients` whenever data is kept
and any recipient is not an administrator. Editors and shop managers
therefore never got the email, and the note misleads the admin
viewing the entry. Reword the translatable string so it only says
keys are not stored for staff accounts and drops the delivery claim
for non-admins (for example, "…because anyone can request a staff
account's reset"). Keep the condition, the text domain and the
surrounding note structure unchanged.
- Line 287: The comment above `$secrets = $has_secrets && $keys &&
! is_sent_to_staff( $args ) ? wp_json_encode( $keys ) : false;` in
`log_email()` still says "Anyone can request an administrator's
password reset". The guard now also covers users who can edit_posts
or manage_woocommerce, so the comment understates what it protects.
Update it to say staff accounts (administrators, content editors and
store managers). Leave the expression and the TEXT_BYTES guard below
it unchanged.
♻️ Previously flagged
Resolved
- ✅ includes/email-log.php:L288: now uses
is_sent_to_staff(), which also skips storing keys foredit_posts/manage_woocommerceusers; README updated to match
ℹ️ Review info
- Commit: 3ab2433
- Files reviewed: includes/email-log.php, includes/admin.php, README.md, AGENTS.md
- Files skipped: tests/smoke/fixtures/mu-plugins/00-sn-test-helper.php, tests/smoke/fixtures/php/seed.php, tests/smoke/scenarios.mjs, tests/smoke/scenarios/email-log.test.mjs, tests/smoke/scenarios/multisite-main-first.test.mjs (test fixtures and scenarios, not shipped; skimmed only)
- Model: claude-opus-5-5
Only administrators get their own reset emails; Safety Net blocks the others, so the entry's note and the comments now give the real reason: anyone can request a staff account's password reset. Refs #126. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🔱 Poseidon Review
Summary — The latest push only rewords the copy_note() string, the $secrets comment, the AGENTS.md text and the matching test constant, so they no longer claim that non-admin staff received the email. Both nitpicks from the last pass are closed. Risk is low and nothing new turned up.
Walkthrough
- 📝 Docs: The
copy_note()text and the comment inlog_email()now say keys are left out because anyone can request a staff account's password reset. They no longer claim that staff got the email. - 🧪 Tests:
KEYS_FOR_ADMINSinemail-log.test.mjsis updated to the new string.
💡 Nitpicks (0) · Deferred (1)
Deferred improvements
- AGENTS.md:L105: Still says "for an entry to an administrator (
is_entry_to_staff()…)". The helper now covers every staff account, so this could say "administrator or other staff account". This line has not changed since the prior review.
♻️ Previously flagged
Resolved
- ✅ includes/email-log.php:L1813: The
copy_note()string now ends "since anyone can request their password reset". The delivery claim is gone. - ✅ includes/email-log.php:L287: The comment now says "a staff account's password reset", which matches
is_sent_to_staff().
ℹ️ Review info
- Commit: f16de50
- Files reviewed: includes/email-log.php, includes/admin.php, AGENTS.md, README.md, tests/smoke/scenarios/email-log.test.mjs
- Files skipped: tests/smoke/fixtures/mu-plugins/00-sn-test-helper.php, tests/smoke/fixtures/php/seed.php, tests/smoke/scenarios.mjs, tests/smoke/scenarios/multisite-main-first.test.mjs (test fixtures and scenarios with no changes since the prior review; not shipped)
- Model: claude-opus-5-5
Resolves the overlap with #219: log_email() keeps both the secrets column and the allowed_switch status, the docs combine both changes, and ST6 expects the email log's table version 2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
1.11.0 replaced every
key=andconfirm_key=link value with[redacted]before saving the email log entry. A Send to me copy of a password reset, a "set your password" email or a privacy request confirmation therefore had a dead link, and flows for test customers could not be tested from a copy.message, so it can't be used to guess a key.secretscolumn, written by a separate UPDATE after the insert. That keeps them out of SQLite's error text, which ends up in debug.log. They are never shown, searched or logged.edit_userson a single site, and super admins on multisite, where delegatedmanage_network_userswould otherwise passedit_users. Restoring happens only when every placeholder lines up with a stored key; otherwise the copy stays masked. The entry view says whether the copy's links will work and why not. A newsent-with-keysnotice confirms when keys were put back.edit_postsormanage_woocommerce(editors, shop managers and the like), in To, Cc or Bcc. Anyone can request an administrator's password reset from the login page, and Safety Net lets it through to administrators, and requests for other staff accounts work the same way, so a stored key would let anyone who can read the database take over that account within 24 hours. Administrators got the real email. Customers' and subscribers' emails keep their keys, which is what testing their flows needs.DB_VERSION2. A 1.11.0 table getsALTER TABLE … ADD COLUMN secrets text, nullable so it is SQLite-portable. If the column is already there, the upgrade counts as done, and a newer version is never lowered. If the ALTER fails, it isn't retried in that request, one line is logged, and emails are logged without keys. A 1.11.0 table whose option was lost is detected afterCREATE TABLE IF NOT EXISTS.Refs #126.
Notes
Test plan
retrieve_password()for a test customer, a WooCommerce-style&key=HTML link and core'swp_send_user_request()(confirm_key=). Checks:check_password_reset_key()/wp_validate_user_request_key()accept the restored keys;edit_usersgets a masked copy;Name <addr>), store no keys and their copies stay masked. A customer-only control stores and restores its key.manage_network_usersgets a masked copy; a super admin gets the key back.