Add settings to automatically disable new fields

Created on 2 July 2025, about 1 month ago

Problem/Motivation

Currently when adding new fields to entities they automatically get exposed in the JSON:API resource. When creating a public API it could lead to inadvertently expose fields which are not meant to be public, if access is not correctly configured. In order to make it easy to produce a secure by default API we propose to add a settings which when turned on would automatically disable new fields not present in the JSON:API extras config.

Proposed resolution

Create a setting similar to the disabled by default setting for fields, and disable fields present in the entity and not present in the extras config in the JsonApiBuildSubscriber.

Feature request
Status

Active

Version

3.26

Component

Code

Created by

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

Comments & Activities

  • Issue created by @duivw
  • e0ipso Can Picafort

    If you don't want these fields to be publicly accessible to anonymous users, have you considered adding field access rules?

  • We do perform access checks, however this change would further guarantee that no field is inadvertently exposed to the API, even if multiple people with differences in experience work on the project and don't keep in mind that fields added to nodes will be added to the API as well. This change would also make it so that if in a few years time new fields are added to nodes they aren't automatically exposed on the API which I believe to be a good thing.
    This change wouldn't necessarily be useful for an entirely headless Drupal application, but in our use case we are providing an API together with the regular Drupal frontend, and while users may see a body field in the frontend, for reasons of response time we don't want to expose it in the API. The same may be said for new fields added later down the line.

  • 🇯🇵Japan ptmkenny

    Please add an MR instead of a patch. Drupal.org CI infrastructure only runs the module's tests on MRs, not patches.

Production build 0.71.5 2024