diff --git a/CHANGELOG.md b/CHANGELOG.md index 11bfdc0..e7638f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [Unreleased] + +### Security +- Added nonce validation in admin pages + ## [2.1.1] - 2022-09-15 ### Fixed diff --git a/inc/class-mailrelaypages.php b/inc/class-mailrelaypages.php index f1378da..27f47fd 100644 --- a/inc/class-mailrelaypages.php +++ b/inc/class-mailrelaypages.php @@ -39,7 +39,18 @@ public function render_admin_page() { load_plugin_textdomain( 'mailrelay', false, 'mailrelay/languages/' ); - if ( isset( $_POST['action'] ) ) { + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated + if ( isset($_SERVER['REQUEST_METHOD']) && 'POST' === $_SERVER['REQUEST_METHOD'] && ! wp_verify_nonce(sanitize_key($_POST['_mailrelay_nonce']), '_mailrelay_nonce') ) { + wp_die( + 'Invalid Nonce', + 'Invalid Nonce', + array( + 'back_link' => true, + ) + ); + } + + if ( isset($_POST['action']) ) { if ( 'mailrelay_save_authentication_settings' === $_POST['action'] ) { $response = $this->process_save_connection_settings(); } elseif ( 'mailrelay_save_settings' === $_POST['action'] ) { @@ -108,10 +119,11 @@ public function render_admin_page() {
@@ -130,6 +142,7 @@ public function render_admin_page() {