Skip to content

Commit

Permalink
Add nonce to AJAX request
Browse files Browse the repository at this point in the history
  • Loading branch information
mmtr committed Feb 6, 2020
1 parent 8c57b4a commit c48ffdb
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions _inc/jetpack-jitm.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ jQuery( document ).ready( function( $ ) {
button.attr( 'disabled', true );
$.post( window.ajaxurl, {
action: button.data( 'ajax-action' ),
_nonce: $el.data( 'ajax-nonce' ),
} )
.done( function() {
$template.fadeOut( 'slow' );
Expand Down
2 changes: 2 additions & 0 deletions modules/tos/jetpack-tos.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* Makes a request to the WP.com legal endpoint to mark the Terms of Service as accepted.
*/
function accept_tos() {
check_ajax_referer( 'wp_ajax_action', '_nonce' );

$response = Client::wpcom_json_api_request_as_user(
'/legal',
'2',
Expand Down
1 change: 1 addition & 0 deletions packages/jitm/src/class-jitm.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ public function ajax_message() {
?>
<div class="jetpack-jitm-message"
data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_rest' ) ); ?>"
data-ajax-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_ajax_action' ) ); ?>"
data-message-path="<?php echo esc_attr( $message_path ); ?>"
data-query="<?php echo urlencode_deep( $query_string ); ?>"
data-redirect="<?php echo urlencode_deep( $current_screen ); ?>"
Expand Down

0 comments on commit c48ffdb

Please sign in to comment.