WP Manifestindependent plugin directory
manifest / developer / gutenberg-object-plugin

Gutenberg Object Plugin WP Registry grade D+. High-severity findings · 2 findingsWP RegistryHigh-severity findings · 2 findingsOpen the reportD+

Saves Gutenberg data as an object / array and allows you to access it via REST API

★ 241stars
7composer installs
2.0.0latest · 7 years ago

Install

Download source zip No release zip yet

This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.

Install straight from GitHub with WP-CLI:

wp plugin install https://github.com/royboy789/gutenberg-object-plugin/archive/refs/heads/master.zip

On Packagist as royboy789/gutenberg-array-save:

composer require royboy789/gutenberg-array-save
No built-in updater. New versions won't appear under Dashboard → Updates. Install new releases yourself, or let Git Updater track the repository.

The purpose of this plugin is to save Gutenberg (New WordPress Editor) data as an array in the database which is accessible via the REST API.

Installation

  • Clone
  • Run composer install
  • Run npm install
  • npm run dev / npm run build
  • Activate plugin.

WIKI

I am adding docs to the WIKI

WHY

While the new UI for the WordPress Editor is amazing, the data as it is stored lends a lot ot be desired with HTML comments as a basis for data

WHERE

Data will be saved in a new database table [prefix]_gutes_arrays

REST API

I have included a filter to adda editor_block to the normal post content response.

API ENDPOINTS

Includes 1 new route:

  • wp-json/gutes-db/v1/[post-id] - Supports GET & POST
  • wp-json/gutes-db/v1/[post-id]/revisions - Supports GET only

GET

GET: wp-json/gutes-db/v1/[post-id] Returns

  • __is_gutes__: Is the post created with Gutenberg
  • __post_id__: Post ID
  • data: Gutenberg Data
  • _embedded['post']: optional with _embed - response from WP REST API for post

SAVE

POST: wp-json/gutes-db/v1/[post-id]

  • id - required - post ID
  • __gutes_data__ - required - Data array

Hooks

To send the data to the API to save we must first transform data. Using wp.hooks You can tie into this process by adding a filter

  • namespace - 'gutes_array'
  • filter name - clean_data_[hyphenated-block-name]
  • data - data sent and returned is an array of the attributes

EXAMPLE
wp.hooks.addFilter( 'clean_data_core-paragraph', 'gutes-array', callback );

Adding editor_blocks to other CPT Responses

V 1.1.0+
Do you have another CPT (post type) that you are using Gutenberg with? Great! all you have to do is define GUTENBERG_OBJECT_PLUGIN_CPTS before rest_api_init with a comma separated list of CPTs.

add_action( 'init', 'my_custom_cpts', 10 );
function my_custom_cpts() {
    if ( ! defined( 'GUTENBERG_OBJECT_PLUGIN_CPTS' ) ) {
        define( 'GUTENBERG_OBJECT_PLUGIN_CPTS', 'product,page,other_cpt' );    
    }
}

Once GUTENBERG_OBJECT_PLUGIN_CPTS is defined as a comma separated list the editor_block data will apaper in that CPT's API response

Helper Functions

  • <?php get_editor_blocks( $post_id ); ?> - returns array of block data

Releases / Built Packages

I will try to create packaged releases if you are not comforatble with using composer, webpack, or npm and just want to try this plugin on your site.

Head over to the Releases to download a packaged zip that is ready to use.

Third Party Block Support

If you have a plugin that adds blocks, just create an issue with a link to the plugin and I'll try to add in support!

Releases

7 releases.

Tag
Published
2.0.0 latest
Feb 15, 2019 7 years ago
Dec 12, 2018 7 years ago
Nov 26, 2018 7 years ago
Jul 21, 2018 8 years ago
Jul 21, 2018 8 years ago
Jul 13, 2018 8 years ago
Jul 12, 2018 8 years ago

These releases are tags only. The author does not attach a packaged zip, so there are no download counts to report.

D+ grade

Security

Gutenberg Object Plugin 1.5.0 · audited by WP Registry

High-severity findings.

