Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
75fd04d
Backup: bridge known threats and the restore acknowledgement
RafaelFunchal Oct 17, 2026
eb815fa
Backup: warn about known threats before restoring
RafaelFunchal Oct 17, 2026
55e0c91
Backup: wait for the known-threats check before enabling restore
RafaelFunchal Oct 17, 2026
5a83601
Backup: describe the known-threats warning in the changelog
RafaelFunchal Oct 17, 2026
7051a72
Backup: show known-threat dates in local time
RafaelFunchal Oct 17, 2026
ffd06cf
Backup: check known threats only on WordPress.com-hosted sites
RafaelFunchal Oct 18, 2026
b08e1a5
Activity Log: add a known-threats route for flagged backups
RafaelFunchal Oct 18, 2026
47061b9
Backup, Activity Log: point Restore backup at the in-admin restore sc…
RafaelFunchal Oct 18, 2026
0df8fe1
Activity Log: show a Known threats badge on flagged backups
RafaelFunchal Oct 18, 2026
80f9c9a
Add changelog entries for the Activity Log known-threats badge
RafaelFunchal Oct 18, 2026
fc743f6
Activity Log: match a backup row to the backup it completes
RafaelFunchal Oct 18, 2026
62e8889
Activity Log: show the Known threats badge after the event text, on b…
RafaelFunchal Oct 18, 2026
abbba8e
Backup: add a known-threats route for the newest backups
RafaelFunchal Oct 18, 2026
acd64f6
Backup: read known-threat counts for the backups list
RafaelFunchal Oct 18, 2026
76020bf
Backup: show the known-threats warning as WordPress.com does
RafaelFunchal Oct 18, 2026
033efaf
Backup: mark flagged backups in the list and warn in the backup details
RafaelFunchal Oct 18, 2026
7790c4b
Activity Log: use the same Known threats pill as the Backup dashboard
RafaelFunchal Oct 18, 2026
169397c
Update the Backup changelog entry for the list and details warning
RafaelFunchal Oct 18, 2026
1227db7
Backup: find when the latest clean backup finished
RafaelFunchal Oct 18, 2026
32f51ed
Backup: name the recommended backup in the restore link
RafaelFunchal Oct 18, 2026
48c156c
Backup: point aria-controls at the threats list only while it is shown
RafaelFunchal Oct 18, 2026
50dc8c2
Backup: known-threats accessibility and layout fixes
RafaelFunchal Oct 18, 2026
423b3fe
Backup: restore screen focus and announcements for known threats
RafaelFunchal Oct 18, 2026
5dde7df
Activity Log: give screen readers the known-threats sentence, not a t…
RafaelFunchal Oct 18, 2026
17fa0ed
Backup: explain why the clean backup is recommended
RafaelFunchal Oct 18, 2026
eb98354
Backup: show the known-threats warning as the list badge's tooltip
RafaelFunchal Oct 18, 2026
86037b4
Activity Log: show the known-threats warning as the badge's tooltip
RafaelFunchal Oct 18, 2026
aa56e8e
Backup: Set the known-threats acknowledgement apart from the clean-ba…
RafaelFunchal Oct 18, 2026
d19ca13
Backup: Point the Activity Log's backup links at the Overview
RafaelFunchal Oct 18, 2026
2780c72
Activity Log: Link backup ranges to the Backup dashboard
RafaelFunchal Oct 18, 2026
5021277
Backup: Announce when the known-threats acknowledgement opens the res…
RafaelFunchal Oct 18, 2026
d8f17c2
Backup: Always tell WordPress.com whether known threats were acknowle…
RafaelFunchal Oct 18, 2026
38522cd
Backup: Find when the clean backup finished only when asked, and reme…
RafaelFunchal Oct 18, 2026
70decc0
Backup: Ask for the clean backup's finish time only where a warning l…
RafaelFunchal Oct 18, 2026
8a07b81
Activity Log: Ask WordPress.com for known-threat counts only
RafaelFunchal Oct 18, 2026
3dde3a4
Activity Log: Link only well-formed backup ids, encoded for the Backu…
RafaelFunchal Oct 18, 2026
762d22e
Activity Log: Keep the known-threats sentence inside the badge's span
RafaelFunchal Oct 18, 2026
dfdd765
Backup: Announce the list's Known threats badge with its row
RafaelFunchal Oct 18, 2026
d3faa98
Backup: Announce the known-threats warning when it appears
RafaelFunchal Oct 18, 2026
3841f64
Backup: Queue the known-threats warning with the dashboard's other an…
RafaelFunchal Oct 18, 2026
0f43238
Backup: Show why Restore to this point is off in a tooltip
RafaelFunchal Oct 18, 2026
b1807bb
Backup: Show why Confirm restore is off in a tooltip
RafaelFunchal Oct 18, 2026
9ad91c1
Activity Log: Call the known-threats route without a request in its t…
RafaelFunchal Oct 18, 2026
2cfc678
Update plugin lock files for the Activity Log package's JS test scripts
RafaelFunchal Oct 18, 2026
c60bac8
Add changelog entries for the plugin lock file updates
RafaelFunchal Oct 18, 2026
8475de2
Backup: Test the known-threats routes' failure paths
RafaelFunchal Oct 18, 2026
baa0ecf
Activity Log: Test the known-threats route's registration and failures
RafaelFunchal Oct 18, 2026
3e6b0f0
Backup: Test that clicking a row's Known threats badge selects the row
RafaelFunchal Oct 18, 2026
584b21f
Merge trunk into add/known-threats-plugin-restore
dhasilva Oct 20, 2026
6f263ab
Backup, Activity Log: Check known threats only where the warning runs
dhasilva Oct 20, 2026
3ab1751
Activity Log: Leave backup ranges as plain text again
dhasilva Oct 20, 2026
434ba80
Backup: Say "No known threats found" only after a check that answered
dhasilva Oct 20, 2026
b89fb1e
Backup: Carry the details' acknowledgement in history state, not the URL
dhasilva Oct 20, 2026
b4796ce
Backup, Activity Log: Build the known-threats warning from @wordpress/ui
dhasilva Oct 20, 2026
6231540
Backup: Keep the restore card's heading still when the warning arrives
dhasilva Oct 20, 2026
c660a39
Backup, Jetpack: Describe the restore warning in the plugin changelogs
dhasilva Oct 20, 2026
97a4f33
Activity Log: Start the Known threats badge under the event title
RafaelFunchal Oct 21, 2026
eb2b678
Backup: Check older backups' known threats from their details
RafaelFunchal Oct 21, 2026
eb63078
Backup: Space the open threats list from the clean-backup link
RafaelFunchal Oct 21, 2026
3f1c614
Backup: Keep the known-threats checkbox inside the warning
RafaelFunchal Oct 21, 2026
725512b
Backup: Make the known-threats acknowledgement label bold
RafaelFunchal Oct 21, 2026
9560001
Backup: Make the threats toggle an outlined "Known threats (N)" button
RafaelFunchal Oct 21, 2026
9abe548
Merge trunk into add/known-threats-plugin-restore
RafaelFunchal Oct 21, 2026
22ef0c9
Backup: Label the threats toggle "Show threats (N)" so it differs fro…
RafaelFunchal Oct 21, 2026
548a6df
Backup: Show the Known threats badge with a separate "Show threats" link
RafaelFunchal Oct 21, 2026
e23092e
Backup: Show only an outlined "Show threats" button in the warning
RafaelFunchal Oct 21, 2026
0f7b5d1
Activity Log: Show the known-threats warning as the badge's tooltip
RafaelFunchal Oct 21, 2026
c74aa2c
Merge branch 'trunk' into add/known-threats-plugin-restore
RafaelFunchal Oct 22, 2026
d537b0d
Activity Log: Keep the Known threats badge free of a tooltip
dhasilva Oct 22, 2026
b920d7d
Backup: Explain the disabled restore buttons in text, not tooltips
dhasilva Oct 22, 2026
b7d2493
Backup: Show why the clean backup is recommended under its link
dhasilva Oct 22, 2026
067a167
Backup: Leave the acknowledgement checkbox's label weight to the desi…
dhasilva Oct 22, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Mark backups that are known to contain security threats on sites hosted on WordPress.com, and open the in-admin restore screen from "Restore backup" when the new Backup dashboard is on.
6 changes: 6 additions & 0 deletions projects/packages/activity-log/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
],
"test-php-coverage": [
"php -dpcov.directory=. ./vendor/bin/phpunit-select-config phpunit.#.xml.dist --coverage-php \"$COVERAGE_DIR/php.cov\""
],
"test-js": [
"pnpm run test"
],
"test-js-coverage": [
"pnpm run test-coverage"
]
},
"repositories": [
Expand Down
9 changes: 8 additions & 1 deletion projects/packages/activity-log/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"build:wp-build": "wp-build",
"build-production": "NODE_ENV=production BABEL_ENV=production pnpm run build && pnpm run build:strip-unminified-prod && pnpm run validate",
"clean": "rm -rf build/",
"test": "jest --config=tests/jest.config.js",
"test-coverage": "pnpm run test --coverage",
"typecheck": "tsgo --noEmit",
"validate": "pnpm exec validate-es --no-error-on-unmatched-pattern build/",
"watch": "wp-build --watch"
Expand Down Expand Up @@ -70,13 +72,18 @@
},
"devDependencies": {
"@automattic/jetpack-base-styles": "workspace:*",
"@automattic/jetpack-webpack-config": "workspace:*",
"@automattic/jetpack-wp-build-polyfills": "workspace:*",
"@babel/core": "7.29.7",
"@testing-library/dom": "10.4.2",
"@testing-library/react": "16.3.3",
"@types/react": "19.3.0",
"@typescript/native-preview": "7.0.0-dev.20260707.2",
"@wordpress/browserslist-config": "6.57.0",
"@wordpress/build": "0.25.0",
"@wordpress/theme": "2.3.0",
"browserslist": "^4.24.0"
"babel-jest": "30.5.2",
"browserslist": "^4.24.0",
"jest": "30.5.2"
}
}
19 changes: 15 additions & 4 deletions projects/packages/activity-log/src/class-initial-state.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Automattic\Jetpack\Status;
use function add_query_arg;
use function admin_url;
use function apply_filters;
use function esc_url_raw;
use function get_bloginfo;
use function get_locale;
Expand Down Expand Up @@ -51,13 +52,23 @@ private function get_data() {
return array(
'upgrade' => $upgrade,
'jetpackStatus' => array(
'calypsoSlug' => $site_suffix,
'calypsoSlug' => $site_suffix,
/**
* Filters the in-admin address "Restore backup" opens, with `{rewindId}` as the placeholder.
* Empty keeps the Jetpack Cloud restore flow.
*
* @since $$next-version$$
*
* @param string $template Restore URL template, or an empty string.
*/
'restoreUrlTemplate' => (string) apply_filters( 'jetpack_activity_log_restore_url_template', '' ),
),
'config' => array(
// Simple sites have no Jetpack REST API to proxy through, so the app calls WordPress.com directly.
'apiSource' => $is_wpcom_simple ? 'wpcom' : 'jetpack',
'wpcomUpgradeUrl' => $is_wpcom_simple ? self::get_wpcom_upgrade_url( $site_suffix ) : '',
'tracksUserData' => $is_wpcom_simple ? self::get_wpcom_tracks_user_data() : null,
'apiSource' => $is_wpcom_simple ? 'wpcom' : 'jetpack',
'wpcomUpgradeUrl' => $is_wpcom_simple ? self::get_wpcom_upgrade_url( $site_suffix ) : '',
'tracksUserData' => $is_wpcom_simple ? self::get_wpcom_tracks_user_data() : null,
'knownThreatsAvailable' => REST_Controller::known_threats_available(),
),
'siteData' => array(
'id' => Connection_Manager::get_site_id( true ),
Expand Down
81 changes: 81 additions & 0 deletions projects/packages/activity-log/src/class-rest-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Automattic\Jetpack\Connection\Client;
use Automattic\Jetpack\Connection\Manager as Connection_Manager;
use Automattic\Jetpack\Status\Host;
use Automattic\Jetpack\Status\Visitor;
use Jetpack_Options;
use WP_Error;
Expand Down Expand Up @@ -217,6 +218,16 @@ public static function register_rest_routes() {
)
);

register_rest_route(
self::REST_NAMESPACE,
'/activity-log/known-threats',
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( __CLASS__, 'get_known_threats' ),
'permission_callback' => array( __CLASS__, 'permissions_callback' ),
)
);

register_rest_route(
self::REST_NAMESPACE,
'/activity-log/actors',
Expand Down Expand Up @@ -411,6 +422,76 @@ public static function get_activity_log_actors( WP_REST_Request $request ) {
return self::proxy_get( '/activity/actors', $request, array_keys( self::actors_args() ) );
}

/**
* Whether this site checks backups for known threats. Only WoA sites do, for now.
*
* @return bool
*/
public static function known_threats_available() {
return ( new Host() )->is_woa_site();
}

/**
* Known Scan threat counts for the site's newest 100 backups, by backup period.
*
* Without Scan, or off WoA, the answer is `threats_unavailable` (404) and the log shows no badges.
*
* @return \WP_REST_Response|WP_Error
*/
public static function get_known_threats() {
$unavailable = new WP_Error(
'threats_unavailable',
esc_html__( 'Known threats are not available for this site.', 'jetpack-activity-log' ),
array( 'status' => 404 )
);

$blog_id = (int) Jetpack_Options::get_option( 'id' );
if ( ! $blog_id || ! self::known_threats_available() ) {
return $unavailable;
}

$response = Client::wpcom_json_api_request_as_user(
sprintf( '/sites/%d/rewind/backups?number=100&page=1&known_threats_only=true', $blog_id ),
'3',
array( 'method' => 'GET' ),
null,
'wpcom'
);

if ( is_wp_error( $response ) ) {
return new WP_Error( 'known_threats_request_failed', $response->get_error_message(), array( 'status' => 502 ) );
}

$status = (int) wp_remote_retrieve_response_code( $response );
if ( 403 === $status ) {
return $unavailable;
}

$body = json_decode( wp_remote_retrieve_body( $response ), true );
if ( 200 !== $status || ! is_array( $body ) ) {
return new WP_Error(
'known_threats_request_failed',
esc_html__( 'Unable to fetch the known threats.', 'jetpack-activity-log' ),
array( 'status' => 502 )
);
}

// Every period is kept: a row belongs to the newest backup at or before its rewind id.
$backups = array();
foreach ( (array) ( $body['backups'] ?? array() ) as $backup ) {
if ( ! isset( $backup['object']['backup_period'] ) || ! is_numeric( $backup['object']['backup_period'] ) ) {
continue;
}
$known_threats = $backup['object']['known_threats'] ?? null;
$backups[] = array(
'period' => (int) $backup['object']['backup_period'],
'known_threats' => is_array( $known_threats ) ? $known_threats : null,
);
}

return rest_ensure_response( array( 'backups' => $backups ) );
}

/**
* Shared helper: forward whitelisted query params from $request to the
* equivalent WPCOM v2 path under `/sites/{blog_id}`.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { __experimentalHStack as HStack } from '@wordpress/components'; // eslint-disable-line @wordpress/no-unsafe-wp-apis
import { __, _n, sprintf } from '@wordpress/i18n';
import { Icon } from '@wordpress/icons';
import { Badge, VisuallyHidden } from '@wordpress/ui';
import { useBackupKnownThreats } from '../../hooks/use-known-threats';
import { buildObjectAdminLink } from './admin-links';
import { renderFormattedContent } from './formatted-block';
import { gridiconToWordPressIcon } from './gridicons';
Expand Down Expand Up @@ -46,17 +49,65 @@ export function ActivityEventTitle( { activity }: { activity: Activity } ) {
return <strong className="site-activity-logs__event-title">{ activity.activityTitle }</strong>;
}

/**
* "Known threats" badge for a backup Scan knew to contain threats when it ran.
*
* @param props - Component props.
* @param props.activity - Normalized Activity for the current log row.
* @return The badge, or null when the row isn't a flagged backup.
*/
export function KnownThreatsBadge( { activity }: { activity: Activity } ) {
// Only the backup's own row is marked, not every restore point after it.
const isBackupRow =
activity.activityIsRewindable &&
/^rewind__backup(_only)?_complete/.test( activity.activityName ?? '' );
const knownThreats = useBackupKnownThreats( isBackupRow ? activity.rewindId : undefined );
if ( ! knownThreats?.flagged ) {
return null;
}
const description = sprintf(
/* translators: %d: number of malware and database threats in the backup. */
_n(
'This backup is known to contain %d security threat. Restoring it may bring malware back to your site.',
'This backup is known to contain %d security threats. Restoring it may bring malware back to your site.',
knownThreats.flagged,
'jetpack-activity-log'
),
knownThreats.flagged
);
// Same badge as the Backup dashboard. Keep it static: design-system badges aren't controls.
return (
<span className="site-activity-logs__event-badge">
<Badge intent="medium">
{ sprintf(
/* translators: %d: number of known security threats in a backup. */
__( 'Known threats (%d)', 'jetpack-activity-log' ),
knownThreats.flagged
) }
</Badge>
<VisuallyHidden render={ <span /> }>{ description }</VisuallyHidden>
</span>
);
}

/**
* The formatted description body — parsed ranges (entity links,
* release-notes, etc.) with an `object`-level link fallback for
* range-less payloads like `post__published`. Plugs into DataViews'
* `descriptionField` slot for the Activity layout.
*
* @param props - Component props.
* @param props.activity - Normalized Activity for the current log row.
* @param props - Component props.
* @param props.activity - Normalized Activity for the current log row.
* @param props.withThreatsBadge - Whether to end with the Known threats badge.
* @return The description element, or null when the activity has none.
*/
export function ActivityEventDescription( { activity }: { activity: Activity } ) {
export function ActivityEventDescription( {
activity,
withThreatsBadge = true,
}: {
activity: Activity;
withThreatsBadge?: boolean;
} ) {
const { activityDescription, activityObject } = activity;
const hasRanges = activityDescription.items.some(
item => typeof item === 'object' && item !== null && 'type' in item
Expand All @@ -69,7 +120,10 @@ export function ActivityEventDescription( { activity }: { activity: Activity } )
return null;
}
return (
<span>{ objectHref ? <a href={ objectHref }>{ formattedContent }</a> : formattedContent }</span>
<span>
{ objectHref ? <a href={ objectHref }>{ formattedContent }</a> : formattedContent }
{ withThreatsBadge && <KnownThreatsBadge activity={ activity } /> }
</span>
);
}

Expand All @@ -94,7 +148,9 @@ export function ActivityEvent( { activity }: { activity: Activity } ) {
className="site-activity-logs__event-content"
>
<ActivityEventTitle activity={ activity } />
<ActivityEventDescription activity={ activity } />
<ActivityEventDescription activity={ activity } withThreatsBadge={ false } />
{ /* Wraps onto its own line, starting under the title. */ }
<KnownThreatsBadge activity={ activity } />
</HStack>
</HStack>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { Activity } from './types';
import type { Action } from '@wordpress/dataviews';

interface InitialStateWithCalypsoSlug {
jetpackStatus?: { calypsoSlug?: string };
jetpackStatus?: { calypsoSlug?: string; restoreUrlTemplate?: string };
}

declare const JPACTIVITYLOG_INITIAL_STATE: InitialStateWithCalypsoSlug | undefined;
Expand All @@ -17,6 +17,12 @@ const calypsoSlug: string =
? JPACTIVITYLOG_INITIAL_STATE?.jetpackStatus?.calypsoSlug
: undefined ) ?? '';

// The in-admin restore screen, with `{rewindId}` to fill in; empty when the Backup dashboard can't take it.
const restoreUrlTemplate: string =
( typeof JPACTIVITYLOG_INITIAL_STATE !== 'undefined'
? JPACTIVITYLOG_INITIAL_STATE?.jetpackStatus?.restoreUrlTemplate
: undefined ) ?? '';

type Tracks = { recordEvent: ( name: string, props?: Record< string, unknown > ) => void };

type UseActivityActionsOptions = {
Expand All @@ -25,18 +31,9 @@ type UseActivityActionsOptions = {
};

/**
* Row actions for the DataViews table. The single primary action deep-
* links into the Jetpack Cloud Backup restore flow for the row's rewind
* point (`https://cloud.jetpack.com/backup/{slug}/restore/{rewindId}`)
* and opens in a new tab. Eligibility requires `activityIsRewindable`,
* a `rewindId`, and a `calypsoSlug` from Initial_State; rows missing
* any of those don't render the action.
*
* TEMPORARY: this off-site link is a stop-gap until the Backup wp-admin
* port (https://github.com/Automattic/jetpack/pull/48236) lands. Once
* that ships, every row action here should point at the in-admin
* Backup page instead of cloud.jetpack.com so users stay inside their
* own wp-admin for the restore flow.
* Row actions for the DataViews table. "Restore backup" opens the in-admin
* Backup restore screen when the Backup dashboard provides one
* (`restoreUrlTemplate`), otherwise the Jetpack Cloud restore flow in a new tab.
*
* @param options - Hook options.
* @param options.isLoading - Whether the list is currently fetching. Kept
Expand All @@ -54,10 +51,27 @@ export function useActivityActions( {
isPrimary: true,
label: __( 'Restore backup', 'jetpack-activity-log' ),
icon: <Icon icon={ backup } />,
isEligible: item => Boolean( item.activityIsRewindable && item.rewindId && calypsoSlug ),
isEligible: item =>
Boolean(
item.activityIsRewindable && item.rewindId && ( restoreUrlTemplate || calypsoSlug )
),
callback: async items => {
const item = items[ 0 ];
if ( ! item?.rewindId || ! calypsoSlug ) {
if ( ! item?.rewindId ) {
return;
}
if ( restoreUrlTemplate ) {
tracks?.recordEvent( 'jetpack_activity_log_restore_backup_click', {
rewind_id: item.rewindId,
activity_name: item.activityName,
destination: 'wp-admin',
} );
window.location.assign(
restoreUrlTemplate.replace( '{rewindId}', encodeURIComponent( item.rewindId ) )
);
return;
}
if ( ! calypsoSlug ) {
return;
}
const url = `https://cloud.jetpack.com/backup/${ encodeURIComponent(
Expand Down
Loading
Loading