Repository navigation
feat(auth): add site transfer token scopes - #3339
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: b2db3ef The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 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 |
9 of 19 tasks
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/auth-atproto
@emdash-cms/blocks
@emdash-cms/cloudflare
@emdash-cms/contentful-to-portable-text
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/plugin-cli
@emdash-cms/plugin-test
@emdash-cms/plugin-types
@emdash-cms/registry-client
@emdash-cms/registry-lexicons
@emdash-cms/registry-loader
@emdash-cms/registry-moderation
@emdash-cms/registry-verification
@emdash-cms/sandbox-workerd
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-field-kit
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
🚀 Deploying Preview to Cloudflare 🚀Preview URL: https://transfer-01-auth-scopes.try.emdashcms.com, https://transfer-01-auth-scopes-emdash-playground.emdash-cms.workers.dev (commit b2db3ef)This URL reflects your latest Preview deploymentPreview Deployments by commit
|
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
docs | 7775201 | Sep 23 2026, 05:12 PM |
Adds the transfer:export, transfer:analyze, and transfer:execute token scopes and the admin-only transfer:export and transfer:import permissions that the site transfer feature authorizes against. The admin scope grants all three transfer scopes. Each transfer scope grants only itself, so a token (for example an agent's) can be limited to a single transfer action. Scope clamping drops them for every role below admin. TRANSFER_SCOPES and isTransferScope() identify them.
Wires the transfer scopes into core's token handling ahead of the site transfer API: - Token scope rules accept a list of scopes satisfied by holding any one of them. /_emdash/api/admin/transfer requires any transfer scope and precedes the generic admin rule, so a token holding only one transfer scope reaches the route, which then checks its specific one. - requireAnyScope() and requireAnyPerm() are the any-of counterparts of requireScope() and requirePerm(). - Resolving a bearer token now also returns tokenId, exposed as locals.tokenId: the row id for a personal access token, and for an OAuth token a one-way id of its grant that stays stable across refreshes and is never a token lookup key. Transfer approvals bind to it. - The OAuth consent page labels the transfer scopes.
Lists Site Export, Site Import Analysis, and Site Import in the API token scope picker, so an admin can give a token narrower transfer access than Admin, which includes all three.
ascorbic
force-pushed
the
transfer/01-auth-scopes
branch
from
September 24, 2026 06:53
7775201 to
b2db3ef
Compare
ascorbic
changed the base branch from
fix/redirect-pattern-literal-escaping
to
main
September 24, 2026 06:55
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Part 1 of 8 of the site transfer stack; based on main. (The redirect pattern compiler hardening it once sat on now ships in #3326.) Site transfer exports a whole EmDash site as a portable
.emdashpackage and imports it into an empty site. Design and approval: RFC #3240.This layer adds the authorization pieces the rest of the stack checks against. Nothing calls a transfer route yet.
@emdash-cms/auth: new token scopestransfer:export,transfer:analyze, andtransfer:execute, and admin-only RBAC permissionstransfer:exportandtransfer:import.admingrants all three scopes. Each transfer scope grants only itself, so a token (an agent's, say) can be limited to one transfer action. Scope clamping drops them for every role below admin. ExportsTRANSFER_SCOPESandisTransferScope().astro/middleware/auth.ts): a rule can now name a list of scopes, satisfied by holding any one of them./_emdash/api/admin/transferrequires any transfer scope. The rule sits before the generic/_emdash/api/adminrule, so a token that holds onlytransfer:analyzereaches the route, and the route then checks the specific scope it needs.requireAnyScope()/requireAnyPerm(): any-of counterparts ofrequireScope()/requirePerm(), used by the transfer routes in part 4.locals.tokenId: resolving a bearer token now also returns an id for the credential. For a PAT it is the token row id. For an OAuth token it is a one-way id of the grant: it stays the same across access-token refreshes, and it is never a token hash or lookup key. Transfer approvals (parts 4 and 6) bind to it.Key decisions for review:
adminshould imply the transfer scopes. We settled on yes: existing admin tokens andemdash logincredentials can use transfer without re-issuing. The narrow scopes exist for delegating less than admin.tokenIdhashes the stored refresh-token hash again, so what gets persisted in approval rows cannot be used to look up a token.Type of change
Checklist
pnpm typecheckpassespnpm lintpassespnpm testpasses (or targeted tests for my change)pnpm formathas been runmessages.pochanges except in translation PRs — a workflow extracts catalogs on merge tomain.AI-generated code disclosure
Screenshots / test output
Not applicable. The admin change adds three entries (Site Export, Site Import Analysis, Site Import) to the API token scope list. The labels and descriptions go through Lingui
msg, and catalogs are extracted after merge.Verified on this branch:
pnpm build,pnpm typecheck, andpnpm --silent lint:json | jq '.diagnostics | length'→0oxfmt --checkon every touched filepackages/authtests: 97 passedrequireAnyScope, OAuth consent labels,tokenIdfor PATs and OAuth grants (stable across refresh, never a token hash), and device-flow clamping of transfer scopes.