WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.53k stars 4.21k forks source link

Fix author information leakage by author blocks for Custom Post Types without author support & display notice to user #67136

Open sarthaknagoshe2002 opened 2 days ago

sarthaknagoshe2002 commented 2 days ago

fixes: #65816

What?

This PR updates the behavior of author blocks to ensure they do not render when the post belongs to a Custom Post Type (CPT) that does not explicitly declare support for the author feature.

Why?

Author blocks displaying on CPTs without declared author support is inconsistent with WordPress behavior. This can lead to unintentional data exposure, as WordPress still saves author information to the database even when it is not intended to be visible. Ensures better security, consistency, and adherence to user expectations for CPTs.

How?

Testing Instructions

Reproduction:-

  1. Create a Custom Post Type (CPT) without declaring support for the author feature:
add_action( 'init', function() {
    register_post_type( 'custom-post', array(
        'public' => true,
        'supports' => array( 'title', 'editor', 'custom-fields' ),
    ) );
} );
  1. Add a post to the newly created CPT.
  2. Add an author-related block (e.g., Post Author) in the block editor for that CPT post.
  3. View the post on the frontend.

Expected Outcome:-

  1. In the Editor:

    • A message is displayed informing users that the author block will not render because the CPT does not support the author feature.
  2. On the Frontend:

    • The author block does not render, and no author information is displayed.

Screenshots or screencast

https://github.com/user-attachments/assets/0b8bde8b-b032-44bc-b3da-03b04f8cc441

The suggestion given by @dhruvang21 is also used in this PR from the comment

github-actions[bot] commented 2 days ago

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: sarthaknagoshe2002 <sarthaknagoshe2002@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: dhruvang21 <dhruvang21@git.wordpress.org>
Co-authored-by: groenroos <groenroos@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Mamaduka commented 2 days ago

Thanks for contributing, @sarthaknagoshe2002!

I'm unsure if we need to modify the block's edit components. People with access to the editors can also access details about post type author.

If it's decided to display a notice in edit components, it should probably be a part of rendered content and not an editor notice.

cc @WordPress/gutenberg-design

sarthaknagoshe2002 commented 1 day ago

If it's decided to display a notice in edit components, it should probably be a part of rendered content and not an editor notice.

@Mamaduka Can you elaborate more on this?

Mamaduka commented 1 day ago

The blocks could render static text/warning in the editor when the post type doesn't support authors. But as I mentioned, I'm unsure if that warning makes sense in the editor context.

Rought Example

CleanShot 2024-11-20 at 19 21 46

sarthaknagoshe2002 commented 1 day ago

@Mamaduka I have implemented your suggestion now. In future if we conclude that the warning makes sense in the editor context then we can proceed with the merge.

Screenshot

Screenshot 2024-11-21 at 12 34 10 AM
sarthaknagoshe2002 commented 1 day ago

I believe that the warning definitely makes sense in the editor context since displaying warnings/errors on the frontend doesn't seem appropriate.

Also, as you suggested static warning makes sense too.