-
Notifications
You must be signed in to change notification settings - Fork 280
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
chore(backend,types): Prevent system permissions usage in server-side #4816
base: main
Are you sure you want to change the base?
chore(backend,types): Prevent system permissions usage in server-side #4816
Conversation
🦋 Changeset detectedLatest commit: ca63d27 The changes in this PR will be included in the next version bump. This PR includes changesets to release 23 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
4b60ed7
to
44bb684
Compare
65a25ba
to
ca63d27
Compare
it('prevents usage of system permissions with auth.has()', () => { | ||
clerkMiddlewareMock(async (auth, _event, _request) => { | ||
// @ts-expect-error - system permissions are not allowed | ||
(await auth()).has({ permission: 'org:sys_foo' }); | ||
}); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you think we should add a test case for useAuth()
where the type says that sys permissions are allowed ?
In order to not break something in the future
type DisallowSystemPermissions<P extends string> = P extends `${OrganizationSystemPermissionPrefix}${string}` | ||
? 'System permissions are not included in session claims and cannot be used on the server-side' | ||
: P; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really cool!
Description
Resolves ORGS-441
Context
System permissions (e.g.,
org:sys_domains:manage
) are intentionally excluded from session claims to maintain reasonable JWT sizes. While these permissions work in client-side authorization checks (where they're validated against FAPI organization memberships), they cannot be verified server-side.Problem
Despite documentation updates, developers continue to use server-side authorization checks with system permissions, leading to confusion and support tickets.
Solution
Add type-level validation to catch misuse of system permissions during development. I've opted not to introduce a runtime warning since developers might ignore it.
Checklist
pnpm test
runs as expected.pnpm build
runs as expected.Type of change