Skip to content

Commit 0bd9b20

Browse files
committed
address some secure issue
1 parent 569d9e6 commit 0bd9b20

File tree

9 files changed

+28
-28
lines changed

9 files changed

+28
-28
lines changed

inc/Ajax.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,27 +43,27 @@ public function delete_comment() {
4343
}
4444

4545
function delete_answer() {
46-
if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], '_dwqa_action_remove_answer_nonce' ) || 'dwqa_delete_answer' !== $_GET['action'] ) {
46+
if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], '_dwqa_action_remove_answer_nonce' ) || 'dwqa_delete_answer' !== sanitize_text_field( $_GET['action'] ) ) {
4747
wp_die( __( 'Are you cheating huh?', 'dwqa' ) );
4848
}
4949

5050
if ( ! isset( $_GET['answer_id'] ) ) {
5151
wp_die( __( 'Answer is missing.', 'dwqa' ), 'error' );
5252
}
5353

54-
if ( 'dwqa-answer' !== get_post_type( $_GET['answer_id'] ) ) {
54+
if ( 'dwqa-answer' !== get_post_type( intval( $_GET['answer_id'] ) ) ) {
5555
wp_die( __( 'This post is not answer.', 'dwqa' ) );
5656
}
5757

5858
if ( !dwqa_current_user_can( 'delete_answer' ) ) {
5959
wp_die( __( 'You do not have permission to delete this post.', 'dwqa' ) );
6060
}
6161

62-
do_action( 'dwqa_prepare_delete_answer', $_GET['answer_id'] );
62+
do_action( 'dwqa_prepare_delete_answer', intval( $_GET['answer_id'] ) );
6363

64-
$question_id = get_post_meta( $_GET['answer_id'], '_question', true );
64+
$question_id = get_post_meta( intval( $_GET['answer_id'] ), '_question', true );
6565

66-
$id = wp_delete_post( $_GET['answer_id'] );
66+
$id = wp_delete_post( intval( $_GET['answer_id'] ) );
6767

6868
if ( is_wp_error( $id ) ) {
6969
wp_die( $id->get_error_message() );
@@ -72,7 +72,7 @@ function delete_answer() {
7272
$answer_count = get_post_meta( $question_id, '_dwqa_answers_count', true );
7373
update_post_meta( $question_id, '_dwqa_answers_count', (int) $answer_count - 1 );
7474

75-
do_action( 'dwqa_delete_answer', $_GET['answer_id'], $question_id );
75+
do_action( 'dwqa_delete_answer', intval( $_GET['answer_id'] ), $question_id );
7676

7777
wp_redirect( get_permalink( $question_id ) );
7878
exit();
@@ -146,31 +146,31 @@ public function unvote_best_answer() {
146146

147147
public function delete_question() {
148148
global $dwqa_general_settings;
149-
if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], '_dwqa_action_remove_question_nonce' ) || 'dwqa_delete_question' !== $_GET['action'] ) {
149+
if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_text_field( $_GET['_wpnonce'] ), '_dwqa_action_remove_question_nonce' ) || 'dwqa_delete_question' !== $_GET['action'] ) {
150150
wp_die( __( 'Are you cheating huh?', 'dwqa' ) );
151151
}
152152

153153
if ( ! isset( $_GET['question_id'] ) ) {
154154
wp_die( __( 'Question is missing.', 'dwqa' ), 'error' );
155155
}
156156

157-
if ( 'dwqa-question' !== get_post_type( $_GET['question_id'] ) ) {
157+
if ( 'dwqa-question' !== get_post_type( intval( $_GET['question_id'] ) ) ) {
158158
wp_die( __( 'This post is not question.', 'dwqa' ) );
159159
}
160160

161161
if ( !dwqa_current_user_can( 'delete_answer' ) ) {
162162
wp_die( __( 'You do not have permission to delete this post.', 'dwqa' ) );
163163
}
164164

165-
do_action( 'before_delete_post', $_GET['question_id'] );
165+
do_action( 'before_delete_post', intval( $_GET['question_id'] ) );
166166

167-
$id = wp_delete_post( $_GET['question_id'] );
167+
$id = wp_delete_post( intval( $_GET['question_id'] ) );
168168

169169
if ( is_wp_error( $id ) ) {
170170
wp_die( $id->get_error_message() );
171171
}
172172

173-
do_action( 'dwqa_delete_question', $_GET['question_id'] );
173+
do_action( 'dwqa_delete_question', intval( $_GET['question_id'] ) );
174174

175175
$url = home_url();
176176
if ( isset( $dwqa_general_settings['pages']['archive-question'] ) ) {

inc/Filter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ public function prepare_archive_posts() {
99

1010
$posts_per_page = isset( $dwqa_general_settings['posts-per-page'] ) ? $dwqa_general_settings['posts-per-page'] : 5;
1111
$user = isset( $_GET['user'] ) && !empty( $_GET['user'] ) ? urldecode( $_GET['user'] ) : false;
12-
$filter = isset( $_GET['filter'] ) && !empty( $_GET['filter'] ) ? $_GET['filter'] : 'all';
13-
$search_text = isset( $_GET['qs'] ) ? $_GET['qs'] : false;
14-
$sort = isset( $_GET['sort'] ) ? $_GET['sort'] : '';
12+
$filter = isset( $_GET['filter'] ) && !empty( $_GET['filter'] ) ? sanitize_text_field( $_GET['filter'] ) : 'all';
13+
$search_text = isset( $_GET['qs'] ) ? sanitize_text_field( $_GET['qs'] ) : false;
14+
$sort = isset( $_GET['sort'] ) ? sanitize_text_field( $_GET['sort'] ) : '';
1515
$query = array(
1616
'post_type' => 'dwqa-question',
1717
'posts_per_page' => $posts_per_page,

inc/Posts/Answer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ public function set_has_archive() {
264264
}
265265

266266
public function columns_head( $defaults ) {
267-
if ( isset( $_GET['post_type'] ) && $_GET['post_type'] == $this->get_slug() ) {
267+
if ( isset( $_GET['post_type'] ) && sanitize_text_field( $_GET['post_type'] ) == $this->get_slug() ) {
268268
$defaults = array(
269269
'cb' => '<input type="checkbox">',
270270
'info' => __( 'Answer', 'dwqa' ),

inc/Settings.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -747,14 +747,14 @@ public function init_options(){
747747
}
748748

749749
public function flush_rules() {
750-
if ( isset( $_GET['page'] ) && 'dwqa-settings' == $_GET['page'] ) {
750+
if ( isset( $_GET['page'] ) && 'dwqa-settings' == esc_html( $_GET['page'] ) ) {
751751
flush_rewrite_rules();
752752
}
753753
}
754754

755755
public function current_email_tab() {
756-
if ( isset( $_GET['tab'] ) && 'email' == $_GET['tab'] ) {
757-
return isset( $_GET['section'] ) ? $_GET['section'] : 'general';
756+
if ( isset( $_GET['tab'] ) && 'email' == esc_html( $_GET['tab'] ) ) {
757+
return isset( $_GET['section'] ) ? esc_html( $_GET['section'] ) : 'general';
758758
}
759759

760760
return false;

inc/Template.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
function dwqa_breadcrumb() {
77
global $dwqa_general_settings;
88
$title = get_the_title( $dwqa_general_settings['pages']['archive-question'] );
9-
$search = isset( $_GET['qs'] ) ? $_GET['qs'] : false;
10-
$author = isset( $_GET['user'] ) ? $_GET['user'] : false;
9+
$search = isset( $_GET['qs'] ) ? esc_html( $_GET['qs'] ) : false;
10+
$author = isset( $_GET['user'] ) ? esc_html( $_GET['user'] ) : false;
1111
$output = '';
1212
if ( !is_singular( 'dwqa-question' ) ) {
1313
$term = get_query_var( 'dwqa-question_category' ) ? get_query_var( 'dwqa-question_category' ) : ( get_query_var( 'dwqa-question_tag' ) ? get_query_var( 'dwqa-question_tag' ) : false );
@@ -75,7 +75,7 @@ function dwqa_archive_question_filter_layout() {
7575
function dwqa_search_form() {
7676
?>
7777
<form id="dwqa-search" class="dwqa-search">
78-
<input data-nonce="<?php echo wp_create_nonce( '_dwqa_filter_nonce' ) ?>" type="text" placeholder="<?php _e( 'What do you want to know?', 'dwqa' ); ?>" name="qs" value="<?php echo isset( $_GET['qs'] ) ? $_GET['qs'] : '' ?>">
78+
<input data-nonce="<?php echo wp_create_nonce( '_dwqa_filter_nonce' ) ?>" type="text" placeholder="<?php _e( 'What do you want to know?', 'dwqa' ); ?>" name="qs" value="<?php echo isset( $_GET['qs'] ) ? esc_html( $_GET['qs'] ) : '' ?>">
7979
</form>
8080
<?php
8181
}
@@ -92,7 +92,7 @@ function dwqa_class_for_question_details_container(){
9292
function dwqa_answer_paginate_link() {
9393
global $wp_query;
9494
$question_url = get_permalink();
95-
$page = isset( $_GET['ans-page'] ) ? $_GET['ans-page'] : 1;
95+
$page = isset( $_GET['ans-page'] ) ? intval( $_GET['ans-page'] ) : 1;
9696

9797
$args = array(
9898
'base' => add_query_arg( 'ans-page', '%#%', $question_url ),

inc/helper/functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ function dwqa_question_status( $question = false ) {
234234
}
235235

236236
function dwqa_current_filter() {
237-
return isset( $_GET['filter'] ) && !empty( $_GET['filter'] ) ? $_GET['filter'] : 'all';
237+
return isset( $_GET['filter'] ) && !empty( $_GET['filter'] ) ? sanitize_text_field( $_GET['filter'] ) : 'all';
238238
}
239239

240240
function dwqa_get_ask_link() {

templates/archive-question-filter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
*/
88

99
global $dwqa_general_settings;
10-
$sort = isset( $_GET['sort'] ) ? $_GET['sort'] : '';
11-
$filter = isset( $_GET['filter'] ) ? $_GET['filter'] : 'all';
10+
$sort = isset( $_GET['sort'] ) ? esc_html( $_GET['sort'] ) : '';
11+
$filter = isset( $_GET['filter'] ) ? esc_html( $_GET['filter'] ) : 'all';
1212
?>
1313
<div class="dwqa-question-filter">
1414
<span><?php _e( 'Filter:', 'dwqa' ); ?></span>

templates/content-edit.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
?>
99

1010
<?php
11-
$comment_id = isset( $_GET['comment_edit'] ) && is_numeric( $_GET['comment_edit'] ) ? $_GET['comment_edit'] : false;
12-
$edit_id = isset( $_GET['edit'] ) && is_numeric( $_GET['edit'] ) ? $_GET['edit'] : ( $comment_id ? $comment_id : false );
11+
$comment_id = isset( $_GET['comment_edit'] ) && is_numeric( $_GET['comment_edit'] ) ? intval( $_GET['comment_edit'] ) : false;
12+
$edit_id = isset( $_GET['edit'] ) && is_numeric( $_GET['edit'] ) ? intval( $_GET['edit'] ) : ( $comment_id ? $comment_id : false );
1313
if ( !$edit_id ) return;
1414
$type = $comment_id ? 'comment' : ( 'dwqa-question' == get_post_type( $edit_id ) ? 'question' : 'answer' );
1515
?>

upgrades/upgrades.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static function init() {
1616
}
1717

1818
public static function admin_notices() {
19-
if ( isset( $_GET['page']) && 'dwqa-upgrades' == $_GET['page'] ) {
19+
if ( isset( $_GET['page']) && 'dwqa-upgrades' == esc_html( $_GET['page'] ) ) {
2020
return;
2121
}
2222

0 commit comments

Comments
 (0)