Repository navigation
Fix: Require edit_post capability for raw content in docs search - #375
Open
iftakharul-islam wants to merge 1 commit into
Open
iftakharul-islam wants to merge 1 commit into
iftakharul-islam wants to merge 1 commit into
Conversation
The public wp/v2/docs/search route accepted context=edit from guests and returned content.raw, exposing password-protected docs. Raw fields are now added only when the user can edit the doc, and the route declares a context arg limited to view/embed/edit.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes weDevsOfficial/wedocs-pro#453
Problem
GET /wp/v2/docs/searchis public (permission_callback => '__return_true'). When a request passedcontext=edit,prepare_item_for_response()addedtitle.rawandcontent.rawwithout any capability check. A guest could read the full body of password-protected docs without the password.Fix
prepare_item_for_response()adds raw fields only whencurrent_user_can( 'edit_post', $doc->ID ). Covers the search route and the parents route, which share this method.contextarg (view/embed/edit, defaultview), so unknown values are rejected withrest_invalid_param.Logged-in editors still get raw fields with
context=edit, so nothing changes for the admin UI.Proof
Tested on WordPress Playground (WP latest, PHP 8.3) with one published password-protected doc (body
SECRET-BODY-12345) and one public doc.context=viewcontext=editcontext=bogusrest_invalid_paramcontext=editThe editor row returning the body is expected: editors are allowed to read raw content.