2 high
Audited release
1.5.0
Findings
2
Worst severity
high
Content hash
f6b712299ad66d60333d64b9…

Findings

  • high Unauthenticated REST POST overwrites Gutenberg block JSON for any post

    missing_permission_callback

    gutes_db_api_init() registers POST gutes-db/v1/(?P<id>\d+) with callback save_editor_data and no permission_callback. WordPress REST (WP_REST_Server::respond_to_request) only runs a permission check when permission_callback is non-empty, so an omitted callback is public: administrator, editor, author, subscriber, customer, and unauthenticated all reach the handler. save_editor_data() never calls current_user_can('edit_post') or verifies a nonce; it casts id to int, treats the post as eligible if is_gutes() (empty post_content or has_blocks), json_decodes gutes_data, and save_editor_db() INSERT/UPDATEs {prefix}gutes_arrays.gutes_array via $wpdb->prepare (quoted '%s' is stripped back to %s by wpdb::prepare, so the write succeeds). Observable: curl -X POST /wp-json/gutes-db/v1/1 -d 'gutes_data=[{...}]' overwrites the block object for post 1 if it is Gutenberg (or empty). Consumers of that row are GET /wp-json/gutes-db/v1/{id}, GET /wp-json/wp/v2/posts/{id}/blocks, register_rest_field editor_blocks on the public /wp/v2/posts/{id} response (Hooks::get_block_data), and get_editor_blocks(). wp_posts.post_content is not modified, so the classic PHP theme still shows the original post, but any headless or theme consumer of editor_blocks / get_editor_blocks() serves attacker-controlled block attributes (including HTML paragraph content). The editor script localizes a wp_rest nonce but the PHP callback does not read it; unauthenticated requests do not need one.

    src/API.php:65-110

    Recommendation

    Add permission_callback that returns current_user_can('edit_post', (int) $request['id']) on the POST route (REST cookie auth will then also require a valid X-WP-Nonce). Re-check edit_post inside save_editor_data. Do not accept writes for posts the user cannot edit. Consider show_in_index false for the save route.

  • high Unauthenticated REST GET discloses unpublished Gutenberg data and post revisions

    information_disclosure

    GET gutes-db/v1/(?P<id>\d+) (get_editor_data) and GET gutes-db/v1/(?P<id>\d+)/revisions (get_revision_data) are registered without permission_callback, as are BlockAPI routes GET wp/v2/posts/(?P<id>\d+)/blocks and GET wp/v2/posts/(?P<id>\d+)/blocks/(?P<bid>\S+). get_editor_data() / get_all_blocks() load the post with get_post($id) and the custom table via get_editor_db(); is_gutes() only tests empty content or has_blocks() and never is_post_publicly_viewable() or current_user_can('read_post'). Core /wp/v2/posts hides drafts/private/password bodies from guests; these routes do not. Observable: unauthenticated GET /wp-json/gutes-db/v1/{id} (and GET /wp-json/wp/v2/posts/{id}/blocks) enumerates sequential IDs and returns gutes_array JSON for any draft, private, future, or password-protected Gutenberg post that was saved through this plugin. get_revision_data() calls wp_get_post_revisions($post_id) with no edit_post check and attaches parsed blocks; that dumps full revision WP_Post objects including post_content when function_exists('gutenberg_parse_blocks') (Gutenberg plugin / this plugin's original target). On current core-only WordPress, gutenberg_parse_blocks is absent so the revisions route returns WP_Error before the dump; the custom-table GET routes still leak. register_rest_field editor_blocks on 'post' is not this bug (it inherits core post REST read caps).

    src/API.php:38-63

    Recommendation

    Set permission_callback on every GET route to current_user_can('read_post', (int) $request['id']) (or is_post_publicly_viewable() for a public-read subset). For revisions, require current_user_can('edit_post', $post_id) to match core's revision controller. Apply the same read_post check in get_editor_data, get_all_blocks, and get_single_block before querying {prefix}gutes_arrays.

WP Registry hashes the installable build and reports on that exact bytes-for-bytes copy. Embargoed findings are withheld until they are disclosed, so a clean verdict means nothing public is outstanding. WP Manifest does not audit code itself.