Skip to content

Commit

Permalink
Implement nonce verification for Ajax calls
Browse files Browse the repository at this point in the history
  • Loading branch information
SohamPatel46 committed Feb 21, 2024
1 parent 0065784 commit c383f14
Show file tree
Hide file tree
Showing 5 changed files with 13,529 additions and 2 deletions.
2 changes: 1 addition & 1 deletion admin/js/build/rt-transcoder-block-editor-support.build.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion admin/js/rt-transcoder-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
if ( confirm( rt_transcoder_script.disable_encoding ) ) {

var data = {
action: 'rt_disable_transcoding'
action: 'rt_disable_transcoding',
security: rt_transcoder_script.security_nonce
};

if ( $( this ).next( 'img' ).length === 0 ) {
Expand Down
1 change: 1 addition & 0 deletions admin/rt-transcoder-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ public function enqueue_scripts_styles() {
'enable_encoding' => esc_html__( 'Are you sure you want to enable the transcoding service?', 'transcoder' ),
'something_went_wrong' => esc_html__( 'Something went wrong. Please ', 'transcoder' ) . '<a href onclick="location.reload();">' . esc_html__( 'refresh', 'transcoder' ) . '</a>' . esc_html__( ' page.', 'transcoder' ),
'error_empty_key' => esc_html__( 'Please enter the license key.', 'transcoder' ),
'security_nonce' => esc_js( wp_create_nonce( 'check-transcoder-ajax-nonce' ) )
);

wp_localize_script( 'rt-transcoder-main', 'rt_transcoder_script', $localize_script_data );
Expand Down
4 changes: 4 additions & 0 deletions admin/rt-transcoder-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,7 @@ public function handle_callback() {
* @since 1.0.0
*/
public function hide_transcoding_notice() {
check_ajax_referer( 'check-transcoder-ajax-nonce', 'security', true );
update_site_option( 'rt-transcoding-service-notice', true );
update_site_option( 'rt-transcoding-expansion-notice', true );
echo true;
Expand All @@ -1281,6 +1282,7 @@ public function hide_transcoding_notice() {
* @since 1.0
*/
public function enter_api_key() {
check_ajax_referer( 'check-transcoder-ajax-nonce', 'security', true );
$apikey = transcoder_filter_input( INPUT_GET, 'apikey', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
if ( ! empty( $apikey ) ) {
echo wp_json_encode( array( 'apikey' => $apikey ) );
Expand All @@ -1296,6 +1298,7 @@ public function enter_api_key() {
* @since 1.0.0
*/
public function disable_transcoding() {
check_ajax_referer( 'check-transcoder-ajax-nonce', 'security', true );
update_site_option( 'rt-transcoding-api-key', '' );
esc_html_e( 'Transcoding disabled successfully.', 'transcoder' );
die();
Expand All @@ -1307,6 +1310,7 @@ public function disable_transcoding() {
* @since 1.0.0
*/
public function enable_transcoding() {
check_ajax_referer( 'check-transcoder-ajax-nonce', 'security', true );
update_site_option( 'rt-transcoding-api-key', $this->stored_api_key );
esc_html_e( 'Transcoding enabled successfully.', 'transcoder' );
die();
Expand Down
Loading

0 comments on commit c383f14

Please sign in to comment.