Repository navigation
Honor REST access controls for protected block content #118
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6c6633a
Fix REST access controls for protected content
maxschmeling 99cbf95
Restore REST validation filter overrides
maxschmeling 30793b1
Wrap REST controller check in try/catch, log error and do not allow a…
alecgeatches fae2906
Add README clarifications about security change
alecgeatches 6326764
Add additional tests for wp_block and password-protected posts
alecgeatches 9928675
Merge branch 'trunk' into fix/vipcms-2342-protected-content
alecgeatches 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
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
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
26 changes: 26 additions & 0 deletions
26
tests/mocks/constructor-throwing-rest-posts-controller-mock.php
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 |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <?php | ||
| /** | ||
| * REST posts controller mock that throws during construction. | ||
| * | ||
| * @package vip-block-data-api | ||
| */ | ||
|
|
||
| namespace WPCOMVIP\BlockDataApi; | ||
|
|
||
| use Exception; | ||
| use WP_REST_Posts_Controller; | ||
|
|
||
| /** | ||
| * Test controller that throws during construction. | ||
| */ | ||
| class ConstructorThrowingRestPostsController extends WP_REST_Posts_Controller { | ||
| /** | ||
| * Throw instead of constructing the controller. | ||
| * | ||
| * @param string $post_type Post type. | ||
| * @throws Exception Always. | ||
| */ | ||
| public function __construct( $post_type ) { | ||
| throw new Exception( 'Controller constructor failure' ); | ||
| } | ||
| } |
27 changes: 27 additions & 0 deletions
27
tests/mocks/permission-throwing-rest-posts-controller-mock.php
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 |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <?php | ||
| /** | ||
| * REST posts controller mock that throws during the item permission check. | ||
| * | ||
| * @package vip-block-data-api | ||
| */ | ||
|
|
||
| namespace WPCOMVIP\BlockDataApi; | ||
|
|
||
| use Exception; | ||
| use WP_REST_Posts_Controller; | ||
| use WP_REST_Request; | ||
|
|
||
| /** | ||
| * Test controller that throws during the item permission check. | ||
| */ | ||
| class PermissionThrowingRestPostsController extends WP_REST_Posts_Controller { | ||
| /** | ||
| * Throw instead of checking permissions. | ||
| * | ||
| * @param WP_REST_Request $request Full details about the request. | ||
| * @throws Exception Always. | ||
| */ | ||
| public function get_item_permissions_check( $request ) { | ||
| throw new Exception( 'Permission check failure' ); | ||
| } | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <?php | ||
| /** | ||
| * REST posts controller mock. | ||
| * | ||
| * @package vip-block-data-api | ||
| */ | ||
|
|
||
| namespace WPCOMVIP\BlockDataApi; | ||
|
|
||
| use WP_REST_Posts_Controller; | ||
| use WP_REST_Request; | ||
|
|
||
| /** | ||
| * Test controller that denies every item request. | ||
| */ | ||
| class DenyingRestPostsController extends WP_REST_Posts_Controller { | ||
| /** | ||
| * Deny access to every item. | ||
| * | ||
| * @param WP_REST_Request $request Full details about the request. | ||
| * @return false | ||
| */ | ||
| public function get_item_permissions_check( $request ) { | ||
| return false; | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
This is a breaking change for those customers that depended on this behaviour.
This should be noted in a breaking changes section.
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.
@maxschmeling I think we should keep this behavior the same as before if possible. The
vip_block_data_api__rest_validate_post_idfilter existed to give developers an option to expose a post that our default logic blocked. If a developer wants to use special logic to expose a post in their own code using special rules (e.g. meta capabilities, auth token) I don't think we should block it.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.
Isn't this is the code path to implementing preview functionality via this API?
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.
Max rolled this back in 99cbf95, so the filter can still override default as I think it should work.