Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot access payload-webp optimized images using query return in access control #15

Open
DanielKraemer opened this issue Aug 1, 2023 · 1 comment

Comments

@DanielKraemer
Copy link

Original-Post payloadcms/payload#3101

If you need further information feel free to ask ;-)

Original Post from payloadcms/payload

To Reproduce

Upload images to a media collection with a relationship field (e. g. to a site) and have payload-webp installed and activated.
Only allow user to read the webp files if they have a relationship to the same site and use a query constrained for checking this.

Access-configuration for my media collection:
access: { create: ****, read: hasBasicReadAccess('site'), update: ****, delete: **** },

Function "hasBasicReadAccess":

export const hasBasicReadAccess = (siteIdFieldName = 'siteId'): Access => ({
  req: {
    user,
  },
}) => {
  if (user?.isSystemAdmin) return true;
  if (user) {

    const userSiteIds = [];

    if (user.sites && user.sites.length > 0) {
      user.sites.forEach(({ site } : { site: string | Site }) => {
        userSiteIds.push((typeof site === 'string') ? site : site.id);
      });
    }

    return {
      or: [
        {
          author: {
            equals: user.id,
          },
        },
        {
          [siteIdFieldName]: {
            in: userSiteIds,
          },
        },
      ],
    };
  }
  return false;
};

Describe the Bug

I cannot access a .webp media file created by payload-webp when return a query constrain while checking read-access.

Testing it as a mongodb query using robo3t for example all is fine.

Always receiving error
Forbidden: You are not allowed to perform this action. at /home/user/payloadcms/node_modules/payload/src/auth/getExecuteStaticAccess.ts:53:17 at processTicksAndRejections (node:internal/process/task_queues:95:5)

payload-webp version: ^1.1.0

Payload Version

1.8.2

@MinSomai
Copy link

MinSomai commented Jun 6, 2024

for me, this happened because I had conflicting logins. I have two collection with auth: true and it was causing the issue. If you open in incognito, this goes aways. To fix this , you can simply clear your cookies/localStorage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants