feat: Expand application password abilities#45220
Conversation
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Code Coverage SummaryCoverage changed in 1 file.
2 files are newly checked for coverage.
|
1b9ad63 to
ac4c623
Compare
8e1970e to
cc53440
Compare
b9e2ea4 to
07365ee
Compare
Allow authenticating for `admin-ajax` and post preview requests with application passwords. This enables cookie-less clients--e.g, the iOS and Android mobile apps--to successfully authenticate these requests.
Return early if the provided value is already truthy.
The logic now requires the `preview` parameter.
Mitigate potential security risk by limiting application password capabilities to VideoPress-related AJAX actions.
07365ee to
0da7a8a
Compare
Align the `get_abilities()` key with the REST route name and expected API response documented in the PR.
| // Allow access to post/page previews | ||
| $is_preview_request = isset( $_GET['preview'] ) && 'true' === $_GET['preview']; // phpcs:ignore WordPress.Security.NonceVerification.Recommended | ||
| $has_post_id = isset( $_GET['p'] ) || isset( $_GET['page_id'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended | ||
| if ( $is_preview_request && $has_post_id ) { | ||
| return true; | ||
| } |
There was a problem hiding this comment.
@jkmassel I'm realizing this is too broad and problematic. Effectively, any request can append ?preview=true&p=anything and enable application password authentication for the request.
That effectively nullifies the VideoPress actions limitation. It also expands the potential usage surface immensely, even beyond admin-ajax.
Unfortunately, I don't believe there is a more explicit way to identify a request for post preview. Claude suggested...
- Appending
&& ! is_admin(), but I imagine there are non-admin requests that could still be manipulated. - Leveraging the presence of
WP_USE_THEMES, but this feels brittle as I'm sure that value was never intended for this purpose.
It feels like we shouldn't pursue token authentication for post previews. We might instead...
- Retain the approach of token → cookie exchange for sites with Jetpack.
- Notify users they may need to log in to their site and launch users to their OS browser.
There was a problem hiding this comment.
Pull request overview
This PR extends WordPress Application Password authentication capabilities to support cookie-less clients (like mobile apps) by allowing authentication for:
- VideoPress AJAX actions via
admin-ajax.php - Post and page preview requests
The implementation leverages the application_password_is_api_request filter to conditionally enable these abilities while maintaining security by restricting them to specific, controlled use cases.
Changes:
- Adds new
Jetpack_Application_Password_Extrasclass to extend application password functionality beyond REST API - Introduces REST API endpoints to query application password abilities
- Includes comprehensive test coverage for both core functionality and REST endpoints
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
projects/plugins/jetpack/_inc/lib/class-jetpack-application-password-extras.php |
Core implementation extending application password authentication for VideoPress AJAX actions and post previews |
projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-application-password-extras.php |
REST API endpoint to retrieve application password abilities |
projects/plugins/jetpack/load-jetpack.php |
Initializes the new application password extras functionality |
projects/plugins/jetpack/tests/php/_inc/lib/Jetpack_Application_Password_Extras_Test.php |
Comprehensive unit tests for core functionality |
projects/plugins/jetpack/tests/php/core-api/wpcom-endpoints/WPCOM_REST_API_V2_Endpoint_Application_Password_Extras_Test.php |
Unit tests for REST API endpoints |
projects/plugins/jetpack/changelog/feat-expand-application-passwords-abilities |
Changelog entry documenting the changes |
Allow authenticating for
admin-ajaxand post preview requests with application passwords. This enables cookie-less clients—e.g, the iOS and Android mobile apps—to successfully authenticate these requests.Ref CMM-713. Close CMM-766.
Proposed changes:
Leverage the
application_password_is_api_requestfilter to conditionally extend application password authentication for:admin-ajaxOther information:
Jetpack product discussion
Does this pull request change what data or activity we track or use?
No
Testing instructions:
Important
Apply these Jetpack changes to your site (see comment) before testing.
Important
Replace the placeholder values (wrapped with
<some_value>) with valid information.1. Authenticate VideoPress
admin-ajaxrequests with application passwordsadmin-ajaxaction:curl -I 'https://<site_domain>/wp-admin/admin-ajax.php?action=videopress-get-upload-jwt'admin-ajaxaction:admin-ajaxaction:2. Authenticate draft post preview request with application passwords
curl -I 'https://<site_domain>/?p=<draft_post_id>&preview=true'3. Retrieve application password abilities
{"admin-ajax":true,"post-previews":true}