Repository navigation
Security fix - z8zyy1tv2y #3275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
harunollyo
wants to merge
4
commits into
4.3.0
Choose a base branch
from
security/z8zyy1tv2x
base: 4.3.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
dc95da9
Merge branch '4.2.2' of https://github.com/themeum/tutor into harun
harunollyo 6ed4256
Merge branch '4.3.0' of https://github.com/themeum/tutor into harun
harunollyo 817ae08
fix:Quiz can be moved to another topic without proper validation
harunollyo 52cbc4a
fix: prevent overwriting post author when updating quiz in QuizBuilder
harunollyo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -810,11 +810,22 @@ public function save_quiz( $topic_id, $payload ) { | |
| $errors = array(); | ||
|
|
||
| $validation = $this->validate_payload( $payload ); | ||
| if ( $validation->success && tutor()->topics_post_type !== get_post_type( $topic_id ) ) { | ||
| $validation->success = false; | ||
| $validation->errors['topic_id'][] = __( 'Invalid topic id provided', 'tutor' ); | ||
| } | ||
|
|
||
| if ( ! tutor_utils()->can_user_manage( 'topic', $topic_id ) ) { | ||
| $validation->success = false; | ||
| $validation->errors['topic_id'][] = tutor_utils()->error_message(); | ||
| } | ||
|
|
||
| $existing_quiz_id = (int) ( $payload['ID'] ?? 0 ); | ||
| if ( $validation->success && $existing_quiz_id && (int) wp_get_post_parent_id( $existing_quiz_id ) !== (int) $topic_id ) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Same issue is here. |
||
| $validation->success = false; | ||
| $validation->errors['topic_id'][] = __( 'Quiz does not belong to the submitted topic', 'tutor' ); | ||
| } | ||
|
|
||
| if ( ! $validation->success ) { | ||
| return (object) array( | ||
| 'success' => false, | ||
|
|
@@ -847,6 +858,7 @@ public function save_quiz( $topic_id, $payload ) { | |
| // Add or update the quiz. | ||
| if ( $is_update ) { | ||
| $quiz_data['ID'] = $quiz_id; | ||
| unset( $quiz_data['post_author'] ); | ||
| } | ||
|
|
||
| $quiz_id = wp_insert_post( $quiz_data ); | ||
|
|
@@ -908,6 +920,9 @@ public function ajax_quiz_builder_save() { | |
| $course_cls = new Course( false ); | ||
|
|
||
| $course_cls->check_access( $course_id ); | ||
| if ( $topic_id && (int) wp_get_post_parent_id( $topic_id ) !== $course_id ) { | ||
| $this->json_response( tutor_utils()->error_message(), null, HttpHelper::STATUS_FORBIDDEN ); | ||
| } | ||
|
|
||
| $result = $this->save_quiz( $topic_id, wp_slash( $payload ) ); | ||
| if ( $result->success ) { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking the
validtion->successwill not add the post type error with the validation error. Since the post type check is part of validation, the error should be included regardless of the validation->success status. Now, the user will not know the post type error until it passes the existing validations.