Skip to content

Cannot update media doc in production after 3.46.0+ #13146

Closed

Description

@simovicaleksa

Problem

After updating to Payload 3.46.0+ (also broken in 3.47.0) I cannot update the doc in my media upload collection. Trying to do so results in the console printing out the following error:

[23:13:47] ERROR: There was a problem while uploading the file. fetch failed

Reproduction

I have a publicly readable media collection running with @payloadcms/storage-s3 and minio, with some custom hooks which ensure the media is renamed upon upload to have a unique name, as per the official docs example.

After creating a media document I am forbidden from updating the document in any way. This includes changing other fields such as alt, of type: "text".

Here is my media.ts file:

import type { CollectionConfig } from "payload";

import { getUniqueFilename } from "~/lib/utils/media";

export const Media: CollectionConfig = {
  slug: "media",
  admin: {
    useAsTitle: "name",
  },
  access: {
    read: () => true,
  },
  fields: [
    {
      name: "name",
      type: "text",
    },
    {
      name: "alt",
      type: "textarea",
      required: true,
    },
  ],
  upload: {
    // disabling this results in a different error something along the lines of "Blocked unsafe attempt"
    skipSafeFetch: true,
  },
  hooks: {
    beforeOperation: [
      async ({ req, operation }) => {
        // generate a unique filename for the uploaded file
        if ((operation === "create" || operation === "update") && req.file) {
          const newFilename = getUniqueFilename(req.file.mimetype);
          req.file.name = newFilename;
        }
      },
    ],
  },
};

And my s3Storage configuration in payload.config.ts:

s3Storage({
      bucket: "media",
      collections: {
        media: true,
      },
      config: {
        credentials: {
          accessKeyId: env.MINIO_ROOT_USER,
          secretAccessKey: env.MINIO_ROOT_PASSWORD,
        },
        region: "region",
        endpoint: env.MINIO_URL,

        forcePathStyle: true,
      },
    }),

Additional info

  1. Cannot update any field after adding a media (e.g. name, alt...)
  2. Started happening after 3.46.0, also verified that is still an issue in 3.47.0
  3. Only happens in production
  4. Production is a self-hosted standalone Next.js build running in a docker container
  5. Setting skipSafeFetch: false results in an error. Something along the lines of
  6. In the versions prior (e.g. 3.45.0) setting skipSafeFetch: true fixes the issue
Image

Environment Info

payload: 3.47.0
  next: 15.3.5
  @payloadcms/db-postgres: 3.47.0
  @payloadcms/email-nodemailer: 3.47.0
  @payloadcms/graphql: 3.47.0
  @payloadcms/live-preview: 3.47.0
  @payloadcms/live-preview-react: 3.47.0
  @payloadcms/next/utilities: 3.47.0
  @payloadcms/payload-cloud: 3.47.0
  @payloadcms/plugin-cloud-storage: 3.47.0
  @payloadcms/plugin-multi-tenant: 3.47.0
  @payloadcms/richtext-lexical: 3.47.0
  @payloadcms/storage-s3: 3.47.0
  @payloadcms/translations: 3.47.0
  @payloadcms/ui/shared: 3.47.0
  react: 19.1.0
  react-dom: 19.1.0
Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Pro
  Available memory (MB): 32689
  Available CPU cores: 16

