CMM-2114: Fix media routing for Jetpack-connected sites that carry an Application Password - #23117
Conversation
Jetpack-connected self-hosted sites can have Application Password credentials stored, which makes isUsingSelfHostedRestApi() return true. Media requests were therefore routed to the self-hosted REST client instead of the WP.com REST API (Jetpack tunnel), causing uploads and the Media Library to fail on sites with Application Passwords disabled. Centralize client resolution so the WP.com check runs before the self-hosted check (CMM-2114). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Generated by 🚫 Danger |
|
|
|
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## trunk #23117 +/- ##
=======================================
Coverage 37.68% 37.69%
=======================================
Files 2343 2343
Lines 127339 127339
Branches 17669 17658 -11
=======================================
+ Hits 47984 47995 +11
+ Misses 75424 75411 -13
- Partials 3931 3933 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@adalpari I used a plugin to deactivate application passwords, but I'm unable to login to it in the app.
|
Oh, that's my bad. You can't connect to a self-hosted site without AP that way. It has to be a site linked to your wpcom account. I haven't tested that scenario, but Claude for some reason, went ahead that way. Actually, that scenario is a supposition since we want all the self-hosted sites to use AP. |



Description
Media uploads and the Media Library were failing on Jetpack-connected self-hosted
sites that carry an Application Password.
The root cause is client-selection order in
MediaStore. A Jetpack-connected sitelogs in through WordPress.com (the Jetpack tunnel), but the app can also mint and
store Application Password credentials on it in the background (e.g. the Jetpack REST
connection flow, or credentials auto-generated for taxonomies / navigation menus).
Once those credentials are stored,
SiteModel.isUsingSelfHostedRestApi()returnstrue, because that predicate is simply:Several media routing methods checked
isUsingSelfHostedRestApi()beforeisUsingWpComRestApi(), so these sites were routed to the self-hosted REST client andtalked to the self-hosted REST API directly instead of going through the WP.com REST
API. The bug does not actually depend on Application Passwords being "disabled" — any
Jetpack site carrying stored credentials is mis-routed. The failure just becomes
visible when that direct path stops working, e.g. when the stored credentials no
longer authenticate on the server (Application Passwords later disabled or revoked),
while the WP.com/Jetpack tunnel keeps working.
This PR:
getMediaRestClientType(SiteModel)helper (with aMediaRestClientTypeenum) that centralizes network-client resolution and guarantees the WP.com REST API
check runs before the self-hosted REST API check.
push,upload,fetchList,fetch,delete,cancel) to use this shared helper, removing the previously duplicated —and inconsistently ordered — selection logic.
the self-hosted, WP.com, and XML-RPC paths.
Testing instructions
🤖 Generated with Claude Code