Skip to content

[WEB-9425] fix: require a non-guest workspace role to create personal API tokens - #9989

Closed
mguptahub wants to merge 1 commit into
previewfrom
web-9425/require-member-role-for-personal-api-tokens
Closed

mguptahub wants to merge 1 commit into
previewfrom
web-9425/require-member-role-for-personal-api-tokens

Conversation

@mguptahub

@mguptahub mguptahub commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Creating a personal API token now requires the caller to hold a role above Guest in at least one workspace.

What changed

  • ApiTokenEndpoint.post returns 403 ({"error": "You don't have the required permissions."}, same shape as the permission classes) when the caller has active workspace memberships and none of them is above Guest. This runs before any token is created.
  • The check is a small private helper that reads the caller's active workspace roles in one query.
  • Contract tests added to apps/api/plane/tests/contract/app/test_api_token.py.

Behaviour

  • Guest-only users cannot create a personal token.
  • Members and admins in any workspace can, including a user who is a guest in one workspace and a member in another.
  • Inactive memberships are ignored.
  • Users with no workspace membership (for example new signups and bot users) are unaffected.
  • Existing tokens, listing, editing and deleting are unchanged; enforcement is at creation time only.

Verification

  • Ran plane/tests/contract/app/test_api_token.py through docker-compose-test.yml: all pass with the change (30 tests).
  • With the view change reverted and the new tests kept, exactly the two denial tests fail (guest-only, and inactive member plus active guest); the rest pass. Change restored afterwards.
  • ruff check and ruff format --check pass on the touched files.
  • A guest's pre-existing token was checked to still authenticate (X-Api-Key on /api/v1/users/me/) and to remain listable, editable and deletable.
  • Not run: external clients (CLI, MCP, SDK) creating tokens as a guest, and the web UI. The settings page still shows the create button to guests, who will now get an error response.

Co-authored-by: Plane AI no-reply@plane.so

Summary by CodeRabbit

  • Bug Fixes
    • Personal API token creation is now restricted for users whose active workspace memberships are all Guest or lower. Users with an active Member-or-higher role in any workspace, or no active workspace memberships, can still create tokens.
    • Existing tokens remain available for authentication, listing, renaming, and deletion, including for Guest users.

… API tokens

Co-authored-by: Plane AI <no-reply@plane.so>
Copilot AI balanced review requested due to automatic review settings October 12, 2026 11:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9f579d36-59d7-4b9a-a3cb-11902c11bdef

📥 Commits

Reviewing files that changed from the base of the PR and between bab49bb and 1bdc3d0.


📒 Files selected for processing (2)
  • apps/api/plane/app/views/api.py
  • apps/api/plane/tests/contract/app/test_api_token.py

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.



📝 Walkthrough

Walkthrough

API token creation now returns HTTP 403 for users whose active workspace memberships are all Guest or lower. Contract tests cover role-based creation permissions and confirm that guests can still use existing tokens.

Changes

API token permissions

Layer / File(s) Summary
Guest-only token creation gate
apps/api/plane/app/views/api.py, apps/api/plane/tests/contract/app/test_api_token.py
The endpoint checks active workspace membership roles before creating a token. Tests cover guest-only, member, admin, inactive-membership, and no-membership cases. They also verify guest access to existing-token authentication, listing, renaming, and deletion.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix


Merge Risk: ⚪ Minimal · up to 1bdc3

No actionable merge-blocking risk is identified; the change appears ready to merge after normal checks.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check Passed The description clearly explains the permission change, affected behavior, implementation, tests, and known limitations. It does not use the template headings or checkbox for change type, but it provi…
Title check Passed The title is concise, specific, and accurately describes the main change: requiring a non-guest workspace role to create personal API tokens.
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.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@makeplane

makeplane Bot commented Oct 12, 2026

Copy link
Copy Markdown

Linked to Plane Work Item(s)

This comment was auto-generated by Plane

@mguptahub

Copy link
Copy Markdown
Contributor Author

Closing in favor of a stacked PR on WEB-9425 against #9972's branch. Blocking PAT creation for guests doesn't fix the underlying issue — it doesn't revoke tokens guests already hold, doesn't help a member later demoted to guest, and blocks legitimate guest API use (commenting, attaching files). The real fix is capping what a PAT can actually do to the holder's role, enforced at the permission layer (the same gap this PR's own ticket, WEB-9425, called 'defense-in-depth,' not the fix for WEB-9422). Replacement PR to follow, stacked on #9972 since it shares files and the restricted-guest read-scoping it depends on.

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.

2 participants