Skip to content

fix(studio): default scoped PAT permissions to read - #48176

Closed
dhruv2x wants to merge 1 commit into
supabase:masterfrom
dhruv2x:fix/scoped-pat-default-actions
Closed

dhruv2x wants to merge 1 commit into
supabase:masterfrom
dhruv2x:fix/scoped-pat-default-actions

Conversation

@dhruv2x

@dhruv2x dhruv2x commented Jul 22, 2026 •

Copy link
Copy Markdown

When adding a resource in the scoped access token form, the new permission row was seeded with the resource's entire action set (read/write/create/delete). A newly added resource should be least-privilege by default, just read, or the first available action, so tokens meant to be narrowly scoped aren't granted more than intended.

Seed the row through a shared getDefaultActions() helper (used by both form and the toggle util) and add a component test asserting a single default action.

I have read the CONTRIBUTING.md file.

Yes

What kind of change does this PR introduce?

Bug fix. Fixes: #48175

What is the current behavior?

In the "Generate scoped token" form (Account → Access Tokens → scoped), adding a
resource under Configure permissions pre-selects all of that resource's
actions (e.g. read, write, create, delete). The access dropdown shows
"N selected" with every checkbox ticked. If the user submits without manually
deselecting, the created token is granted every action for that resource rather
than a minimal default. the opposite of what a scoped, least-privilege token
is for.

No existing issue. found while reviewing the scoped access token form.

What is the new behavior?

Adding a resource now selects a single least-privilege action by default:
read when the resource supports it, otherwise its first available action. The
user can still tick additional actions as needed. This matches the default the
togglePermissionResource util already applied before the form was reworked.

The default-action logic is extracted into a shared getDefaultActions() helper
so the form and the util can't drift apart again.

Additional context

Root cause:

  • The add-resource handler appended the full resource object,
    whose actions field lists every available action, instead of a row seeded with
    a single default action.

Fix:

  • Permissions.tsx: append(resource) → append({ resource: resource.resource, actions: getDefaultActions(resource) })
  • Permissions.utils.ts: new getDefaultActions() helper; togglePermissionResource reuses it (no behavior change)

Summary by CodeRabbit

  • New Features

    • New access-token permission entries now start with least-privilege defaults, selecting read when available or the first supported action.
  • Bug Fixes

    • Improved initialization of permissions when resources are added, ensuring each entry includes its resource and default actions.

When adding a resource in the scoped access token form, the new
permission row was seeded with the resource's entire action set
(read/write/create/delete). A newly added resource should be
least-privilege by default, just `read`, or the first available action,
so tokens meant to be narrowly scoped aren't granted more than intended.

Seed the row through a shared getDefaultActions() helper (used by both
form and the toggle util) and add a component test asserting a single
default action.

Signed-off-by: Dhruv Chauhan <[email protected]>
@dhruv2x
dhruv2x requested a review from a team as a code owner July 22, 2026 05:59
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for contributing to Supabase! ❤️ Our team will review your PR.

A few tips for a smoother review process:

  • If you have a local version of the repo, run pnpm run format to make sure formatting checks pass.
  • Once we've reviewed your PR, please don't trivially merge master (don't click Update branch if there are no merge conflicts to be fixed). This invalidates any pre-merge checks we've run.

@vercel

vercel Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
design-system Ready Ready Preview, Comment Jul 22, 2026 6:01am

Request Review

@vercel

vercel Bot commented Jul 22, 2026

Copy link
Copy Markdown

@dhruv2x is attempting to deploy a commit to the Supabase Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c4b7d7c2-58a2-41cd-81f0-50a0e376e1d3

📥 Commits

Reviewing files that changed from the base of the PR and between f55ff0e and 3630005.

📒 Files selected for processing (3)
  • apps/studio/components/interfaces/Account/AccessTokens/Scoped/Form/Permissions/Permissions.test.tsx
  • apps/studio/components/interfaces/Account/AccessTokens/Scoped/Form/Permissions/Permissions.tsx
  • apps/studio/components/interfaces/Account/AccessTokens/Scoped/Form/Permissions/Permissions.utils.ts

📝 Walkthrough

Walkthrough

The permissions form now initializes newly selected resources with least-privilege actions, preferring read and otherwise using the first available action. A test harness verifies the resulting permission row.

Changes

Scoped permission defaults

Layer / File(s) Summary
Default action computation and form wiring
apps/studio/components/interfaces/Account/AccessTokens/Scoped/Form/Permissions/Permissions.utils.ts, apps/studio/components/interfaces/Account/AccessTokens/Scoped/Form/Permissions/Permissions.tsx
Adds getDefaultActions and uses it when appending newly selected resources to permissionRows.
Default action behavior test
apps/studio/components/interfaces/Account/AccessTokens/Scoped/Form/Permissions/Permissions.test.tsx
Mounts the real permissions form and verifies that a selected resource receives exactly one default action.
Estimated code review effort: 2 (Simple) ~10 minutes

Possibly related issues

Possibly related PRs

  • supabase/supabase#48011: Both changes modify the scoped permission resource-toggle flow and appended permission entries.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: defaulting scoped PAT permissions to read.
Description check ✅ Passed The description follows the template and includes the required sections with clear current, new, and additional context.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@dhruv2x

dhruv2x commented Jul 22, 2026

Copy link
Copy Markdown
Author

hello @djhi can you have a look?

@djhi

djhi commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

As @awaseem said in the issue: This isn't even out to users btw, its behind a flag since we're actively working on it...
Indeed, we are in the process of refactoring this form entirely. Thanks anyway!

@djhi djhi closed this Jul 24, 2026
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

Successfully merging this pull request may close these issues.

Scoped access token form pre-selects all actions when adding a resource

2 participants