Skip to content

Commit

Permalink
Enhanced security issue
Browse files Browse the repository at this point in the history
  • Loading branch information
kawsarahmedr committed Jul 30, 2024
1 parent 08eec4c commit 49f527b
Show file tree
Hide file tree
Showing 8 changed files with 371 additions and 496 deletions.
818 changes: 336 additions & 482 deletions composer.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Admin/ListTables/ActivationsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ protected function extra_tablenav( $which ) {
* @since 1.4.6
*/
public function process_bulk_actions( $doaction ) {
if ( $doaction && check_ajax_referer( 'bulk-activations' ) ) {
if ( $doaction && check_ajax_referer( 'bulk-activations' ) && current_user_can( wcsn_get_manager_role() ) ) {
if ( isset( $_REQUEST['id'] ) ) {
$ids = wp_parse_id_list( wp_unslash( $_REQUEST['id'] ) );
} elseif ( isset( $_REQUEST['ids'] ) ) {
Expand Down
5 changes: 3 additions & 2 deletions src/Admin/ListTables/KeysTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ public function no_items() {
* @return array $views All the views sellable
*/
public function get_views() {
$current = isset( $_GET['status'] ) ? sanitize_key( wp_unslash( $_GET['status'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
wp_verify_nonce( '_nonce' );
$current = isset( $_GET['status'] ) ? sanitize_key( wp_unslash( $_GET['status'] ) ) : '';
$available_count = '&nbsp;<span class="count">(' . $this->available_count . ')</span>';
$pending_count = '&nbsp;<span class="count">(' . $this->pending_count . ')</span>';
$sold_count = '&nbsp;<span class="count">(' . $this->sold_count . ')</span>';
Expand Down Expand Up @@ -291,7 +292,7 @@ protected function extra_tablenav( $which ) {
* @since 1.4.6
*/
public function process_bulk_actions( $doaction ) {
if ( $doaction && check_ajax_referer( 'bulk-' . $this->_args['plural'] ) ) {
if ( $doaction && check_ajax_referer( 'bulk-' . $this->_args['plural'] ) && current_user_can( wcsn_get_manager_role() ) ) {
if ( wp_unslash( isset( $_REQUEST['id'] ) ) ) {
$ids = wp_parse_id_list( wp_unslash( $_REQUEST['id'] ) );
} elseif ( isset( $_REQUEST['ids'] ) ) {
Expand Down
3 changes: 2 additions & 1 deletion src/Admin/ListTables/ListTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class ListTable extends \WP_List_Table {
* @return mixed Un-sanitized request var
*/
protected function get_request_var( $param = '', $fallback = false ) {
return isset( $_REQUEST[ $param ] ) ? sanitize_text_field( wp_unslash( $_REQUEST[ $param ] ) ) : $fallback; // phpcs:ignore WordPress.Security.NonceVerification
wp_verify_nonce( '_nonce' );
return isset( $_REQUEST[ $param ] ) ? sanitize_text_field( wp_unslash( $_REQUEST[ $param ] ) ) : $fallback;
}

/**
Expand Down
24 changes: 15 additions & 9 deletions src/Admin/Menus.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public function __construct() {
* @since 1.4.6
*/
public function setup_screen() {
if ( isset( $_GET['edit'] ) || isset( $_GET['delete'] ) || isset( $_GET['add'] ) || isset( $_GET['generate'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
wp_verify_nonce( '_nonce' );

if ( isset( $_GET['edit'] ) || isset( $_GET['delete'] ) || isset( $_GET['add'] ) || isset( $_GET['generate'] ) ) {
return;
}

Expand Down Expand Up @@ -201,8 +203,9 @@ public function promo_menu() {
* @return void
*/
public function output_main_page() {
$add = isset( $_GET['add'] ) ? true : false; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$edit = isset( $_GET['edit'] ) ? absint( $_GET['edit'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
wp_verify_nonce( '_nonce' );
$add = isset( $_GET['add'] ) ? true : false;
$edit = isset( $_GET['edit'] ) ? absint( $_GET['edit'] ) : 0;
if ( $edit ) {
$key = new Key( $edit );
if ( ! $key->exists() ) {
Expand Down Expand Up @@ -239,6 +242,7 @@ public function output_activations_page() {
* @return void
*/
public function output_tools_page() {
wp_verify_nonce( '_nonce' );
$tabs = array(
'generators' => __( 'Generators', 'wc-serial-numbers' ),
'api' => __( 'API Toolkit', 'wc-serial-numbers' ),
Expand All @@ -253,8 +257,8 @@ public function output_tools_page() {

$tabs = apply_filters( 'wc_serial_numbers_tools_tabs', $tabs );
$tab_ids = array_keys( $tabs );
$current_tab = isset( $_GET['tab'] ) ? sanitize_key( wp_unslash( $_GET['tab'] ) ) : reset( $tab_ids ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$current_tab = isset( $_GET['tab'] ) ? sanitize_key( wp_unslash( $_GET['tab'] ) ) : reset( $tab_ids );
$page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : '';

Admin::view(
'html-tools.php',
Expand All @@ -273,14 +277,15 @@ public function output_tools_page() {
* @return void
*/
public function output_reports_page() {
wp_verify_nonce( '_nonce' );
$tabs = array(
'stock' => __( 'Stock', 'wc-serial-numbers' ),
);

$tabs = apply_filters( 'wc_serial_numbers_reports_tabs', $tabs );
$tab_ids = array_keys( $tabs );
$current_tab = isset( $_GET['tab'] ) ? sanitize_key( wp_unslash( $_GET['tab'] ) ) : reset( $tab_ids ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$current_tab = isset( $_GET['tab'] ) ? sanitize_key( wp_unslash( $_GET['tab'] ) ) : reset( $tab_ids );
$page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : '';

Admin::view(
'html-reports.php',
Expand All @@ -299,8 +304,9 @@ public function output_reports_page() {
* @return void
*/
public function go_pro_redirect() {
if ( isset( $_GET['page'] ) && 'go_wcsn_pro' === $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
wp_redirect( 'https://pluginever.com/plugins/woocommerce-serial-numbers-pro/?utm_source=admin-menu&utm_medium=link&utm_campaign=upgrade&utm_id=wc-serial-numbers' ); // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect
wp_verify_nonce( '_nonce' );
if ( isset( $_GET['page'] ) && 'go_wcsn_pro' === $_GET['page'] ) {
wp_safe_redirect( 'https://pluginever.com/plugins/woocommerce-serial-numbers-pro/?utm_source=admin-menu&utm_medium=link&utm_campaign=upgrade&utm_id=wc-serial-numbers' );
die;
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/Admin/Metaboxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ public static function product_save_data() {
if ( ! isset( $_POST['woocommerce_meta_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['woocommerce_meta_nonce'] ) ), 'woocommerce_save_data' ) ) {
return;
}

// Must have WC Serial Numbers manager role to access this endpoint.
if ( ! current_user_can( wcsn_get_manager_role() ) ) {
return;
}

$status = isset( $_POST['_is_serial_number'] ) ? 'yes' : 'no';
$source = isset( $_POST['_serial_key_source'] ) ? sanitize_text_field( wp_unslash( $_POST['_serial_key_source'] ) ) : 'custom_source';
update_post_meta( $post->ID, '_is_serial_number', $status );
Expand Down
6 changes: 6 additions & 0 deletions src/Admin/Notices.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ public function output_notices() {
*/
public function dismiss_notice() {
check_ajax_referer( 'wc_serial_numbers_dismiss_notice', 'nonce' );

// Must have WC Serial Numbers manager role to access this endpoint.
if ( ! current_user_can( wcsn_get_manager_role() ) ) {
wp_die();
}

$notice_id = isset( $_POST['notice_id'] ) ? sanitize_text_field( wp_unslash( $_POST['notice_id'] ) ) : '';
if ( $notice_id ) {
update_option( 'wc_serial_numbers_dismissed_notices', array_merge( get_option( 'wc_serial_numbers_dismissed_notices', array() ), array( $notice_id ) ) );
Expand Down
3 changes: 2 additions & 1 deletion src/Admin/views/html-list-keys.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@

<form id="wcsn-keys-table" method="get">
<?php
$status = isset( $_GET['status'] ) ? sanitize_text_field( wp_unslash( $_GET['status'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
wp_verify_nonce( '_nonce' );
$status = isset( $_GET['status'] ) ? sanitize_text_field( wp_unslash( $_GET['status'] ) ) : '';
$list_table->prepare_items();
$list_table->views();
$list_table->search_box( __( 'Search key', 'wc-serial-numbers' ), 'key' );
Expand Down

0 comments on commit 49f527b

Please sign in to comment.