draft content leaking into "live" server

Created on 10 March 2023, over 1 year ago
Updated 9 May 2023, over 1 year ago

Problem/Motivation

When using both a "live"/build server and a preview server,
and the option "Only trigger builds for published content" is EITHER checked or not,
and the user saving the content has permission to see draft content,
and there is related content that has an unpublished default revision (ie, never before published),
the unpublished related content is posted to the live/build server.

For our purposes we are using nodes and storage entities, and content moderation is enabled for both.

Steps to reproduce

Install "storage" module, or use another entity type.
Create a storage type.
Create a content type with an entity reference field to the storage type.
Enable content moderation workflows for both.
Create a storage entity and save it as a draft/unpublished.
Create a node and relate the storage entity to it.
Publish the node, but do not publish the storage entity.
Observe: JSON stored in fastbuild log is based on content editor's permissions, and includes unpublished related storage entities.
When the API user requests the fastbuilds endpoint, that user's permissions are not validated and it is served the stored json, regardless of what it should have access to.

Proposed resolution

I'm not sure what the best resolution is here, in the module itself. I have created a workaround for it, by using a RouteSubscriber to override the GatsbyFastbuildsController, and I have attached that override here. You can see I'm re-adding the json when the API user requests the data, so that user's permissions are taken into account.

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇺🇸United States lisagodare@gmail.com

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @lisagodare@gmail.com
  • We are also experiencing this issue.

    In our case, we're not using storage entities. We are using content moderation with node entities.
    Randomly, pages that are unpublished are leaking onto the live/build server.

    Hoping there's going to be a resolution quickly for this one as our users can no longer rely on an "unpublished" page being unpublished.

  • First commit to issue fork.
  • Open on Drupal.org →
    Core: 9.5.5 + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    Waiting for branch to pass
  • @apmsooner opened merge request.
  • Status changed to Needs review over 1 year ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.5 + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    Build Successful
  • 🇺🇸United States apmsooner

    I don't know if this solves your exact issue or not and it's difficult to test locally without having a separate preview/build server but this patch syncs up the logging service with the hooks, factors in the build_published option to early return for non-node entities when its true, and accounts for entities like "redirects" that don't have a publish state to also be triggered. It "should" resolve draft versions getting on build server. @lisagodare, your description involving referenced entities also in a moderated state may be a more unique issue and seemingly to me a case where those references might be better served as entity_reference_revisions if you're still having issues beyond this patch.

  • 🇺🇸United States apmsooner

    Noting here also... per Shane & Tyler at Gatsby, the version 2 of the module depends on fast_builds being enabled and thus it never sends json to the gatsby site like version 1 did. It just creates the log entity and triggers the gatsby site to make a request to the api endpoint to retrieve the data. So i've removed the json variables from the functions and the json logging setting should really just go away as its irrelevant since the data exists in the logging entity itself. One other important note, the "Only trigger builds for published content" is confusing as it really restricts updates to just nodes. The caveat of having this setting enabled means things not referenced to the node in an "entity reference" way like path aliases and redirects don't get triggered as part of node updates. I personally recommend disabling that setting.

  • Open on Drupal.org →
    Core: 9.5.5 + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    Waiting for branch to pass
  • 🇺🇸United States shrop

    Thanks for the updates @apmsooner. We will test this as a next step.

    For the "Only trigger builds for published content" not being set, what would be a process to ensure live content isn't published or is it covered via Fastbuilds publish/preview payloads?

  • Status changed to RTBC over 1 year ago
  • 🇨🇦Canada slydevil Halifax

    Patch works great!

  • 🇺🇸United States lisagodare@gmail.com

    This patch appears to work great for our needs.

    We don't want to use Entity Reference Revisions fields, because we don't want to associate a specific revision of a related entity on the relating entity. This is because multiple different entities may relate to it, and we don't want them each showing a different revision. They should all show the same revision - either the default revision, if published, on the 'live' build; or the latest revision, published or not, on the 'preview' build.

  • Open on Drupal.org →
    Core: 9.5.5 + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    Waiting for branch to pass
    • apmsooner committed 9ffa6b47 on 2.0.x
      Issue #3347297 by apmsooner, lisagodare@gmail.com, slydevil, shrop:...
  • Status changed to Fixed over 1 year ago
  • 🇺🇸United States apmsooner

    Merging to dev.

  • Status changed to Fixed over 1 year ago
Production build 0.71.5 2024