Skip to content

plugin-cloud-storage: since 3.90, files without ?prefix= return 500 when collection read access allows only static-file reads (getFilePrefix ignores isReadingStaticFile) #19008

Open

Description

@clarson00

Describe the Bug

A common pattern for upload collections is "anyone may download the file bytes, only staff may list the documents":

access: {
  read: (args) => (args.isReadingStaticFile ? true : isStaff(args)),
}

Payload's own static-file check (uploads/checkFileAccess) passes isReadingStaticFile: true, so this worked through 3.89.

Since 3.90, @payloadcms/plugin-cloud-storage's getFilePrefix (packages/plugin-cloud-storage/src/utilities/getFilePrefix.ts, ~line 96) runs a second lookup before serving the object, when the serve path did not already load the doc (i.e. the URL has no ?prefix=):

await req.payload.find({ collection, overrideAccess: false, req, select: { _objectKey: true, prefix: true }, where: { filename… } })

That call goes through collection read access without isReadingStaticFile, so the rule above returns false, find throws Forbidden, and the file request fails with 500 for every anonymous caller.

Affected in practice:

  • every file URL in a collection without a prefix (the afterRead hook never appends ?prefix= there), e.g. media;
  • every file URL stored before 3.90 (no ?prefix=), e.g. URLs saved in rich text, JSON, emails;
  • next/image optimisation of those URLs (fetches anonymously → 400).

With ?prefix= it works, because checkFileAccess already loaded the doc and getFilePrefix returns early.

Reproduction Steps

  1. s3Storage (no clientUploads, no disablePayloadAccessControl) on an upload collection with the read rule above.
  2. Upload a file as an admin.
  3. curl -i /api/<slug>/file/<filename> with no session (and no ?prefix=).
  4. 3.89: 200. 3.90–3.92: 500 (Forbidden: You are not allowed to perform this action. in the server log).

Expected

The prefix lookup should be treated as part of serving the static file — e.g. call the read access with isReadingStaticFile: true (the same way checkFileAccess does), or run the lookup with overrideAccess: true after checkFileAccess has already authorised the request.

Workaround

Return a match-nothing Where instead of false for non-staff document reads:

read: (args) => (args.isReadingStaticFile ? true : isStaff(args) || { id: { exists: false } })

The lookup then finds no row and falls back to the collection prefix; document lists stay empty for anonymous callers.

Which area(s) are affected?

plugin: cloud-storage, plugin: storage-s3

Environment Info

Payload 3.92.0 (also 3.90.0), @payloadcms/storage-s3 3.92.0, @payloadcms/db-postgres 3.92.0, Next.js 15.4.11, Node 22.23.4

Activity

  1. cestercian commented on Oct 23, 2026

    @cestercian

    Mind if I take this? I'm thinking getFilePrefix should run the read access with isReadingStaticFile: true like checkFileAccess does, instead of a plain find that drops that flag. Will open a PR with a test.

  2. removed
    plugin: cloud-storage
    on Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions