Repository navigation
Block Library: Don't pass post_id to server-side renders for posts the user can't edit - #80604
Conversation
|
Size Change: +113 B (0%) Total Size: 7.91 MB 📦 View Changed
|
b12202a to
219f87f
Compare
|
Flaky tests detected in 1def218. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/32280733452 should insert block with the slash inserter when using multiple words in
|
219f87f to
9af7df0
Compare
| } ), | ||
| isLoading: | ||
| ( postId && ! _post ) || | ||
| // When the user can't edit the post, its record may not be |
There was a problem hiding this comment.
Can you elaborate a bit more why we need these changes in Breadcrumbs. How could a user have an issue?
Can you share some manual reproduction steps?
There was a problem hiding this comment.
Hi @ntsekouras, manual reproduction steps were shared in #80604 (comment). The issue only affects third party blocks that provide a post context of a different post. Regarding the Breadcrumbs changes: the record fetch uses context=edit, so for a post the user can read but not edit the record never arrives, and without checking the permission the block would stay in the loading state forever. The guard was also updated to follow the same conservative rule as the block-renderer change.
|
Thanks for the PR! I mentioned that in my comment, but can you share some manual reproduction steps? I don't know much of PHP only blocks, but I find it odd that we have testing instructions (and tests) that use a custom provider. Is this something that is needed for possible 3rd party devs only? |
Hi Nik I expanded the replication instructions this is an issue that just affects when used in third party blocks that set the post context of a different post. Basically create an author user. Set the post id to 1 (normally the hello world post created by admin), and add the breacrumbs block inside that test block.
On trunk the block stays loading for ever: This PR is just adding a defensive check on places where we retrieve post id from context to make sure the user has edit permissions. |
9af7df0 to
c669d34
Compare
priethor
left a comment
There was a problem hiding this comment.
Thanks for tackling this!
c669d34 to
8b3db5b
Compare
8b3db5b to
1def218
Compare
c29244d to
aac08f5
Compare
aac08f5 to
9c04f67
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (7)
Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthroughThe block library now checks contextual post permissions before server-side rendering. It omits ChangesPost context permissions
Estimated code review effort: 3 (Moderate) | ~25 minutes Merge Risk: ⚪ Minimal · up to The change prevents inaccessible post IDs from being sent to server-side block renders while preserving rendering for editable posts. No actionable merge-blocking risk remains beyond normal checks and review. Sequence Diagram(s)sequenceDiagram
participant Editor
participant useCanEditPostContext
participant core-data
participant block-renderer
Editor->>useCanEditPostContext: Resolve contextual post editability
useCanEditPostContext->>core-data: Check read and update permissions
core-data-->>useCanEditPostContext: Return permission state
Editor->>block-renderer: Send render request with or without post_id
block-renderer-->>Editor: Return rendered block output
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Linked Issues checkExplanation The pull request addresses the requirements in [ Full details: Docstring CoverageExplanation Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 6 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Warning Some tools did not complete. Review the errors below. 🔧 ESLint
ESLint install timed out. The project may have too many dependencies for the sandbox. Comment |
🤖 PR meta 🤖🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the 📦 Bundle sizeSize Change: +203 B (0%) Total Size: 8.69 MB 📦 View Changed
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
|
f11fbaa to
7ebd451
Compare
90ca3f6 to
76bd8be
Compare
16d4806 to
fd33c6f
Compare
fd33c6f to
9db9179
Compare
priethor
left a comment
There was a problem hiding this comment.
Thanks for addressing he feedback, @jorgefilipecosta ! I've updated the PR from trunk to resove the conflics, but CI is not passing because it's also broken in trunk for now.
I opened a patch to fix it in #87165 |
…e user can't edit The block-renderer REST endpoint requires edit_post permissions for the post referenced by post_id, so server-side rendered previews failed with a 403 error when the postId block context referenced a post the current user can't edit. Only forward the context postId when canUser( 'update' ) allows it, in the Breadcrumbs block and in auto-registered PHP-only blocks. Breadcrumbs falls back to its placeholder in that case instead of waiting for a post record the user can't access.
Co-authored-by: priethor <27339341+priethor@users.noreply.github.com>
ec75623 to
142f845
Compare
|
Thank you for fixing the CI and thank you for reviewing this PR @priethor! |
…e user can't edit (WordPress#80604) Co-authored-by: priethor <27339341+priethor@users.noreply.github.com> Co-authored-by: jorgefilipecosta <jorgefilipecosta@git.wordpress.org> Co-authored-by: priethor <priethor@git.wordpress.org> Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org> Co-authored-by: deepakpra <deepakprajapati@git.wordpress.org>


Fixes #79949
Fixes the Breadcrumbs block and auto-registered PHP-only blocks failing to preview in the editor when the
postIdblock context references a post the current user can't edit.The block-renderer REST endpoint requires
edit_postpermissions for the post referenced bypost_id, and these blocks forwarded the contextpostIdunchecked. Core alone never triggers this, the posts list used by the Query Loop preview excludes posts the user can't edit, but providing apostIdcontext is exactly the pattern third-party query-like blocks (related posts, custom loops) are built on, and those don't go through that filter. Inside one of them, Breadcrumbs stays on its loading state forever (its post record request also fails) and PHP-only blocks show "Error loading block: …", while the front end renders fine.To fix this we only forward
post_idwhencanUser( 'update', … )allows it: Breadcrumbs stops waiting for the inaccessible post record and falls back to its placeholder, and PHP-only blocks render without post context. Permissions usually resolve from thetargetHintsalready sent with entity records, so no extra requests are made for editable posts. A minimaltest/post-context-providerblock is added to the SSR e2e test plugin to stand in for third-party providers, with an e2e test for the permission scenario.Before
After
Testing Instructions
Manual, on any site running this branch (no plugin needed):
Create an Author user and log in with it. Create a new post.
Paste this in the browser console; it registers a throwaway block that provides the
postIdcontext, standing in for a third-party query-like block:Insert the "Post context provider (repro)" block and type
1in its "Context post ID" input (the admin-owned "Hello world!" post — any post the Author can't edit works).Insert Breadcrumbs inside it. Without this branch it stays on its loading state forever and the network tab shows the block-renderer and post record requests failing with 403; with this branch it renders its placeholder and
post_idis not sent.Change the ID to a post the Author owns and verify real breadcrumbs render (
post_idis still sent). As admin, verify Breadcrumbs in a plain post and inside a Query Loop's Post Template are unchanged.AI usage disclosure: fix and description drafted with AI assistance and reviewed by me.
Summary by CodeRabbit
Bug Fixes
Tests