Skip to content

Commit bfaccc2

Browse files
committed
Prevent Updating AU via API
Prevent Updating AU via API Fixes #325 Fixes #324
1 parent a8e008e commit bfaccc2

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

includes/class-controller.php

+16
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function __construct() {
2222
$this->api_rewrite();
2323
add_action( 'wp_ajax_aspireupdate_clear_log', [ $this, 'clear_log' ] );
2424
add_action( 'wp_ajax_aspireupdate_read_log', [ $this, 'read_log' ] );
25+
add_filter( 'site_transient_update_plugins', [ $this, 'check_self_update_notifications' ] );
2526
}
2627

2728
/**
@@ -125,4 +126,19 @@ public function read_log() {
125126
]
126127
);
127128
}
129+
130+
/**
131+
* Hide Aspire Update plugin from plugin update notifications.
132+
* This is to prevent supply chain attacks via unverified API providers.
133+
*
134+
* @param object $value The Update Notifications Data.
135+
*
136+
* @return object $value The Update Notifications Data.
137+
*/
138+
public function check_self_update_notifications( $value ) {
139+
if ( isset( $value->response['aspireupdate/aspire-update.php'] ) ) {
140+
unset( $value->response['aspireupdate/aspire-update.php'] );
141+
}
142+
return $value;
143+
}
128144
}

includes/class-plugins-screens.php

+34
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public function __construct() {
3535
$admin_settings = Admin_Settings::get_instance();
3636
if ( $admin_settings->get_setting( 'enable', false ) ) {
3737
add_filter( 'install_plugins_tabs', [ $this, 'remove_unused_filter_tabs' ] );
38+
add_filter( 'plugins_api_result', [ $this, 'hide_self_plugins_api_result' ], 10, 1 );
3839
}
3940
}
4041

@@ -62,4 +63,37 @@ public function remove_unused_filter_tabs( $tabs ) {
6263
}
6364
return $tabs;
6465
}
66+
67+
/**
68+
* Hide Aspire Update plugin from plugin search results.
69+
* This is to prevent supply chain attacks via unverified API providers.
70+
*
71+
* @param array $results The Results of the Plugins API call.
72+
*
73+
* @return array $results The updated Results of the Plugins API call.
74+
*/
75+
public function hide_self_plugins_api_result( $results ) {
76+
if (
77+
! is_admin() ||
78+
! isset( $_REQUEST['s'] )
79+
) {
80+
return $results;
81+
}
82+
83+
if (
84+
! is_object( $results ) ||
85+
! isset( $results->plugins ) ||
86+
! is_array( $results->plugins )
87+
) {
88+
return $results;
89+
}
90+
91+
foreach ( $results->plugins as $key => $plugin ) {
92+
if ( isset( $plugin['slug'] ) && ( 'aspireupdate' === $plugin['slug'] ) ) {
93+
unset( $results->plugins[ $key ] );
94+
break;
95+
}
96+
}
97+
return $results;
98+
}
6599
}

0 commit comments

Comments
 (0)