Skip to content

storage-s3: Changing uploaded Media fails with "Blocked unsafe attempt" in v3.43.0 #12876

Description

@nettags

Describe the Bug

s3 storage: Changing an image that has already been uploaded throws the following error: "An error occurred while uploading the file.. Blocked unsafe attempt to http://xxx" in Payload v3.43.0.

Earlier versions are not affected; there is no error after downgrading to version 3.42.

Thanks in advance for checking this out.

Link to the code that reproduces this issue

pnpx create-payload-app@latest -t website

Reproduction Steps

These steps are based on the Website template:

1.) Enable the s3 storage plugin:

s3Storage({
      collections: {
        media: true,
      },
      bucket: process.env.S3_BUCKET_NAME || '',
      config: {
        region: process.env.S3_REGION || '',
        endpoint: process.env.S3_ENDPOINT || '',
        credentials: {
          accessKeyId: process.env.S3_ACCESS_KEY || '',
          secretAccessKey: process.env.S3_SECRET_KEY || '',
        },
      },
    }),
  1. Upload an image to the Media collection – this works without any issues.

  2. Edit the image, for example by changing the alt text, and click Save.

  3. An error is thrown and the image is not updated. See the error in the logs:

err: {
      "type": "FileRetrievalError",
      "message": "An error occurred while uploading the file.. Blocked unsafe attempt to http://localhost:3020/api/media/file/dummy-upload.png",
...}

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

plugin: cloud-storage

Environment Info

Binaries:
  Node: 20.19.0
  npm: 10.8.2
  Yarn: N/A
  pnpm: 10.3.0
Relevant Packages:
  payload: 3.43.0
  next: 15.3.0
  @payloadcms/db-mongodb: 3.43.0
  @payloadcms/email-nodemailer: 3.43.0
  @payloadcms/graphql: 3.43.0
  @payloadcms/live-preview: 3.43.0
  @payloadcms/live-preview-react: 3.43.0
  @payloadcms/next/utilities: 3.43.0
  @payloadcms/payload-cloud: 3.43.0
  @payloadcms/plugin-cloud-storage: 3.43.0
  @payloadcms/plugin-form-builder: 3.43.0
  @payloadcms/plugin-nested-docs: 3.43.0
  @payloadcms/plugin-redirects: 3.43.0
  @payloadcms/plugin-seo: 3.43.0
  @payloadcms/richtext-lexical: 3.43.0
  @payloadcms/storage-s3: 3.43.0
  @payloadcms/translations: 3.43.0
  @payloadcms/ui/shared: 3.43.0
  react: 19.1.0
  react-dom: 19.1.0
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.5.0: Tue Apr 22 19:53:27 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T6041
  Available memory (MB): 24576
  Available CPU cores: 12

