Skip to content

feat: add read/write/delete scopes to API tokens - #10349

Open
harshdubey1234 wants to merge 1 commit into
makeplane:previewfrom
harshdubey1234:feature/api-token-scopes
Open

harshdubey1234 wants to merge 1 commit into
makeplane:previewfrom
harshdubey1234:feature/api-token-scopes

Conversation

@harshdubey1234

@harshdubey1234 harshdubey1234 commented Nov 18, 2026 •

Copy link
Copy Markdown

Description

Part of #10221. This first PR adds token scopes; per-token rate limits will follow in a separate PR.

The problem

Teams connect bots and scripts to Plane with API tokens. Today, every token can do everything its owner can, including deleting work items and entire projects.

Example: you give a reporting bot a token so it can read work items for a weekly summary. If the token leaks, or the bot has a bug, that same token can delete your whole project, and there is no way to give the bot read-only access.

The solution

When you create an API token, you can now choose what it is allowed to do:

Scope Allows
read Viewing data
write Creating and updating data
delete Deleting data

A read-only token can still view everything. If it tries to create, change or delete anything, Plane refuses the request with a clear message, and nothing changes.

Existing tokens keep all three scopes, so current integrations work exactly as before.

sequenceDiagram
    participant Bot as Reporting bot (read-only token)
    participant API as Plane API
    Bot->>API: List work items
    API-->>Bot: 200 OK, work items returned
    Bot->>API: Delete project
    API-->>Bot: 403 "This API token does not have the 'delete' scope."
    Note over API: Project is untouched
Loading

API changes

  • Creating a token (POST /api/users/api-tokens/) accepts an optional scopes list, e.g. ["read"]. If it's left out, the token gets all three scopes.
  • Token details now include scopes. Scopes are fixed when the token is created; to give a bot more access, create a new token.
  • Public API (/api/v1/): a request the token's scopes don't allow returns 403 with a message naming the missing scope.

Data model changes

  • New scopes column on api_tokens. A migration gives every existing token all three scopes.

Root-cause investigation

Before writing code, I used Operate to trace how Plane checks API tokens. It found that tokens carried no information about what they were allowed to do, so there was nothing to check against.

Full investigation: https://operatex.dev/open-source/github/makeplane/plane/issues/10221

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Improvement (change that would cause existing functionality to not work as expected)
  • Code refactoring
  • Performance improvements
  • Documentation update

Screenshots and Media (if applicable)

Loom walkthrough of the fix in action: link will be added here shortly.

Test Scenarios

Same requests, sent to a running Plane server before and after this change:

Request with a read-only token Before After
List work items Allowed Allowed
Create a work item Allowed Refused (403)
Delete a work item Deleted Refused (403), work item kept
Delete the project Deleted Refused (403), project kept
Existing full-access token deletes a work item Allowed Allowed (unchanged)

Automated tests cover each scope, token creation and validation, and existing tokens. The external API test suite passes (433 tests).

References

Copilot AI balanced review requested due to automatic review settings November 18, 2026 17:39
@CLAassistant

CLAassistant commented Nov 18, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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 insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

API tokens now store read, write, and delete scopes. Token creation validates supplied scopes, and API authentication enforces scope requirements based on the HTTP method.

Changes: API token scopes

Layer / File(s) Summary
Store and validate token scopes
apps/api/plane/db/models/api.py, apps/api/plane/db/migrations/0126_apitoken_scopes.py, apps/api/migrations_lockfile.txt, apps/api/plane/app/serializers/api.py, apps/api/plane/app/serializers/__init__.py, apps/api/plane/app/views/api.py, apps/api/plane/tests/contract/app/test_api_token.py
API tokens gain a scopes field that defaults to all three scopes. Token creation validates optional scope lists, removes duplicates, and orders valid values. The API view saves valid tokens through the create serializer. Tests cover defaults, invalid values, and unchanged scopes on PATCH.
Enforce scopes during authentication
apps/api/plane/api/middleware/api_authentication.py, apps/api/plane/tests/unit/middleware/test_api_authentication.py, apps/api/plane/tests/contract/api/test_api_token_scopes.py
Authentication returns the API token object and requires read for GET, HEAD, and OPTIONS; write for POST, PUT, and PATCH; and delete for DELETE. Unsupported methods and missing scopes are denied. Tests cover these method checks and their responses.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant APIKeyAuthentication
  participant APIToken
  participant ProtectedAPIEndpoint
  Client->>APIKeyAuthentication: Send request with API token and HTTP method
  APIKeyAuthentication->>APIToken: Validate token
  APIToken-->>APIKeyAuthentication: Return token object with scopes
  APIKeyAuthentication->>APIKeyAuthentication: Check required scope for method
  APIKeyAuthentication-->>ProtectedAPIEndpoint: Allow request when scope is present
Loading

Possibly related issues

  • Issue 10221 requests per-token read, write, and delete scopes with method-based checks. This PR implements those scope checks; the issue’s per-token rate limit is not included.

Possibly related PRs

  • makeplane/plane#10189: Introduces the migration lockfile contract that this PR updates alongside its new migration.

Suggested labels: 🛡️security

Merge Risk: Minimal · up to 67003

This change adds read, write, and delete scopes to API tokens and enforces them by HTTP method. Existing tokens keep full access, and the supplied context shows no merge-blocking risk.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "feat: add read/write/delete scopes to API tokens" matches the main change. The changeset adds a scopes field to APIToken, enforces scopes in APIKeyAuthentication, and accepts scopes at toke…
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.
Description check Passed The description is mostly complete and follows the repository template. It has a clear Description section that explains the problem, the scope model, the API changes, and the data model change. The T…
Full details: Title check

Explanation

The title "feat: add read/write/delete scopes to API tokens" matches the main change. The changeset adds a scopes field to APIToken, enforces scopes in APIKeyAuthentication, and accepts scopes at token creation. The title is short, specific, and states the primary change.

Full details: Description check

Explanation

The description is mostly complete and follows the repository template. It has a clear Description section that explains the problem, the scope model, the API changes, and the data model change. The Type of Change section has Feature checked. The Test Scenarios section gives a before/after table and reports that automated tests cover each scope, token creation and validation, and existing tokens, with 433 external API tests passing. The References section links issue #10221. The Screenshots section has only a placeholder saying a Loom walkthrough will be added, which is non-critical. The description also includes a Root-cause investigation section that goes beyond the template. It is a useful addition, not a conflict.

Finishing Touches

Generate unit tests (beta)

  • 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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 19456a8b-c05f-4ad0-920f-27f1528ef1f1
Commits

Reviewing files that changed from the base of the PR and between da6e808 and 6700320.

Files selected for processing: 1

  • apps/api/plane/db/models/api.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.

@harshdubey1234
harshdubey1234 force-pushed the feature/api-token-scopes branch from da6e808 to 6700320 Compare November 18, 2026 17:59
@harshdubey1234 harshdubey1234 changed the title feat(api): scoped API tokens (read / write / delete) feat: add read/write/delete scopes to API tokens Nov 18, 2026
API tokens could do everything their owner can, including deleting
work items and whole projects. Tokens now carry scopes (read, write,
delete) that are checked on every /api/v1 request. Existing tokens
keep all three, so current integrations are unaffected.

Refs makeplane#10221
@harshdubey1234
harshdubey1234 force-pushed the feature/api-token-scopes branch from 6700320 to 58a385f Compare November 19, 2026 06:19

This branch has not been deployed

No deployments
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.

3 participants