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

chore(backend,types): Prevent system permissions usage in server-side #4816

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

LauraBeatris
Copy link
Member

@LauraBeatris LauraBeatris commented Dec 19, 2024

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.

CleanShot 2024-12-19 at 14 02 48

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

@LauraBeatris LauraBeatris self-assigned this Dec 19, 2024
Copy link

changeset-bot bot commented Dec 19, 2024

🦋 Changeset detected

Latest commit: ca63d27

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 23 packages
Name Type
@clerk/backend Patch
@clerk/types Patch
@clerk/astro Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/nextjs Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/remix Patch
@clerk/clerk-sdk-node Patch
@clerk/tanstack-start Patch
@clerk/testing Patch
@clerk/clerk-js Patch
@clerk/elements Patch
@clerk/expo-passkeys Patch
@clerk/clerk-expo Patch
@clerk/localizations Patch
@clerk/clerk-react Patch
@clerk/shared Patch
@clerk/themes Patch
@clerk/ui Patch
@clerk/vue Patch
@clerk/chrome-extension Patch

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

Copy link

vercel bot commented Dec 19, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
clerk-js-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 19, 2024 6:05pm

@LauraBeatris LauraBeatris force-pushed the laura/orgs-441-do-not-allow-passing-system-permissions-to-has-from-the branch from 4b60ed7 to 44bb684 Compare December 19, 2024 17:56
@LauraBeatris LauraBeatris changed the title chore(backend,types): Prevent system permissions usage in server-side chore(backend,types): Prevent system permissions usage in server-side Dec 19, 2024
@LauraBeatris LauraBeatris force-pushed the laura/orgs-441-do-not-allow-passing-system-permissions-to-has-from-the branch from 65a25ba to ca63d27 Compare December 19, 2024 18:03
@LauraBeatris LauraBeatris marked this pull request as ready for review December 19, 2024 18:10
Comment on lines +116 to +122
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' });
});
});

Copy link
Member

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

Comment on lines +29 to +31
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;
Copy link
Member

Choose a reason for hiding this comment

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

This is really cool!

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