Dev.to WebDev 🛠 Dev 👁 0 📖 4 min read

WordPress published a change nobody re-approved: the SHA-256 fix

WordPress published a change nobody re-approved: the SHA-256 fix A writer drafts. A reviewer signs it off. An hour before launch, somebody fixes "just a typo" — except the typo was the price in the third paragraph. The

WordPress published a change nobody re-approved: the SHA-256 fix

A writer drafts. A reviewer signs it off. An hour before launch, somebody fixes "just a typo" — except the typo was the price in the third paragraph. The post still says approved. It still publishes.

Nothing in that story is a permissions bug. The approval was a flag with no memory of what it approved.

What actually breaks

What the site has What it proves What it misses
A status like approved, or "Editor can publish" Somebody pressed a button at some point Whether the text in the row is the text that was on screen then
Revisions History exists after the fact Nothing stops the write; you find out from a client email
A staging site A copy existed somewhere Production still accepts any edit, from anyone, at any time
A hash of title + content + excerpt taken at approval This exact text was signed off Edits, and nothing else — see the limits below

The first three answer "was this workflow followed?". Only the fourth answers "is this the text that was approved?".

Why roles and permissions do not solve it

Giving publish rights only to a reviewer controls who can publish. It says nothing about what. In practice the reviewer is the one making the last-minute edit half the time, and a second administrator — the agency, the VA, the intern with an app password — goes around the reviewer completely.

The same hole exists in the other direction: an automation that gates publishing with an approval step is bypassed the moment a human publishes from wp-admin. If the check lives in the automation, the site is only protected for the people who use the automation.

The mechanism

  1. On approval, store the SHA-256 of post_title + post_content + post_excerpt together, in post meta.
  2. On every save, recompute that hash from the incoming data, before the row is written.
  3. If the stored hash is missing, or does not equal the recomputed one, force the post back to draft.
  4. Show both hashes in an admin notice, so "which version was approved" is answerable instead of arguable.

The hook is the whole argument for this design: wp_insert_post_data runs for the classic editor, the block editor, the REST API, quick edit and bulk edit. A save that goes through WordPress goes through that filter — which is why the check belongs there, not in admin-side validation or a JavaScript guard.

// Simplified excerpt - a real plugin does the bookkeeping around this.
add_filter( 'wp_insert_post_data', function ( $data, $postarr ) {
    $post_id = (int) ( $postarr['ID'] ?? 0 );

    if ( ! $post_id || 'publish' !== $data['post_status'] ) {
        return $data;                     // only a publish attempt is gated
    }

    $approved = get_post_meta( $post_id, '_sag_approved_hash', true );
    if ( '' === $approved ) {
        return $data;                     // never approved: not this check's business
    }

    $current = hash( 'sha256',
        $data['post_title'] . "\n" . $data['post_content'] . "\n" . $data['post_excerpt']
    );

    if ( ! hash_equals( $approved, $current ) ) {
        $data['post_status'] = 'draft';   // publish refused
        set_transient( 'sag_blocked_' . $post_id, array(
            'approved' => $approved,
            'current'  => $current,
        ), 60 );
    }

    return $data;
}, 10, 2 );

Two details matter more than they look:

  • hash_equals, not ===. Cheap, and it keeps the comparison constant-time out of habit.
  • The check only fires on a publish attempt. Drafts and autosaves must stay cheap and must never be silently rewritten, or editors will (rightly) hate it.

What it does not cover — say this out loud

  • Images and custom fields. The hash covers the three text fields. Swap the featured image after approval and the hash does not move.
  • Judgement. It cannot tell a good edit from a bad one. It only says this is not what was signed off.
  • Render-time changes. A template edit, a shortcode or a plugin that rewrites output later is outside the check.
  • Friction. It will annoy somebody exactly once per project, on the day the process changes — which is the point, and worth saying before you install it.

Try it

I packaged this as a free GPLv2 plugin so the mechanism can be checked rather than trusted:

It hooks wp_insert_post_data, stores a SHA-256 of the approved text in post meta, re-stamps on re-approval, forces draft on a mismatch, and leaves three filters open (sag_post_types, sag_blocked_status, sag_block_publish). PHP 7.4+, WordPress 6.x, no external services, nothing leaves the site.

I also install and configure it for people who would rather not touch the code — that part is paid, the plugin itself is not. If you have seen this exact failure in production, I would like to hear which editor path caught you: classic, block, REST, or bulk edit.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.