Skip to content

Commit 832366c

Browse files
coder-karenmatticbot
authored andcommitted
Connection: My Jetpack - Ensure that token related errors are clearly attributable and actionable (#51034)
Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/31702717089 Upstream-Ref: Automattic/jetpack@3d85c2b
1 parent 6221875 commit 832366c

14 files changed

Lines changed: 202 additions & 142 deletions

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"automattic/jetpack-autoloader": "^5.0.23",
88
"automattic/jetpack-composer-plugin": "^4.0.9",
99
"automattic/jetpack-config": "^3.1.3",
10-
"automattic/jetpack-connection": "^8.10.1",
11-
"automattic/jetpack-my-jetpack": "^5.42.3",
10+
"automattic/jetpack-connection": "^8.10.2-alpha",
11+
"automattic/jetpack-my-jetpack": "^5.43.0-alpha",
1212
"automattic/jetpack-search": "^7.4.0-alpha",
1313
"automattic/jetpack-stats": "^0.20.2-alpha",
1414
"automattic/jetpack-status": "^6.3.1-alpha",

jetpack_vendor/automattic/jetpack-connection/CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [8.10.2-alpha] - unreleased
9+
10+
This is an alpha version! The changes listed here are not final.
11+
12+
### Security
13+
- Connection: Leave another user's broken-token error out of the connection error data, so the reconnect CTA is no longer offered against a token it cannot restore.
14+
15+
### Changed
16+
- Connection: Warn a secondary admin that reconnecting on the connection owner's behalf transfers ownership and disconnects every other user.
17+
18+
### Fixed
19+
- Connection: Stop displaying connection owner errors that refer to a previous owner.
20+
821
## [8.10.1] - 2026-08-12
922
### Fixed
1023
- Report connection errors that happen while signing an outgoing request, record the specific reason the token could not be loaded, and store the request body hash with them. [#51116]
@@ -1990,6 +2003,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
19902003

19912004
- Separate the connection library into its own package.
19922005

2006+
[8.10.2-alpha]: https://github.com/Automattic/jetpack-connection/compare/v8.10.1...v8.10.2-alpha
19932007
[8.10.1]: https://github.com/Automattic/jetpack-connection/compare/v8.10.0...v8.10.1
19942008
[8.10.0]: https://github.com/Automattic/jetpack-connection/compare/v8.9.0...v8.10.0
19952009
[8.9.0]: https://github.com/Automattic/jetpack-connection/compare/v8.8.2...v8.9.0
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('jetpack-script-data', 'react', 'react-jsx-runtime', 'wp-a11y', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-date', 'wp-element', 'wp-i18n', 'wp-polyfill', 'wp-primitives', 'wp-url'), 'version' => '2a34b42acafaa72e8fd6');
1+
<?php return array('dependencies' => array('jetpack-script-data', 'react', 'react-jsx-runtime', 'wp-a11y', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-date', 'wp-element', 'wp-i18n', 'wp-polyfill', 'wp-primitives', 'wp-url'), 'version' => '4b984610682285071677');

jetpack_vendor/automattic/jetpack-connection/dist/jetpack-connection.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jetpack_vendor/automattic/jetpack-connection/src/class-error-handler.php

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,28 @@ public function get_displayable_errors() {
341341
continue;
342342
}
343343

344+
// An owner error attributed to someone who is no longer the connection
345+
// owner describes a previous owner's token. Nobody can act on it.
346+
// Only skip when there is a current owner to compare against.
347+
if ( 'invalid_connection_owner' === $error_code
348+
&& $owner_id > 0
349+
&& (int) $user_id !== $owner_id ) {
350+
continue;
351+
}
352+
344353
$audience = $this->classify_error_audience( $user_id, $owner_id );
345354

355+
// A viewer is only ever shown errors for: their own user connection, the
356+
// site connection, or the connection owner. Another (non-owner) user's
357+
// broken token is invisible to everyone else, not just non-actionable.
358+
// `invalid_connection_owner` is exempt: when there's no current owner to
359+
// compare against, it falls back to 'user' audience by ID alone.
360+
if ( 'user' === $audience
361+
&& (int) $user_id !== $viewer_id
362+
&& 'invalid_connection_owner' !== $error_code ) {
363+
continue;
364+
}
365+
346366
$message = __( "Your connection with WordPress.com seems to be broken. If you're experiencing issues, please try reconnecting.", 'jetpack-connection' );
347367
$action = null;
348368

@@ -351,31 +371,43 @@ public function get_displayable_errors() {
351371
$message = call_user_func( $display_config['message_callback'], $error );
352372
}
353373

354-
// A secondary admin looking at the connection owner's token error, on a
355-
// site where ownership is locked (a consumer declared it non-transferable).
356-
// This admin cannot resolve the error themselves, so surface an
357-
// informational notice naming the owner and offer no reconnect CTA.
358-
if ( 'owner' === $audience && ! $viewer_is_owner && ! $is_transferable ) {
359-
// Only name the owner for viewers who can act on connection issues:
360-
// this output is also printed into the initial state for
361-
// lower-capability users (e.g. contributors in the editor), who
362-
// shouldn't learn who owns the connection. The name is resolved from
363-
// the local user rather than get_connection_owner(), which
364-
// re-reports the error and fails exactly when the token is broken.
365-
$owner_name = '';
366-
if ( current_user_can( 'jetpack_connect' ) ) {
374+
// A secondary admin looking at the connection owner's token error. What
375+
// they can usefully be told depends on whether ownership is transferable.
376+
if ( 'owner' === $audience && ! $viewer_is_owner ) {
377+
// Only name the owner, or describe what reconnecting would do, for
378+
// viewers who can act on connection issues.
379+
$viewer_can_connect = current_user_can( 'jetpack_connect' );
380+
$owner_name = '';
381+
if ( $viewer_can_connect ) {
367382
$owner = get_userdata( $owner_id );
368383
$owner_name = $owner instanceof \WP_User ? $owner->display_name : '';
369384
}
370385

371-
$message = $owner_name
372-
? sprintf(
373-
/* translators: %s is the display name of the Jetpack connection owner. */
374-
__( 'The connection owner (%s) needs to reconnect their WordPress.com account to restore the connection.', 'jetpack-connection' ),
375-
$owner_name
376-
)
377-
: __( 'The connection owner needs to reconnect their WordPress.com account to restore the connection.', 'jetpack-connection' );
378-
$action = 'none';
386+
if ( ! $is_transferable ) {
387+
// Ownership is locked (a consumer declared it non-transferable).
388+
// This admin cannot resolve the error themselves, so surface an
389+
// informational notice naming the owner and offer no reconnect CTA.
390+
$message = $owner_name
391+
? sprintf(
392+
/* translators: %s is the display name of the Jetpack connection owner. */
393+
__( 'The connection owner (%s) needs to reconnect their WordPress.com account to restore the connection.', 'jetpack-connection' ),
394+
$owner_name
395+
)
396+
: __( 'The connection owner needs to reconnect their WordPress.com account to restore the connection.', 'jetpack-connection' );
397+
$action = 'none';
398+
} elseif ( $viewer_can_connect ) {
399+
// Ownership is transferable, so the reconnect CTA stays available
400+
// to this admin — but it is destructive in a way the generic copy
401+
// doesn't convey. Manager::restore() branches on the *clicking*
402+
// user's tokens, not on whose token the error describes.
403+
$message = $owner_name
404+
? sprintf(
405+
/* translators: %s is the display name of the Jetpack connection owner. */
406+
__( 'The connection owner (%s) needs to reconnect their WordPress.com account to restore the connection. If you reconnect instead, you will become the new connection owner and every other user will be disconnected from WordPress.com.', 'jetpack-connection' ),
407+
$owner_name
408+
)
409+
: __( 'The connection owner needs to reconnect their WordPress.com account to restore the connection. If you reconnect instead, you will become the new connection owner and every other user will be disconnected from WordPress.com.', 'jetpack-connection' );
410+
}
379411
}
380412

381413
$error['audience'] = $audience;

jetpack_vendor/automattic/jetpack-connection/src/class-package-version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
class Package_Version {
1414

15-
const PACKAGE_VERSION = '8.10.1';
15+
const PACKAGE_VERSION = '8.10.2-alpha';
1616

1717
const PACKAGE_SLUG = 'connection';
1818

jetpack_vendor/automattic/jetpack-my-jetpack/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [5.43.0-alpha] - unreleased
9+
10+
This is an alpha version! The changes listed here are not final.
11+
12+
### Changed
13+
- Connection: Leave another user's broken token out of the connection error notice, since only that user can restore it.
14+
- Connection: Show the scope and error code of each connection error in the notice, instead of only the first error's message.
15+
816
## [5.42.3] - 2026-08-12
917
### Changed
1018
- Protect: Test the site protection data endpoint against the real firewall configuration. [#51184]
@@ -2840,6 +2848,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
28402848
### Added
28412849
- Created package
28422850

2851+
[5.43.0-alpha]: https://github.com/Automattic/jetpack-my-jetpack/compare/5.42.3...5.43.0-alpha
28432852
[5.42.3]: https://github.com/Automattic/jetpack-my-jetpack/compare/5.42.2...5.42.3
28442853
[5.42.2]: https://github.com/Automattic/jetpack-my-jetpack/compare/5.42.1...5.42.2
28452854
[5.42.1]: https://github.com/Automattic/jetpack-my-jetpack/compare/5.42.0...5.42.1
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('jetpack-connection', 'jetpack-script-data', 'jetpack-shared-stores', 'react', 'react-dom', 'react-jsx-runtime', 'wp-a11y', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-data', 'wp-date', 'wp-element', 'wp-i18n', 'wp-keycodes', 'wp-notices', 'wp-polyfill', 'wp-primitives', 'wp-private-apis', 'wp-rich-text', 'wp-theme', 'wp-url', 'wp-warning'), 'version' => '2380d233324a43dd20a4');
1+
<?php return array('dependencies' => array('jetpack-connection', 'jetpack-script-data', 'jetpack-shared-stores', 'react', 'react-dom', 'react-jsx-runtime', 'wp-a11y', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-data', 'wp-date', 'wp-element', 'wp-i18n', 'wp-keycodes', 'wp-notices', 'wp-polyfill', 'wp-primitives', 'wp-private-apis', 'wp-rich-text', 'wp-theme', 'wp-url', 'wp-warning'), 'version' => '527818c8c3a69e58d41d');

0 commit comments

Comments
 (0)