Skip to content

Field is set to null if the user does not have access #11543

Closed

Description

@SimonVreman

Describe the Bug

Introduced by #11433

If access control decides a user cannot update a field, it will now be set to null, or fail validation if required.

Example:

{
  name: 'group',
  type: 'relationship',
  relationTo: 'groups',
  required: true,
  access: {
    update: () => false,
  }
}

If I previously updated another field, it would delete the group value if present in the update data, and then fallback to the old value. But now, access is executed after fallback, so the fallback is deleted and it will instead attempt to set the field to null. In this case, that fails, as the field is required. Still unexpected. But if not required, it will just wipe the field, without the user having touched it!

Link to the code that reproduces this issue

https://github.com/SimonVreman/fix-field-fallback-access-data-loss

Reproduction Steps

Just add a field like the example, and try updating it. It will throw if the field is required as in the example, and wipe data if it is not required.

Which area(s) are affected? (Select all that apply)

area: core

Environment Info

Payload: 3.26.0
Next: 15.2.1
Node: 20
Postgres

Activity

  1. added
    status: needs-triage
    validate-reproduction
    on Mar 5, 2025
  2. added and removed
    validate-reproduction
    on Mar 5, 2025
  3. SimonVreman commented on Mar 5, 2025

    @SimonVreman
    ContributorAuthor

    Opened a PR #11544

  4. self-assigned this
    on Mar 5, 2025
  5. removed
    status: needs-triage
    on Mar 5, 2025
  6. JarrodMFlesch commented on Mar 5, 2025

    @JarrodMFlesch
    Contributor

    Hey @SimonVreman I saw your comment on the other PR, I will look into this first thing. Thanks for bringing it to our attention. I'll look at your PR and write some tests for the issue it solved and the one it created.

  7. SimonVreman commented on Mar 5, 2025

    @SimonVreman
    ContributorAuthor

    Reproduction repo: https://github.com/SimonVreman/fix-field-fallback-access-data-loss

    Steps to recreate validation error:

    1. Create initial user by accessing admin, fill out the field 'breaks on update'
    2. Go to user in admin panel
    3. Change email, or trigger save in some other way
    4. 'breaks on update' value is deleted before validation and an error is thrown as the field is required

    Steps to recreate data loss:

    1. Remove the field from before to get rid of the error
    2. Make sure the data loss field is populated (e.g. through db update)
    3. Trigger save in admin again
    4. Field is now empty, even though access returned false for the current user
  8. github-actions commented on Mar 5, 2025

    @github-actions
    Contributor

    🚀 This is included in version v3.27.0

  9. github-actions commented on Mar 13, 2025

    @github-actions
    Contributor

    This issue has been automatically locked.
    Please open a new issue if this issue persists with any additional detail.

  10. locked as resolved and limited conversation to collaborators on Mar 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions