Repository navigation
Add personal data eraser - #1026
faisalahammad wants to merge 8 commits into
Conversation
Register the plugin with the WordPress personal data export and erasure tools. - Two_Factor_Core registers both privacy filters and implements the callbacks, keeping the data provider-agnostic. - Providers contribute via two optional base methods on Two_Factor_Provider: privacy_export_data() and privacy_eraser_user_meta_keys(), mirroring the existing uninstall_user_meta_keys() pattern. - The eraser removes short-lived records (login nonce, rate limit counters, email tokens, TOTP replay marker) and keeps credentials (TOTP secret, backup codes), reporting them as retained so the second factor stays active on the account. - Exports never include secret material: the TOTP key, hashed email tokens and backup codes stay out of the payload. - Tests cover the export contents, the erasure behavior, and that no secret material appears in the export payload. Fixes WordPress#954
- Remove the personal data eraser, it moves to a separate PR - Show provider labels instead of class names, fall back to the key - Export the password reset flag - Add per-session Two Factor data to the core session tokens export Addresses PR feedback. Refs WordPress#997
- Register an eraser with the WordPress privacy tools - Erase the login nonce and provider short-lived keys - Keep credentials, login protection records and session details - Report retained data with a message Refs WordPress#954
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
wp-env uses wordpress-develop trunk tests when the core version has an -alpha suffix. The 7.1-branch is 7.1.4-alpha, so it got trunk tests that need WP_Secrets_Store, which 7.1 does not have. Check out the matching wordpress-develop branch for the branch matrix legs.
There was a problem hiding this comment.
🟡 Changes recommended
Site-disabled custom providers can be skipped, leaving their data unexported and short-lived records unerased.
1 open issue
What changed in this PR
Adds personal data erasure to WordPress’s privacy tools, building on the exporter in #997 while preserving account security.
Changes:
- Registers export and erasure callbacks with provider-specific privacy methods.
- Removes short-lived records and reports retained security data.
- Adds tests for privacy output, secret exclusion, and retention.
| File | Description |
|---|---|
| tests/providers/class-two-factor-totp.php | Tests TOTP export and retention. |
| tests/providers/class-two-factor-provider.php | Tests default privacy methods. |
| tests/providers/class-two-factor-email.php | Tests email export and erasure keys. |
| tests/providers/class-two-factor-backup-codes.php | Tests code counts and secret exclusion. |
| tests/class-two-factor-core.php | Tests privacy registration, export, and erasure. |
| providers/class-two-factor-totp.php | Exports configuration and preserves replay protection. |
| providers/class-two-factor-provider.php | Defines optional privacy methods. |
| providers/class-two-factor-email.php | Exports send time and declares erasable keys. |
| providers/class-two-factor-backup-codes.php | Exports remaining recovery-code counts. |
| class-two-factor-core.php | Coordinates privacy callbacks and retention reporting. |
Review effort: Balanced
A custom provider registered before the site-wide setting filter was removed when it was disabled in Settings > Two-Factor. Merging the default providers back only restored bundled ones, so the exporter and eraser skipped the custom provider's data. Skip the site-wide setting filter while collecting providers for the privacy tools, and keep every other registration filter. Add a test with a disabled custom provider registered at priority 5.

What?
Registers the plugin with the WordPress personal data erasure tool (Tools > Erase Personal Data). Site admins can clear short-lived Two Factor records for a user.
Fixes #954
This PR is stacked on #997 (personal data exporter), as asked in review there. It builds on the provider methods from #997, so the diff shows #997's commits until that one is merged. Only the last commit is new here.
Why?
The plugin stores short-lived per-user records (login nonce, pending email code) that a personal data erasure request should remove. Without an eraser, sites that handle erasure requests must clean up user meta by hand.
How?
Two_Factor_Coreregisters thewp_privacy_personal_data_erasersfilter and implements the callback.privacy_eraser_user_meta_keys()method onTwo_Factor_Provider, mirroringuninstall_user_meta_keys(). Email returns its token and token timestamp. TOTP returns nothing.items_retainedand a message:USER_RATE_LIMIT_KEYandUSER_FAILED_LOGIN_ATTEMPTS_KEYdrive the brute force backoff and the forced password reset after 30 failed attempts.USER_PASSWORD_WAS_RESET_KEYis cleared when the user sets a new password, and the CLIdisablecommand preserves it the same way. These are cleared only by a successful Two Factor login,wp two-factor unlock, or a new password.session_tokens. They stay with the session.Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus
Used for: Implementation and test help. I reviewed and edited all generated code and tests.
Testing Instructions
Automated:
npm testruns the new PHPUnit tests covering the removed records, the retained credentials, login protection records and session details, the retained message, and providers disabled site-wide.Manual:
npm install && npm run build && npm run env start.npm run env run cli -- wp user meta update <user_id> _two_factor_failed_login_attempts 3.wp user meta list <user_id>:_two_factor_nonce,_two_factor_email_tokenand_two_factor_email_token_timestampare gone. The credentials,_two_factor_totp_last_successful_loginand_two_factor_failed_login_attempts(still3) remain.Screenshots or screencast
Changelog Entry
Added - Register a personal data eraser with the WordPress privacy tools.