Activity

  1. added
    status: needs-triage
    validate-reproduction
    on Jul 11, 2025
  2. removed
    validate-reproduction
    on Jul 11, 2025
  3. github-actions commented on Jul 11, 2025

    @github-actions
    Contributor

    Please add a reproduction in order for us to be able to investigate.

    Depending on the quality of reproduction steps, this issue may be closed if no reproduction is provided.

    Why was this issue marked with the invalid-reproduction label?

    To be able to investigate, we need access to a reproduction to identify what triggered the issue. We prefer a link to a public GitHub repository created with create-payload-app@latest -t blank or a forked/branched version of this repository with tests added (more info in the reproduction-guide).

    To make sure the issue is resolved as quickly as possible, please make sure that the reproduction is as minimal as possible. This means that you should remove unnecessary code, files, and dependencies that do not contribute to the issue. Ensure your reproduction does not depend on secrets, 3rd party registries, private dependencies, or any other data that cannot be made public. Avoid a reproduction including a whole monorepo (unless relevant to the issue). The easier it is to reproduce the issue, the quicker we can help.

    Please test your reproduction against the latest version of Payload to make sure your issue has not already been fixed.

    I added a link, why was it still marked?

    Ensure the link is pointing to a codebase that is accessible (e.g. not a private repository). "example.com", "n/a", "will add later", etc. are not acceptable links -- we need to see a public codebase. See the above section for accepted links.

    Useful Resources

  4. changed the title [-]Cannot rename media in production after 3.46.0+[/-] [+]Cannot UPDATE media docs in production after 3.46.0+[/+] on Jul 11, 2025
  5. changed the title [-]Cannot UPDATE media docs in production after 3.46.0+[/-] [+]Cannot update media docs in production after 3.46.0+[/+] on Jul 11, 2025
  6. changed the title [-]Cannot update media docs in production after 3.46.0+[/-] [+]Cannot update media doc in production after 3.46.0+[/+] on Jul 12, 2025
  7. mikkelwf commented on Jul 13, 2025

    @mikkelwf
    Contributor

    Try adding skipSafeFetch: true to the upload config

  8. simovicaleksa commented on Jul 13, 2025

    @simovicaleksa
    Author

    Try adding skipSafeFetch: true to the upload config

    As you can see from the code example of my media collection config that's what the issue is about. In prior versions to 3.46.0 that fixed the issue, but now I get an error regardless skipSafeFetch value.

    For example with skipSafeFetch: true I am getting:

    [23:13:47] ERROR: There was a problem while uploading the file. fetch failed

    And with skipSafeFetch: false I get:

    Blocked unsafe attempt

    My guess is it's got likely something to do with: #13018.

    Edit:

    Here is an image describing my setup on a higher level. Caddy acts as a reverse proxy between User and App. App and MinIO are connected to each other via HTTP. This connection is secure even if it's HTTP since it's internal. This might be what's causing the "Blocked unsafe attempt" issues, but it does not explain why I can upload a media in the first place.

    Image
  9. mikkelwf commented on Jul 14, 2025

    @mikkelwf
    Contributor

    Sorry, didn't see you've applied skipSafeFetch already..
    I got the same error and it started working when I applied skipSafeFetch: true

  10. mikenicklas commented on Jul 19, 2025

    @mikenicklas

    FWIW, I was running into this issue as well. I had the standard Media collection as defined by the payload installation template I used. We're using S3 uploads with this config:

    s3Storage({
          collections: {
            media: true,
          },
          bucket: process.env.S3_BUCKET!,
          config: {
            credentials: {
              accessKeyId: process.env.S3_ACCESS_KEY_ID!,
              secretAccessKey: process.env.S3_SECRET_ACCESS_KEY!,
            },
            region: process.env.S3_REGION!,
          },
        }),
    

    Payload versions:

    "@payloadcms/db-postgres": "^3.44.0",
    "@payloadcms/next": "^3.44.0",
    "@payloadcms/payload-cloud": "^3.44.0",
    "@payloadcms/richtext-lexical": "^3.44.0",
    "@payloadcms/storage-s3": "^3.44.0",
    

    I was unable to update the alt tag of a Media record once it was published. However setting the skipSafeFetch did seem to resolve that for me ✅

  11. removed
    status: needs-triage
    on Jul 21, 2025
  12. simovicaleksa commented on Jul 22, 2025

    @simovicaleksa
    Author

    @mikenicklas, @kendelljoseph It was like this for me as well before updating to payload 3.46.0+. skipSafeFetch: true used to fix the issue until I updated payload to the latest version. The update/change that probably introduced this bug is #13018.

    I suspect that the reason is because I am running my app container as a part of an internal network in docker (behind a reverse proxy), thus it is not able to resolve to a dns directly. This causes the node.js promises/dns to throw an error, canceling the UPDATE transaction on media document.

    This would also explain why it only happens in production, as during development my app has access to a dns.

    I feel like this should be considered as a bug on payload's side since it does not allow the user to be fully disable the safeFetch/dns-lookup check.

  13. r1tsuu commented on Aug 21, 2025

    @r1tsuu
    Member

    This issue was fixed here #13475

  14. github-actions commented on Aug 29, 2025

    @github-actions
    Contributor

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

  15. locked as resolved and limited conversation to collaborators on Aug 29, 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