Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nonce verification to SimpleShop disconnect feature #138

Merged
merged 3 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions package-lock.json

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

14 changes: 13 additions & 1 deletion src/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,15 @@ public function field_type_disconnect_button(
$object_type,
$field_type_object
) {
$url = add_query_arg( [
'_wpnonce' => wp_create_nonce(),
'page' => 'ssc_options',
'disconnect_simpleshop' => 1,
], admin_url( 'admin.php' ) );

printf(
'<a href="%s">%s</a>',
htmlspecialchars( admin_url( 'admin.php?page=ssc_options&disconnect_simpleshop=1' ), ENT_QUOTES ),
htmlspecialchars( $url, ENT_QUOTES ),
__( 'Disconnect SimpleShop', 'simpleshop-cz' )
);
}
Expand Down Expand Up @@ -339,6 +345,10 @@ public function add_options_page_metabox() {
* Maybe delete the API keys
*/
public function maybe_disconnect_simpleshop() {
if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'] ) ) {
return;
}

if ( ! isset( $_GET['disconnect_simpleshop'] ) || $_GET['disconnect_simpleshop'] !== '1' ) {
return;
}
Expand All @@ -353,6 +363,8 @@ public function maybe_disconnect_simpleshop() {

// Update the SS options
update_option( $this->key, $options );
$url = add_query_arg( [ 'page' => 'ssc_options' ], admin_url( 'admin.php' ) );
wp_redirect( $url );
}

/**
Expand Down