Skip to content

Commit 1dd248e

Browse files
committed
Remediate security vulnerabilities
1 parent 12c9a9e commit 1dd248e

1 file changed

Lines changed: 27 additions & 4 deletions

File tree

index.php

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,20 @@ final class NotionLink {
4141
public function __construct() {
4242
if ( ! defined( 'NOTIONLINK_ENDPOINT' ) ) {
4343
add_action( 'admin_notices', static function () {
44+
if ( ! current_user_can( 'manage_options' ) ) {
45+
return;
46+
}
47+
4448
$class = 'notice notice-error';
45-
$message = __( 'No endpoint URL has been set. Add a `define( "NOTIONLINK_ENDPOINT, "https://url.com/example" );` to your functions.php or wp-config.php file.', 'NotionLink' );
49+
$message = __( 'NotionLink requires an endpoint URL. Please check your configuration.', 'NotionLink' );
4650
printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) );
4751
} );
4852

4953
return;
5054
}
5155

52-
if ( isset( $_GET['cacheBust'] ) ) {
56+
if ( isset( $_GET['cacheBust'] ) && current_user_can( 'manage_options' ) ) {
57+
check_admin_referer( 'notionlink_cache_bust' );
5358
delete_transient( self::KEY );
5459
}
5560

@@ -62,6 +67,24 @@ public function __construct() {
6267
}
6368

6469
add_filter( 'plugin_row_meta', [ $this, 'addNotionLinkToMeta' ], 9999, 4 );
70+
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), [ $this, 'addPluginActionLinks' ] );
71+
}
72+
73+
74+
/**
75+
* @param array $links
76+
*
77+
* @return array
78+
*/
79+
public function addPluginActionLinks( array $links ): array {
80+
if ( ! current_user_can( 'manage_options' ) ) {
81+
return $links;
82+
}
83+
84+
$url = wp_nonce_url( admin_url( 'plugins.php?cacheBust=1' ), 'notionlink_cache_bust' );
85+
$links[] = sprintf( '<a href="%1$s">%2$s</a>', esc_url( $url ), __( 'Clear Cache', 'NotionLink' ) );
86+
87+
return $links;
6588
}
6689

6790

@@ -90,7 +113,7 @@ public function addNotionLinkToMeta( array $plugin_meta, string $plugin_file, ar
90113
) {
91114
$url = array_column( $this->pluginData, 'url', 'plugin' )[ $plugin_file ];
92115

93-
$link_and_icon = '<a href="' . $url . '" target="_blank" style="transform: translateY(5px);height: 21px;margin-left: 4px;display: inline-block;">' . notionIcon() . '</a>';
116+
$link_and_icon = '<a href="' . esc_url( $url ) . '" target="_blank" style="transform: translateY(5px);height: 21px;margin-left: 4px;display: inline-block;">' . notionIcon() . '</a>';
94117

95118
/**
96119
* Filter the link and icon html right before it gets added to the plugin meta.
@@ -201,6 +224,6 @@ function notionIcon(): string {
201224
],
202225
);
203226

204-
return wp_kses( $filtered_icon, $allowed_tags );
227+
return wp_kses( $icon, $allowed_tags );
205228
}
206229

0 commit comments

Comments
 (0)