Activity

  1. added
    status: needs-triage
    validate-reproduction
    on Jun 20, 2025
  2. removed
    validate-reproduction
    on Jun 20, 2025
  3. github-actions commented on Jun 20, 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. fedosev commented on Jun 20, 2025

    @fedosev

    Same issue without s3 (local storage). It seems to be an issue after adding safeFetch. There is no checking for allowList. Was there some sort of merge issues? packages/payload/src/uploads/getExternalFile.ts

  5. JayBee007 commented on Jun 20, 2025

    @JayBee007

    The issue is with how isSafeIp works, more info here #12870

  6. luochuanyuewu commented on Jun 21, 2025

    @luochuanyuewu

    Same issue here after upgrade to 3.43

  7. noa-santo commented on Jun 22, 2025

    @noa-santo

    i have the same error with the vercel blob storage

  8. JesperWe commented on Jun 23, 2025

    @JesperWe
    Contributor

    Same issue here using Digital Ocean S3 storage

  9. tsemachh commented on Jun 23, 2025

    @tsemachh
    Contributor

    @nettags this happens also on GCS and local storage , this is regression because of the change done by @kendelljoseph
    #12622 there are also remarks there , this needs to get prioritiy

  10. lukebennett commented on Jun 23, 2025

    @lukebennett
    Contributor

    Yes, totally broken here too (using R2 via S3 but doesn't appear to be provider specific). Can't update any uploads at the moment.

  11. TwR-Slice commented on Jun 23, 2025

    @TwR-Slice

    +1 unable to edit

  12. roymandev commented on Jun 24, 2025

    @roymandev

    +1 unable to edit

  13. lukyfebrianto commented on Jun 24, 2025

    @lukyfebrianto

    +1 unable to edit

  14. 33 remaining items

  15. kendelljoseph commented on Jul 2, 2025

    @kendelljoseph
    Contributor

    @johnslemmer this is connected to this: #12622 (comment)

    I'm verifying a fix that should work right now.

  16. kendelljoseph commented on Jul 2, 2025

    @kendelljoseph
    Contributor

    @tsemachh

    ...failing on same scenario also on self hosted env on gck when gcs was the storage.

    The fix, #13018 should address this problem as well since you are using a storage adapter.

    ...When I had the problems I was working locally with no cloud storage...

    The upload operation that triggers getExternalFile,

    file = await getExternalFile({

    Should happen only when the url is not a local.

    if (url && url.startsWith('/') && !disableLocalStorage) {

    However it's possible that upload collection document url you are using has a local address.

    This fix, #13018, may not solve what you described.

    I would need to know more about your local config, or document, to understand why external fetches are being triggered for local resources. I haven't been able to recreate that problem so far, I'll be watching for your recreation notes.

  17. tsemachh commented on Jul 2, 2025

    @tsemachh
    Contributor

    O.k. will try tomorrow to set up public GitHub with the recreation on localhost with localstorage

  18. tsemachh commented on Jul 3, 2025

    @tsemachh
    Contributor

    @kendelljoseph nailed it:
    look at: https://github.com/shefing/bulkuploadbug
    I added GCS (not enabled) and beforeValidate hook and I managed to recreate it
    Use posts add research document then edit it after creation

  19. removed
    status: needs-triage
    on Jul 3, 2025
  20. kendelljoseph commented on Jul 3, 2025

    @kendelljoseph
    Contributor

    @tsemachh using your reproduction and the GCS storage plugin I was unable to trigger a result related to this issue.

    I did get this error when trying to update:

    Image

    Which is unrelated.

  21. tsemachh commented on Jul 3, 2025

    @tsemachh
    Contributor

    Try to upload pdf then after saving try to edit the upload by adding related posts

  22. tsemachh commented on Jul 4, 2025

    @tsemachh
    Contributor

    @kendelljoseph I upgraded the test to 3.45 and the test now works o.k.

    However in my repo upgrading to 3.45 I still see same error.
    I will try maybe next week to recreate it in the test repo , for now you can ignore this.

    Here's a readable version of the stack trace from the provided error log:
    Error Type: FileRetrievalError
    Message: אירעה בעיה בזמן העלאת הקובץ. Blocked unsafe attempt to http://localhost:3000/api/research-documents/file/summerwork.pdf
    Status: 500
    Environment: Development
    User: tsemachhadad
    Hostname: Tsemachs-MacBook-Pro.local
    Stack Trace:
    File: /Users/tsemachhadad/devemada/emda2/node_modules/payload/dist/uploads/generateFileData.js:53:19
    File: node:internal/process/task_queues:105:5
    File: /Users/tsemachhadad/devemada/emda2/node_modules/payload/dist/collections/operations/updateByID.js:80:61
    File: /Users/tsemachhadad/devemada/emda2/node_modules/payload/dist/collections/endpoints/updateByID.js:16:17
    File: /Users/tsemachhadad/devemada/emda2/node_modules/payload/dist/utilities/handleEndpoints.js:169:26
    File: /Users/tsemachhadad/devemada/emda2/.next/server/chunks/node_modules_@payloadcms_1f8018f9._.js:6595:26
    File: /Users/tsemachhadad/devemada/emda2/node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.dev.js:26:34112
    File: /Users/tsemachhadad/devemada/emda2/node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.dev.js:26:41338
    AI Summary:
    The error occurred during a file upload attempt to http://localhost:3000/api/research-documents/file/summerwork.pdf. The FileRetrievalError indicates a blocked unsafe attempt, likely due to security restrictions or misconfiguration in the file upload process. The issue originates in the generateFileData function within the Payload CMS library and propagates through Next.js server-side rendering and request handling. Check the file upload configuration, security policies (e.g., CORS, Content Security Policy), or the specified URL for potential issues.`]

  23. simovicaleksa commented on Jul 6, 2025

    @simovicaleksa

    Hello guys, I should probably open an issue for this but it seems related to this closed one.

    Problem

    I have started experiencing the same issue in the original post after adding beforeOperation hook to my media collection config. Interestingly, it only happens in production when I try to update an existing document by changing for example alt text. Changing the entire image does not seem to cause any trouble.

    Besides not being able to save the new document configuration, I'm experiencing a weird bug where once I start editing the text fields, my writing gets interrupted by cursor moving to the end of the string (video example attached).

    Once I finish editing the field and click "save", the console logs the following error:

    ERROR: There was a problem while uploading the file. Blocked unsafe attempt to https://example.com/api/media/file/c33814713f7e4190b7f3aa661b4c9629.jpg

    Setting skipSafeFetch to true fixes my issue in production, but it also introduces the cursor bug in the dev.

    2025-07-06.02-15-11.mp4

    Take note of the keyboard cursor behavior at the beginning of the video when editing the "name" field

    Media Collection Config

    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: true,
      hooks: {
        beforeOperation: [
          ({ req, operation }) => {
            if ((operation === "create" || operation === "update") && req.file) {
              const newFilename = getUniqueFilename(req.file.mimetype); // f3f49059c8ba4414bc64cbfcbd4641b2.jpg
              req.file.name = newFilename;
            }
          },
        ],
      },
    };

    Additional Information

    1. Started happening after adding beforeOperation hook to my media collection
    2. Unable to reproduce in dev
    3. Production is running inside of a Docker container
    4. PayloadCMS version: 3.45.0
    5. skipSafeFetch is set to false
    6. Using MinIO as an S3 storage (self-hosted in the same compose as my application, not exposed outside of Docker network)
    7. User interacts with the admin app through a reverse proxy

    Question

    What exactly does the safeFetch do? I couldn't find anything in the docs about it. Also any ideas for fixing the cursor bug, or what could be causing it?

  24. github-actions commented on Jul 7, 2025

    @github-actions
    Contributor

    🚀 This is included in version v3.46.0

  25. appfresheners commented on Jul 9, 2025

    @appfresheners
  26. github-actions commented on Jul 17, 2025

    @github-actions
    Contributor

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

  27. locked as resolved and limited conversation to collaborators on Jul 17, 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