From 565c596872452a01b7e94b226773ef8931558963 Mon Sep 17 00:00:00 2001 From: Sazedul Haque Date: Wed, 2 Dec 2026 12:42:04 +0600 Subject: [PATCH] Prevent course creation from updating posts Strip post IDs and arbitrary meta input from course creation requests, and check access without trusting a submitted post ID. --- classes/Course.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/classes/Course.php b/classes/Course.php index 0f20a0e78f..83bebe1b3f 100644 --- a/classes/Course.php +++ b/classes/Course.php @@ -1089,9 +1089,6 @@ public function ajax_course_list() { public function ajax_create_course() { tutor_utils()->check_nonce(); - $course_id = intval( wp_unslash( $_POST['ID'] ?? 0 ) ); - $this->check_access( $course_id ); // Check user cap for the given id before processing. - $params = Input::sanitize_array( //phpcs:ignore WordPress.Security.NonceVerification.Missing $_POST, @@ -1101,6 +1098,12 @@ public function ajax_create_course() { ) ); + // This endpoint only creates new courses. Strip any fields that could + // cause wp_insert_post() to update an existing post or write arbitrary meta. + unset( $params['ID'], $params['import_id'], $params['meta_input'] ); + + $this->check_access(); + $params['post_type'] = tutor()->course_post_type; // Validate inputs.