Skip to content

Application Password: Add expiration presets and validation to Application Passwords - #14069

Open
shewa12 wants to merge 12 commits into
WordPress:trunkfrom
shewa12:53995-app-password-expiry-presets
Open

shewa12 wants to merge 12 commits into
WordPress:trunkfrom
shewa12:53995-app-password-expiry-presets

Conversation

@shewa12

@shewa12 shewa12 commented Oct 7, 2026

Copy link
Copy Markdown

Description

This PR improves the Application Passwords expiration feature on top of PR #11685 by introducing sensible presets, a timezone-aware custom expiration calendar, backend validation, and security UX enhancements aligned with modern token management standards.

Summary of Changes:

  1. Expiry Presets Dropdown:
    • Added a dropdown selector offering standard token lifetime options:
      • 7 days
      • 30 days (default)
      • 90 days
      • No expiry
      • Custom date
    • Presets are defined as class constants on WP_Application_Passwords (EXPIRY_7_DAYS, EXPIRY_30_DAYS, EXPIRY_90_DAYS, EXPIRY_NO_EXPIRY, EXPIRY_CUSTOM) with a helper method get_expiry_presets().
  2. Timezone-Aware Expiration Calculation:
    • When selecting a custom date or preset, expiration is calculated to the end of the day (23:59:59) in the site's configured local timezone (wp_timezone()), converted to UTC ISO format for consistent storage and comparison.
    • The custom date field utilizes native HTML5 date input with min set to the site's current date (wp_date( 'Y-m-d' )), preventing users from picking past dates.
  3. Validation & Sanitization:
    • Updated WP_Application_Passwords::create_new_application_password() to validate $args['expires'] and explicitly reject timestamps in the past with a WP_Error (application_password_past_expiration).
  4. Removal of "Edit Expiry" Action:
    • Removed the inline "Edit Expiry" button and editing form from WP_Application_Passwords_List_Table and application-passwords.js.
    • Rationale: Similar to industry token management standards (e.g., GitHub Personal Access Tokens and GitLab Access Tokens), application passwords and access tokens are meant to be immutable credentials. Modifying token lifespans post-creation introduces security risks and audit ambiguity. If an application password expires or its validity period needs to change, the secure and recommended practice is to revoke the existing password and generate a new one.
  5. Unit Tests:
    • Added tests in tests/phpunit/tests/auth.php covering authentication with expired passwords as well as passwords with valid future expiration.
    • Added tests in tests/phpunit/tests/rest-api/application-passwords.php verifying that past expiration timestamps are rejected during creation and verifying preset definitions.

Trac ticket: https://core.trac.wordpress.org/ticket/53995

Use of AI Tools

AI assistance: Yes
Tool(s): Antigravity
Model(s): Gemini 3.8 Flash
Used for: Generation of PHPUnit tests, JS code, tests, and translations; refined and verified in a local Docker environment.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props lakshyajeet, peterwilsoncc, shewa.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

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.

3 participants