Skip to content

Conversation

@carlos-r-l-rodrigues
Copy link
Contributor

@carlos-r-l-rodrigues carlos-r-l-rodrigues commented Jan 20, 2026

Summary
This PR introduces RBAC-based field filtering for API responses and enhances the permission system to support wildcard resources ("*"), enabling super admin roles with full access.

🔧 RBAC Field Filtering
Added field filtering based on user permissions for API responses
Filters out requested fields (e.g., prices, tags) when users lack permissions
Configurable via new feature flag MEDUSA_FF_RBAC_FILTER_FIELDS

🎯 Wildcard Resource Support
Enhanced hasPermission function to support resource: "*" for all resources
Super admin roles can now access all resources and operations with : permissions

⚙️ Feature Flag
New feature flag: rbac_filter_fields (disabled by default)
Environment variable: MEDUSA_FF_RBAC_FILTER_FIELDS


Note

Introduces RBAC-aware field filtering for API queries and enables super-admin style wildcard permissions.

  • Adds FieldParser, AllowedFieldFilter, RestrictedFieldFilter, and policy-backed RBACFieldFilter; updates prepareListQuery/prepareRetrieveQuery to async, accept req, and filter disallowed fields when rbac_filter_fields is enabled
  • Extends has-permission to support resource * and adjusts exports; updates middleware loader to attach policies even without explicit handlers; check-permissions now uses new policy path
  • Adds feature flag rbac_filter_fields (env: MEDUSA_FF_RBAC_FILTER_FIELDS) and comprehensive integration tests for field filtering and wildcard access
  • Updates pricing policy/resources (prices -> price) and policy typings; JWT generation sets roles optionally; adapts affected routes/tests (e.g., cart complete) to async query utils

Written by Cursor Bugbot for commit 51b295a. This will update automatically on new commits. Configure here.

@changeset-bot
Copy link

changeset-bot bot commented Jan 20, 2026

⚠️ No Changeset found

Latest commit: 51b295a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Jan 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

8 Skipped Deployments
Project Deployment Review Updated (UTC)
api-reference Ignored Ignored Jan 23, 2026 11:25am
api-reference-v2 Ignored Ignored Preview Jan 23, 2026 11:25am
cloud-docs Ignored Ignored Preview Jan 23, 2026 11:25am
docs-ui Ignored Ignored Preview Jan 23, 2026 11:25am
docs-v2 Ignored Ignored Preview Jan 23, 2026 11:25am
medusa-docs Ignored Ignored Preview Jan 23, 2026 11:25am
resources-docs Ignored Ignored Preview Jan 23, 2026 11:25am
user-guide Ignored Ignored Preview Jan 23, 2026 11:25am

Request Review

@carlos-r-l-rodrigues carlos-r-l-rodrigues changed the base branch from develop to chore/apply-middleware-policies January 20, 2026 13:21
cursor[bot]

This comment was marked as outdated.

Copy link
Member

@adrien2p adrien2p left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

Comment on lines +129 to +133
if (route.policies && !route.middlewares?.length) {
middlewares.push((_, __, next) => {
next()
})
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: any reason for pushing a noop there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we wrap the policy checks and run the original middleware, in this case, there were none.
Potentially I can check on the wrapper if there is any original function to be executed, but I was affraid of breaking something unexpected.
Will run some real tests and if I can have this removed, I'll do it in a next PR.

*
* const readOp = PolicyOperation.read // "read"
* const writeOp = PolicyOperation.write // "write"
* const writeOp = PolicyOperation.create // "create"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: write op are used for create and update no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can discuss that, if it makes sense to have create and update, or we just use write for everything.
cc: @olivermrbl

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah my concern here is that write is changed to create, but then what happen to update? could exist a case where someone cannot create something and only update existing objects?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, a simple example that comes to mind is that customer service staff might not be allowed to create entire new orders, but only update them with e.g. shipping or customer info.

And if we think about this outside the context of commerce (e.g. on Cloud), I think these scenarios become even more realistic.

I would maybe go with create and update as separate actions for now, and see how that fits.

cursor[bot]

This comment was marked as outdated.

@carlos-r-l-rodrigues carlos-r-l-rodrigues changed the base branch from chore/apply-middleware-policies to develop January 22, 2026 14:41
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

Copy link
Contributor

@olivermrbl olivermrbl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM, will let @adrien2p review the filtering algo

@adrien2p
Copy link
Member

I am currently on the review @carlos-r-l-rodrigues, I might have some changes to propose but i ll let you know 👍

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 3 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants