Files
summercms/.planning/phases/19.7-generic-mcp-module/19.7-08-PLAN.md

65 KiB

phase, plan, type, wave, depends_on, gap_closure, files_modified, autonomous, requirements, estimate, must_haves
phase plan type wave depends_on gap_closure files_modified autonomous requirements estimate must_haves
19.7-generic-mcp-module 08 execute 3
19.7-06
19.7-07
true
../sm-demo-app/plugins/golem15/user/controllers/backend_link_controller.go
../sm-demo-app/plugins/golem15/user/classes/backend_links.go
../sm-demo-app/plugins/golem15/user/account_contributions.go
../sm-demo-app/plugins/golem15/user/routes.go
../sm-demo-app/plugins/golem15/user/config/config.yaml
../sm-demo-app/plugins/golem15/user/backend_link_auth_time_smoke_test.go
../sm-demo-app/plugins/golem15/user/classes/events.go
../sm-demo-app/plugins/golem15/user/classes/access_revoked.go
../sm-demo-app/plugins/golem15/user/classes/subject_events.go
../sm-demo-app/plugins/golem15/user/classes/mcp_guard.go
../sm-demo-app/plugins/golem15/user/controllers/api_controller.go
../sm-demo-app/plugins/golem15/user/controllers/users_admin_controller.go
../sm-demo-app/plugins/golem15/user/controllers/api_tokens.go
../sm-demo-app/plugins/golem15/user/classes/api_token_scopes.go
../sm-demo-app/plugins/golem15/user/classes/api_tokens.go
../sm-demo-app/plugins/golem15/user/console/api_tokens.go
../sm-demo-app/plugins/golem15/user/plugin.go
../sm-demo-app/plugins/golem15/user/member_token_scopes_smoke_test.go
../sm-demo-app/plugins/golem15/user/models/organisation.go
../sm-demo-app/plugins/golem15/user/models/organisation/fields.yaml
../sm-demo-app/plugins/golem15/user/classes/organisation_logo.go
../sm-demo-app/plugins/golem15/user/lang/en/lang.yaml
../sm-demo-app/plugins/golem15/user/lang/pl/lang.yaml
../sm-demo-app/plugins/golem15/user/README.md
../sm-oauthserver-plugin/classes/mcp_verifier.go
../sm-oauthserver-plugin/classes/mcp_store.go
../sm-oauthserver-plugin/classes/cascade.go
../sm-oauthserver-plugin/classes/subject_events.go
../sm-oauthserver-plugin/controllers/authorizations.go
../sm-oauthserver-plugin/plugin.go
../sm-oauthserver-plugin/mcp_revocation_smoke_test.go
../sm-oauthserver-plugin/README.md
../sm-journal-plugin/mcp.go
../sm-journal-plugin/README.md
../sm-demo-app/vue-demo-app/app/pages/link-admin.vue
../sm-demo-app/vue-demo-app/app/lib/linkCode.ts
../sm-demo-app/vue-demo-app/i18n/locales/en.json
../sm-demo-app/vue-demo-app/i18n/locales/pl.json
../sm-demo-app/vue-demo-app
../sm-demo-app/deploy/nginx/demo.summercms.io.conf
../sm-demo-app/scripts/check-deploy.sh
../sm-demo-app/plugins/golem15/oauthserver
../sm-demo-app/plugins/golem15/journal
true
SC-4
D-03
D-05
D-07
D-08
D-09
D-19
D-20
D-21
D-26
D-27
D-28
E-1
E-2
tokens raw_tokens tasks confidence
140000 140000 4 low
truths artifacts key_links
The account link is confirmed only by a session whose auth_time is at or after the link request: a token refreshed after the request is refused with 409 stale_session, a token without auth_time is refused the same way, and a fresh sign-in after the request links (C-CR-02 plugin side, D-05)
The link code never reaches a server log: My account answers <frontend_url><page_path>#code=<code>, the site page reads the fragment, keeps the code in sessionStorage across the sign-in, shows the request through POST /_user/api/v1/backend-link/show with the code in the body, and shows which frontend account is signed in before the confirm button (C-WR-01, C-IN-06, D-05)
Banning a user, resetting their password, an admin setting their password, or their own password change revokes their MCP access and refresh tokens created before the cut-off and ends their MCP sessions; the MCP verifier and the MCP refresh rotation refuse a banned user and any token created before tokens_valid_after plus one second (the stored cutoff is whole seconds, so a token from earlier in the cutoff's second is refused too), and the revoke uses the untruncated revocation instant; a banned user's link answers no backend user (C-CR-01, D-08, D-27)
Creating or removing a frontend user's backend link revokes that user's MCP grants that carry the backend scope, so a backend grant never runs with the reach of an administrator the user did not consent to (C-WR-02, D-21)
A plugin declares member token scopes with pact.HasFrontendTokenScopes; POST /_user/api/v1/tokens and MintAPITokenFor accept them for the application that declares them (a second application in the same process refuses them), the legacy MintAPIToken accepts them through a process-wide fallback, middleware.Scope and APIToken.HasScope check them unchanged, GET /tokens lists them, GET /_user/api/v1/tokens/scopes lists the built-ins and the declared scopes with translated labels, and a duplicate, a built-in redeclared or a bad name fails boot (E-2)
Organisations have a logo image (attachOne `logo`) editable in the backend Organisations form, and applications get the logo for their organisation payloads through exported helpers using the same keys the user payload uses for avatars (E-1)
Revoking one personal token or one OAuth authorization ends only the MCP sessions it opened; a personal token used at /mcp records last_used_ip; Journal's draft_post prompt is hidden from read-only grants; nginx accepts MCP bodies up to pier's 4 MiB cap (C-IN-01..C-IN-05)
Every plugin change is additive: no exported identifier, route, column, payload field or migration removed or changed; plugin go.mod require lines are unchanged
path provides contains
../sm-demo-app/plugins/golem15/user/controllers/backend_link_controller.go auth_time-based confirm and the POST show route VerifyAuthTime
path provides contains
../sm-demo-app/plugins/golem15/user/classes/access_revoked.go AccessRevokedEvent firing helper func FireAccessRevoked(
path provides contains
../sm-demo-app/plugins/golem15/user/classes/api_token_scopes.go the member token scope catalog HasFrontendTokenScopes
path provides contains
../sm-demo-app/plugins/golem15/user/classes/organisation_logo.go OrganisationLogoURL and OrganisationLogoFields func OrganisationLogoFields(
path provides contains
../sm-oauthserver-plugin/classes/cascade.go revocation on access-revoked and on link changes AccessRevokedEvent
path provides contains
../sm-demo-app/vue-demo-app/app/lib/linkCode.ts fragment parsing and sessionStorage key for the link page readLinkCode
from to via pattern
../sm-demo-app/plugins/golem15/user/controllers/backend_link_controller.go summercms.go modules/bouncer/jwt.go bouncer.VerifyAuthTime replaces the iat read VerifyAuthTime
from to via pattern
../sm-oauthserver-plugin/plugin.go ../sm-demo-app/plugins/golem15/user/classes/events.go Listen on *userclasses.AccessRevokedEvent, BackendLinkedEvent and BackendUnlinkedEvent AccessRevokedEvent
from to via pattern
../sm-demo-app/plugins/golem15/user/plugin.go ../sm-demo-app/plugins/golem15/user/classes/api_token_scopes.go Boot compiles the catalog from party.Activated and publishes it; a bad declaration fails boot CompileAPITokenScopes
Close lane C of the phase code review and both sm-servers-app escalations, on the plugin side, as additive changes against the local framework from plans 06 and 07.
Repository Changes
sm-user-plugin (checkout ../sm-demo-app/plugins/golem15/user) C-CR-01 user side; C-CR-02 plugin side (compare against auth_time); C-WR-01; the C-WR-02 link events; E-1 organisation logo; E-2 member token scopes; C-IN-02, C-IN-04, C-IN-05, C-IN-06
../sm-oauthserver-plugin C-CR-01 (verifier and refresh refusals, revoke on ban, reset or password change); C-WR-02 (revoke backend grants on link and unlink); C-IN-02 (client-specific revoke event); C-IN-05
../sm-journal-plugin C-IN-01 (draft_post marked Writes)
../sm-demo-app nginx body cap (C-IN-03); the vue-demo-app /link-admin page (code in the fragment, POST show, signed-in account shown); plugin submodule checkouts synced to the local commits for verification

Planner decisions recorded here (P-34..P-39):

  • P-34 (link page and proof, C-CR-02 and C-WR-01):
    • My account answers golem15.user.frontend_url (else app.url) + golem15.user.backend_links.page_path (new key, default /link-admin, C-IN-06) + #code=<code>.
    • New route POST /_user/api/v1/backend-link/show with body {"code"} and the same answers as the GET route. The GET route stays for compatibility (core-plugin additive rule); the README marks it deprecated because the code in its path reaches access logs.
    • The confirm reads the session token with bouncer.VerifyAuthTime(..., bouncer.AudienceUser) and passes auth_time to ConfirmLinkRequest. The signature is unchanged; the parameter is renamed sessionAuthTime in the doc. A token without auth_time answers 409 stale_session.
  • P-35 (access revocation, C-CR-01):
    • New classes.AccessRevokedEvent{UserIDs []uint, Before time.Time, Reason string, Tx *gorm.DB}.
    • New classes.FireAccessRevoked(ctx, app, tx, userIDs, before, reason) error. It fires the event in tx (a listener error rolls the write back) and one pact.MCPSubjectRevoked per user after commit.
    • Called by the plugin's ban action, password reset, an admin setting a password, and the self-service password change.
    • The ban action is a wrapper around BanUsers, whose exported signature is unchanged. Inside the action's transaction it reads ThrottleStates for the selected ids before and after BanUsers. The newly banned ids are those banned after but not before, and only they are passed to FireAccessRevoked.
    • Before is the untruncated instant of the revocation (time.Now() taken at the write). The stored tokens_valid_after keeps its whole-second shape (for example now.Truncate(time.Second) in ResetPassword). The self-service change keeps its cutoff of iat minus one second and passes cutoff.Add(time.Second), the current session's sign-in second, so tokens issued since that sign-in survive.
    • RevokeUserAccess, BanUsers and DeactivateUsers keep their signatures. The README tells applications that call them directly to call FireAccessRevoked too. Deactivation keeps its DeactivatingEvent cascade.
    • oauthserver revokes MCP-client access and refresh tokens with created_at < Before. Both the verifier and the MCP refresh rotation also refuse a banned user, and refuse a token with created_at before tokens_valid_after + 1s (CreatedAt.Before(cutoff.Add(time.Second))).
      • Why a second is added: the stored cutoff is truncated to whole seconds while created_at is not. A token created at 12:00:05.300, before a reset at 12:00:05.700 that stores 12:00:05, is therefore refused by the verifier even without the revoke listener.
      • Why !CreatedAt.After(cutoff) alone is not enough: it lets that token through.
      • The cost is a token legitimately minted in the same second right after a reset. An OAuth consent round trip cannot complete that fast, so the cost is accepted.
    • The revocation sits behind one oauthserver function, revokeUserGrants(ctx, tx, userIDs []uint, before time.Time, kinds []string) error. OnAccessRevoked calls it with both the MCP and the OIDC client kinds: the user decided on 2026-10-23 that a ban or a password reset ends every OAuth grant of that user, MCP agents and OIDC sign-ins alike. Link changes (C-WR-02) still revoke only backend-scoped MCP grants.
  • P-36 (backend grants follow the link, C-WR-02): oauthserver listens to BackendLinkedEvent and BackendUnlinkedEvent. In the event's transaction it revokes the frontend user's unrevoked MCP access and refresh tokens whose scopes contain backend; after commit it fires MCPSubjectRevoked with each affected ClientID.
    • BackendUnlinkedEvent already fires on every unlink the plugin performs: My account, the Administrators screen, and the deletion or deactivation of the frontend user (dropUserLink → RemoveLink, documented in classes/events.go).
    • The link event is still handled for one silent path: deleting the backend administrator in cabana removes the link row through the foreign key's ON DELETE CASCADE, and no event fires. Revoking on every new link means a grant left over from that path cannot run with the reach of a later admin, so a backend grant only ever runs with the reach of the admin shown at its consent.
    • This is the review's first option. The second option, storing the consented admin on the grant, needs a framework field and an oauthserver migration and is not taken.
  • P-37 (member token scopes, E-2):
    • classes.APITokenScope{Name, Label, Description, PluginID string; BuiltIn bool} and classes.APITokenScopeCatalog (Scopes(), Allowed(name)).
    • classes.CompileAPITokenScopes(plugins []party.Plugin) (*APITokenScopeCatalog, error) validates with pact.ValidTokenScopeName. It refuses a built-in name (read, write, ai), a duplicate across plugins, an empty label or description, and a :: label or description whose phrase key is missing (checked in Boot against the translator).
    • Boot compiles from party.Activated, publishes the catalog, and fails boot on an error.
    • classes.APITokenScopesFor(app) returns the published catalog or the built-ins.
    • Validation is scoped to the application. New classes.MintAPITokenFor(app *backpack.App, prefix string, userID uint, name string, scopes []string, expiresAt *time.Time, collectionIDs []uint) (string, *models.APIToken, error) checks scopes against APITokenScopesFor(app). The HTTP mint route and the plugin's console command use it, and the README tells applications to use it.
    • The legacy MintAPIToken keeps its signature and keeps working for existing callers (for example an application's own token manager). It accepts the built-ins plus a process-wide fallback set: every name a booted catalog in this process declared. Production runs one application per process, so the set equals that application's catalog. The README documents the difference.
    • classes.ResetDeclaredAPITokenScopes() clears the fallback set. It is exported as a test seam (documented "tests only"), because the plugin's tests live outside the classes package.
    • The HTTP mint route checks the application's own catalog, so an undeclared scope answers the existing 422 text "The selected scope is invalid.". In a test binary that boots two applications, app B refuses app A's scope.
    • Discovery is GET /_user/api/v1/tokens/scopes behind jwt.auth, answering {"data":[{"name","label","description","built_in"}]} with built-ins first. Labels are translated with the plugin's appTranslator for the request locale.
    • AllowedAPITokenScopes stays the built-in list.
  • P-38 (organisation logo, E-1): a second public attachOne logo on Organisation (OrganisationLogoField); the existing avatar stays, for PHP parity and additivity.
    • Attachments live in system_files, so there is no migration.
    • The Organisations form gains an image fileupload field logo.
    • The plugin serves no frontend organisation payload today, so it ships two helpers for the applications that build one:
      • classes.OrganisationLogoURL(ctx, app, org, size) (string, bool, error);
      • classes.OrganisationLogoFields(ctx, app, org) (map[string]any, error), answering has_logo, logo (disk name or nil) and logo_url (a 256 px thumbnail or nil), the keys the user payload uses for avatars.
    • Reversibility costly: the relation name is stored in system_files.field.
  • P-39 (local verification wiring): oauthserver's git-ignored go.work points sm-user-plugin at ../sm-demo-app/plugins/golem15/user. Today it points at another application's checkout, which lacks the new exports. The demo's plugins/golem15/oauthserver and plugins/golem15/journal submodule checkouts are moved, detached, to this plan's local plugin commits so the demo's end-to-end test runs them.
    • None of this is committed: the pointer bumps in sm-demo-app happen after the plugin tags, per the release order.
    • The vue-demo-app pointer is a normal local commit in sm-demo-app, as in plan 04. vue-demo-app is pushed before sm-demo-app when the user releases.

Commits are self-contained: each task's commits build and pass the repository's go vet and -short tests on their own. No commit leaves a repository relying on a later task's commit, and a cross-repository dependency is always committed in the order user plugin → oauthserver → demo.

Purpose: SC-4's identity chain holds under ban, password reset, refresh and re-linking; sm-servers-app gets E-1 and E-2; plan 09 can pin all of it. Output: local commits in sm-user-plugin, sm-oauthserver-plugin, sm-journal-plugin, vue-demo-app and sm-demo-app; three smoke tests.

<execution_context> @/.claude/msd-core/workflows/execute-plan.md @/.claude/msd-core/templates/summary.md </execution_context>

@.planning/PROJECT.md @.planning/STATE.md @.planning/phases/19.7-generic-mcp-module/19.7-GAP-INPUTS.md @.planning/phases/19.7-generic-mcp-module/19.7-REVIEW.md @.planning/phases/19.7-generic-mcp-module/19.7-CONTEXT.md @.planning/phases/19.7-generic-mcp-module/19.7-03-SUMMARY.md @.planning/phases/19.7-generic-mcp-module/19.7-04-SUMMARY.md @.planning/phases/19.7-generic-mcp-module/19.7-07-SUMMARY.md @.planning/notes/2026-10-23-frontend-token-scopes.md @.planning/notes/core-plugins-own-repos.md @CLAUDE.md

<project_rules>

  • Core-plugin rule: sm-user-plugin is used by many applications, and oauthserver and Journal are shared. Every change is additive:
    • no exported func, method or type removed or re-signed (the gate's additive check against 930b158 and v0.1.9 for the user plugin, d31f8e7 for oauthserver, ffa2c8f for Journal);
    • no route, column, migration id, config key, permission code or payload field removed or renamed;
    • existing error bodies stay word for word.
  • Plugin go.mod require lines stay as they are (summercms v0.4.4, sm-user-plugin v0.1.10 in oauthserver). The local framework comes from each repository's replace ../summercms.go or go.work. Never run go get for the framework or a plugin.
  • The user plugin is built and tested with GOWORK=off; its go.mod replace points at ../../../../summercms.go. oauthserver uses its git-ignored go.work (Task 2 retargets it). Journal uses its tracked go.work, which is left unchanged.
  • Docker-backed tests: if the socket is denied although the user is in the docker group, run them through sudo -u golem (CLAUDE.md). Postgres tests never use t.Parallel; they seed unique rows and clean up.
  • Unit tests are plan 09's job. This plan carries three smokes (TestBackendLinkAuthTimeSmoke, TestMCPRevocationSmoke, TestMemberTokenScopesSmoke) and keeps every existing suite green: TestBackendLink, TestUserMCPGuard, TestMCPTokenVerifier, TestMCPConsent, TestJournalMCP, TestMCPEndToEnd. A test pinning the old behaviour (for example the iat-based confirm) changes in the fix commit and is named in the SUMMARY.
  • Each plugin's README changes in the same commit as its exported API, config keys or routes.
  • sm-demo-app has uncommitted changes from other sessions (main.go, the plugins/golem15/user pointer from plan 05): run git -C ../sm-demo-app status --short first and never stage either. Stage by explicit path in every repository. One logical change per commit, no co-author tags. Order: plugin repo commits first, then sm-demo-app commits.
  • Release rule: no tag, push or deploy in this plan. </project_rules>
Task 1: Tracer: the account link proof end to end — My account answers a fragment link, the site page shows the request through POST and the signed-in account, and only a session signed in after the request (auth_time) confirms it Plan 07's `bouncer.VerifyAuthTime` exists in the local framework (`grep -c "func VerifyAuthTime(" modules/bouncer/jwt.go` prints 1), and a Docker daemon answers (`docker info`, directly or through `sudo -u golem`). ../sm-demo-app/plugins/golem15/user/controllers/backend_link_controller.go, ../sm-demo-app/plugins/golem15/user/classes/backend_links.go, ../sm-demo-app/plugins/golem15/user/account_contributions.go, ../sm-demo-app/plugins/golem15/user/routes.go, ../sm-demo-app/plugins/golem15/user/config/config.yaml, ../sm-demo-app/plugins/golem15/user/README.md, ../sm-demo-app/plugins/golem15/user/backend_link_auth_time_smoke_test.go, ../sm-demo-app/vue-demo-app/app/pages/link-admin.vue, ../sm-demo-app/vue-demo-app/app/lib/linkCode.ts, ../sm-demo-app/vue-demo-app/i18n/locales/en.json, ../sm-demo-app/vue-demo-app/i18n/locales/pl.json, ../sm-demo-app/vue-demo-app - 19.7-REVIEW.md, sections C-CR-02, C-WR-01 and C-IN-06; 19.7-07-SUMMARY.md (`VerifyAuthTime`'s final signature) - U controllers/backend_link_controller.go (`BackendLinkShow`, `BackendLinkConfirm`, `backendLinks`, `isLinkGone`); U classes/backend_links.go (`LinkRequestByCode`, `ConfirmLinkRequest` and its doc, `requestUsable`); U account_contributions.go (`startFrontendLink`); U routes.go (the `/backend-link/*` routes and `g.Where("code", ...)`); U config/config.yaml (`frontend_url`, `backend_links`); U classes `FrontendURL` - U backend_link_smoke_test.go and backend_link_test.go (the Postgres harness, `startLink`/`confirmLink`, how a session token is minted for a user) - V app/pages/link-admin.vue, app/composables/useDemoAuth.ts (token cookie, logout), app/pages/login.vue (how `next` is followed), i18n/locales/en.json and pl.json (`linkAdmin.*`) - U README.md, the account link section Implement P-34.
**U backend_link_controller.go:**
- `BackendLinkConfirm` replaces the `VerifyClaims` iat read with `bouncer.VerifyAuthTime(classes.SessionToken(r), secret, bouncer.AudienceUser)`. A subject mismatch or a verify error stays 401. `ok == false` answers the existing 409 `stale_session` body. Pass `authTime` to `ConfirmLinkRequest`.
- Add `BackendLinkShowPost(app)`: it reads `{"code"}` with `readFields` and answers exactly like `BackendLinkShow`: the same 404 for an unknown, used or expired code, and the same data shape. Both show handlers set `Cache-Control: no-store, private`.

**U classes/backend_links.go:** rename the `ConfirmLinkRequest` parameter to `sessionAuthTime` and rewrite its doc. The proof is the sign-in time (`auth_time`), which a refresh never renews; the comparison stays in whole seconds against `created_at`. Keep the signature and types.

**U routes.go:** add `g.Post("/backend-link/show", controllers.BackendLinkShowPost(p.app))` in the same group. The GET route stays.

**U account_contributions.go:**
- `startFrontendLink` answers `classes.FrontendURL(p.app) + pagePath + "#code=" + plain`. Rewrite its doc comment to describe the fragment link as well; the comment must not show the old query-string form.
- `pagePath` comes from the new config key `golem15.user.backend_links.page_path` (default `/link-admin`; a value without a leading `/` gets one) through a small helper in classes next to `FrontendURL`.
- Add the key to config/config.yaml under `backend_links`.

**U README.md:** the link section describes:
- the fragment URL;
- the POST show route;
- the GET show route, kept for compatibility (its path puts the code in access logs, so pages use POST);
- `page_path`;
- the `auth_time` rule, with an upgrade note: session tokens issued before this release carry no `auth_time`, so a frontend user signed in before the upgrade gets `stale_session` and must sign in again before linking. A refresh does not help, because it carries the absence forward.

**New smoke `backend_link_auth_time_smoke_test.go`** (Postgres, created only when not `-short`) holds `TestBackendLinkAuthTimeSmoke`:
1. A user signs in (minted token).
2. The admin creates a request.
3. Refreshing the old token through `POST /_user/api/v1/refresh` and confirming with the refreshed token answers 409 `stale_session`.
4. A login after the request confirms with 200.
5. `POST /backend-link/show` with the code in the body answers the admin's login.
6. The My account action's URL contains `/link-admin#code=` and no query string.

**V app/lib/linkCode.ts** (pure, unit-testable in plan 09):
- `LINK_CODE_KEY = 'link-admin-code'`;
- `readLinkCode(hash: string): string`, returning the 64-hex value of a `#code=` fragment or '';
- `isLinkCode(s: string): boolean`.

**V app/pages/link-admin.vue:**
- In `onMounted` (client only), read the fragment. If it holds a code, store it under `LINK_CODE_KEY` in `sessionStorage` and drop the fragment with `history.replaceState`. Otherwise take the stored code.
- Load the request with `$fetch('/_user/api/v1/backend-link/show', { method: 'POST', body: { code } })`.
- When signed in, load `GET /_user/api/v1/fetch` with the bearer and show `linkAdmin.signedInAs` (the email) above the confirm button, with a `linkAdmin.notYou` action that calls `logout()` and shows the sign-in link.
- The sign-in link is `/login?next=/link-admin`; the code stays in sessionStorage, never in a URL.
- Remove the stored code on success and when the request is gone.
- The route's query parameter is no longer read, and the page's header comment describes the fragment flow.
- Add `linkAdmin.signedInAs` and `linkAdmin.notYou` to en.json and pl.json.
- Reword the existing `linkAdmin.signInAgain` text (shown after a 409 `stale_session` or a 401) in both locales. It says the link needs a sign-in made after the request, and that a session started before the site's last update, or before the link was requested, must sign in again. For example, en: "Linking needs a fresh sign-in. Sessions started before the link was requested, or before the site was last updated, have to sign in again." Add pl to match.

Run `pnpm --dir ../sm-demo-app/vue-demo-app run test` (the existing lib tests stay green).

**Commits:**
1. The user plugin commit.
2. The vue-demo-app commit in its submodule checkout.
3. In sm-demo-app, a separate local commit `chore: bump vue-demo-app (link page: code in the fragment, POST show)` staging only `vue-demo-app`.
GOWORK=off go -C ../sm-demo-app/plugins/golem15/user vet ./... && GOWORK=off go -C ../sm-demo-app/plugins/golem15/user test -count=1 -short ./... && GOWORK=off go -C ../sm-demo-app/plugins/golem15/user test -count=1 -run '^(TestBackendLinkAuthTimeSmoke|TestBackendLink|TestBackendLinkSmoke)$' -v . 2>&1 | grep -c -- '^--- PASS: Test' | grep -qx 3 && pnpm --dir ../sm-demo-app/vue-demo-app run test non-zero exit, "FAIL" in the output, or fewer than 3 top-level PASS lines (a SKIP because Docker is unreachable counts as not passing: run on a Docker host, through sudo -u golem if needed) - `grep -v '^\s*//' ../sm-demo-app/plugins/golem15/user/controllers/backend_link_controller.go | grep -c "bouncer.VerifyAuthTime("` prints 1 and the same filter for `bouncer.VerifyClaims(` prints 0 - `grep -c 'g.Post("/backend-link/show"' ../sm-demo-app/plugins/golem15/user/routes.go` prints 1 and `grep -c 'g.Get("/backend-link/{code}"' ../sm-demo-app/plugins/golem15/user/routes.go` prints 1 (kept) - `grep -c '#code=' ../sm-demo-app/plugins/golem15/user/account_contributions.go` prints 1 and `grep -c '?code=' ../sm-demo-app/plugins/golem15/user/account_contributions.go` prints 0 - `grep -c "page_path" ../sm-demo-app/plugins/golem15/user/config/config.yaml ../sm-demo-app/plugins/golem15/user/README.md` prints at least 1 per file - `grep -c "route.query" ../sm-demo-app/vue-demo-app/app/pages/link-admin.vue` prints 0, `grep -c "sessionStorage" ../sm-demo-app/vue-demo-app/app/pages/link-admin.vue` prints at least 1, and `grep -c "signedInAs" ../sm-demo-app/vue-demo-app/i18n/locales/en.json ../sm-demo-app/vue-demo-app/i18n/locales/pl.json` prints 1 per file - `git -C ../sm-demo-app log -1 --name-only --format=%s | grep -c "^vue-demo-app$"` prints 1 and the same commit lists neither `main.go` nor `plugins/golem15/user` The link proof rests on the sign-in time, the code never appears in a URL the server sees, and the person confirming sees which account they are linking; the smoke proves refresh no longer passes as a fresh sign-in. Task 2: Grant revocation chain: ban, password reset or change revoke MCP grants and end sessions; the verifier and refresh refuse banned and pre-cutoff tokens; backend grants follow the link; token- and client-specific revoke events; last_used_ip on /mcp; deduplicated helpers New events and listeners plus stricter refusals; nothing stored changes shape. ../sm-demo-app/plugins/golem15/user/classes/events.go, ../sm-demo-app/plugins/golem15/user/classes/access_revoked.go, ../sm-demo-app/plugins/golem15/user/classes/backend_links.go, ../sm-demo-app/plugins/golem15/user/classes/subject_events.go, ../sm-demo-app/plugins/golem15/user/classes/mcp_guard.go, ../sm-demo-app/plugins/golem15/user/controllers/api_controller.go, ../sm-demo-app/plugins/golem15/user/controllers/users_admin_controller.go, ../sm-demo-app/plugins/golem15/user/controllers/api_tokens.go, ../sm-demo-app/plugins/golem15/user/controllers/backend_link_controller.go, ../sm-demo-app/plugins/golem15/user/account_contributions.go, ../sm-demo-app/plugins/golem15/user/README.md, ../sm-oauthserver-plugin/classes/mcp_verifier.go, ../sm-oauthserver-plugin/classes/mcp_store.go, ../sm-oauthserver-plugin/classes/cascade.go, ../sm-oauthserver-plugin/classes/subject_events.go, ../sm-oauthserver-plugin/controllers/authorizations.go, ../sm-oauthserver-plugin/plugin.go, ../sm-oauthserver-plugin/mcp_revocation_smoke_test.go, ../sm-oauthserver-plugin/README.md - 19.7-REVIEW.md, sections C-CR-01, C-WR-02, C-IN-02, C-IN-04 and C-IN-05 - U classes/admin_actions.go (`ThrottleStates`, `RevokeUserAccess`, `BanUsers`, `DeactivateUsers`); U classes/events.go (event structs, the `*EventName` constants, `BackendLinkedEvent`, `BackendUnlinkedEvent`); U classes/subject_events.go; U classes/backend_links.go (`LinkedBackendUser` SQL at ~385-410, `insertLink`, `RemoveLink`, `requestUsable`); U models/backend_link_request.go (`IsUsableAt`) - U controllers/api_controller.go (`ResetPassword` at ~440-460, `ChangePassword` at ~700-725); U controllers/users_admin_controller.go (password store at ~236-252, the bulk actions at ~625-660); U controllers/api_tokens.go (`APITokenDestroy`); U classes/mcp_guard.go (`MCPResolvePersonalToken`); U middleware/api_token.go (how `last_used_ip` is stamped) - O classes/mcp_verifier.go (`MCPVerifyToken`), classes/mcp_store.go (`mcpTx.refresh` at ~286, `revokeRefreshLineage`), classes/cascade.go (`Cascade`, `purge`), classes/subject_events.go, controllers/authorizations.go (revoke handler at ~110-125), plugin.go (listener registration at ~99-103), models/access_token.go and refresh_token.go (Scopes, CreatedAt, RevokedAt), models/client.go (`ClientKindMCP`), mcp_verifier_smoke_test.go and harness_test.go (test shapes) - summercms.go modules/towel/context.go (`ClientIP`) and modules/pact/mcp.go (`MCPSubjectChanged.TokenID`, `ClientID`) from plan 07 - `cat ../sm-oauthserver-plugin/go.work` (the current `sm-user-plugin` replace target) **Step 0, local environment (P-39).** Edit the git-ignored `../sm-oauthserver-plugin/go.work` so its `sm-user-plugin` replace points at `../sm-demo-app/plugins/golem15/user`. Record the previous target in the SUMMARY. Never commit go.work.
**U, P-35:**
- In classes/events.go, add `AccessRevokedEvent{UserIDs []uint; Before time.Time; Reason string; Tx *gorm.DB}` and `AccessRevokedEventName = "user.AccessRevoked"`, documented like the other events.
- New file classes/access_revoked.go holds `FireAccessRevoked(ctx context.Context, app *backpack.App, tx *gorm.DB, userIDs []uint, before time.Time, reason string) error`. It fires the event (a listener error is returned, so the caller's transaction rolls back), then for each id calls `FireSubjectChangedAfterCommit` with `MCPSubjectRevoked`. A nil app or bus, or an empty id list, is a no-op.
- Callers:
  - **Ban.** `usersAdminController` gets a `banUsers` wrapper used by the `ban` bulk action. Inside the action's transaction `tx`:
    1. read `classes.ThrottleStates(ctx, tx, ids)` for the selected ids;
    2. call `classes.BanUsers(ctx, tx, users)`;
    3. read `ThrottleStates` again;
    4. take the newly banned ids (banned after, not before), and only when that list is non-empty call `FireAccessRevoked(ctx, app, tx, newly, time.Now(), "ban")`.
  - **Password reset.** `ResetPassword` keeps storing `tokens_valid_after = now.Truncate(time.Second)`, so the column keeps its shape. It passes the untruncated `now` as `before`, reason `password_reset`. The handler runs outside a transaction today: wrap the update and the event in `lagoon.Transaction`, so a listener failure leaves the password unchanged.
  - **Self-service change.** `ChangePassword` keeps `cutoff = iat - 1s` in the column and passes `cutoff.Add(time.Second)` (the current session's sign-in second) as `before`, reason `password_changed`. Tokens issued since that sign-in survive, as the session JWT does.
  - **Admin-set password.** The admin password store keeps the truncated value in the column and passes the untruncated `time.Now()` as `before`, reason `password_set_by_admin`, in the save's transaction (`requestDB` or the hook's tx).
- `LinkedBackendUser` adds `AND NOT EXISTS (SELECT 1 FROM user_throttle t WHERE t.user_id = l.user_id AND t.is_banned)`. The columns are `user_throttle.user_id` and `user_throttle.is_banned` (models/throttle.go).

**U, C-IN-02, C-IN-04, C-IN-05:**
- `APITokenDestroy` fires `MCPSubjectRevoked` with `TokenID: token.ID` through a new exported helper pair in classes/subject_events.go: `FireSubjectEvent(ctx, app, ev pact.MCPSubjectChanged)` and `FireSubjectEventAfterCommit(ctx, app, tx, ev)`. The existing helpers become wrappers with their signatures kept.
- `MCPResolvePersonalToken` also stamps `last_used_ip` from `towel.ClientIP(ctx)` when present, in the same `UpdateColumns` call as `last_used_at`.
- `requestUsable` keeps its error split but uses `req.IsUsableAt` for the combined check.
- Add an exported `classes.BackendLinksFor(app) *BackendLinks`, used by both account_contributions.go and the controller instead of their duplicate lookups.
- Confirm, in code and README, that `BackendLinkedEvent` and `BackendUnlinkedEvent` fire on every link and unlink path, with `Link.UserID` set. These are the C-WR-02 events oauthserver listens to.
- The README gains the access-revocation section: when it fires, the event, and what applications calling `RevokeUserAccess` or `BanUsers` directly must add.

**O:**
- Add one unexported helper, `issuedBeforeCutoff(createdAt *time.Time, cutoff time.Time) bool`. It answers true when the cutoff is set and `createdAt` is nil or `createdAt.Before(cutoff.Add(time.Second))`. Reason: the stored cutoff is truncated to whole seconds, so a token created earlier in the cutoff's second must be refused too (P-35). Both checks below use it.
- classes/mcp_verifier.go: after loading the principal, refuse with `pact.ErrMCPTokenInvalid` when `issuedBeforeCutoff(token.CreatedAt, principal.TokensValidAfter)`, or when `userclasses.ThrottleStates` reports the user banned. A database error is returned as an error.
- classes/mcp_store.go `mcpTx.refresh`: apply the same three refusals (user gone through `PrincipalByID`, banned, `issuedBeforeCutoff` on the refresh token) by answering the store's existing not-found result, which wristband maps to `invalid_grant`.
- classes/cascade.go:
  - Add the single revocation function `revokeUserGrants(ctx context.Context, tx *gorm.DB, userIDs []uint, before time.Time, kinds []string) error`. It sets `revoked_at` on the users' unrevoked access and refresh tokens created before `before`, whose client kind is in `kinds`, and returns the distinct client ids it touched.
  - `OnAccessRevoked(ctx, *userclasses.AccessRevokedEvent)` calls it in `ev.Tx` with `ev.Before` and the MCP and OIDC client kinds (user decision 2026-10-23: a ban or reset ends every OAuth grant). Before revoking, check how OIDC grants are stored (client kind constant, consent rows, access and refresh tokens) and revoke the tokens and the consent row so the OIDC client must ask again; record the exact rows touched in the SUMMARY.
  - `OnBackendLinkChanged(ctx, userID uint, tx *gorm.DB)` sets `revoked_at` on the user's unrevoked MCP access and refresh tokens whose scopes contain `backend`, then fires `MCPSubjectRevoked` with each distinct `ClientID` after commit.
  - Two adapters: `OnBackendLinked(ctx, *userclasses.BackendLinkedEvent)` and `OnBackendUnlinked(ctx, *userclasses.BackendUnlinkedEvent)`.
- plugin.go: register the three listeners next to the existing two.
- controllers/authorizations.go: the revoke fires with `ClientID: clientID`.
- classes/subject_events.go: delegate to the user plugin's helpers. Keep oauthserver's exported names as thin wrappers (additive rule).
- README: the revocation behaviour.

**New smoke `../sm-oauthserver-plugin/mcp_revocation_smoke_test.go`** (Postgres) holds `TestMCPRevocationSmoke`:
1. Mint an MCP access and refresh token for a user.
2. `BanUsers` plus `FireAccessRevoked` in one transaction.
3. The verifier answers `ErrMCPTokenInvalid`.
4. Both rows have `revoked_at`.
5. A refresh is refused.
6. A second user linked to an admin with a `backend` grant loses it on `RemoveLink`, and keeps a grant without `backend`.

**Commits:** the user plugin first, then oauthserver.
GOWORK=off go -C ../sm-demo-app/plugins/golem15/user vet ./... && GOWORK=off go -C ../sm-demo-app/plugins/golem15/user test -count=1 -short ./... && GOWORK=off go -C ../sm-demo-app/plugins/golem15/user test -count=1 -run '^(TestBackendLink|TestUserMCPGuard|TestBackendLinkAuthTimeSmoke)$' -v . 2>&1 | grep -c -- '^--- PASS: Test' | grep -qx 3 && go -C ../sm-oauthserver-plugin vet ./... && go -C ../sm-oauthserver-plugin test -count=1 -short ./... && go -C ../sm-oauthserver-plugin test -count=1 -run '^(TestMCPRevocationSmoke|TestMCPTokenVerifier|TestMCPConsent)$' -v . 2>&1 | grep -c -- '^--- PASS: Test' | grep -qx 3 non-zero exit, "FAIL" in the output, or a PASS count other than 3 for either repository (a SKIP without Docker counts as not passing) - `grep -c "type AccessRevokedEvent struct" ../sm-demo-app/plugins/golem15/user/classes/events.go` prints 1 and `grep -c "func FireAccessRevoked(" ../sm-demo-app/plugins/golem15/user/classes/access_revoked.go` prints 1 - `grep -v '^\s*//' ../sm-demo-app/plugins/golem15/user/controllers/api_controller.go | grep -c "FireAccessRevoked("` prints at least 2 and `grep -v '^\s*//' ../sm-demo-app/plugins/golem15/user/controllers/users_admin_controller.go | grep -c "FireAccessRevoked("` prints at least 2 - `grep -c "is_banned" ../sm-demo-app/plugins/golem15/user/classes/backend_links.go` prints at least 1 (`user_throttle.is_banned`, models/throttle.go) - `grep -v '^\s*//' ../sm-oauthserver-plugin/classes/mcp_verifier.go | grep -c "ThrottleStates(\|TokensValidAfter"` prints at least 2 - `grep -c "AccessRevokedEvent\|BackendLinkedEvent\|BackendUnlinkedEvent" ../sm-oauthserver-plugin/plugin.go` prints at least 3 - `grep -v '^\s*//' ../sm-oauthserver-plugin/controllers/authorizations.go | grep -c "ClientID"` prints at least 1 and `grep -v '^\s*//' ../sm-demo-app/plugins/golem15/user/classes/mcp_guard.go | grep -c "last_used_ip"` prints at least 1 - `git -C ../sm-oauthserver-plugin status --short go.work | wc -l` prints 0 (go.work stays ignored and uncommitted) - `grep -c "func revokeUserGrants(\|func issuedBeforeCutoff(" ../sm-oauthserver-plugin/classes/*.go | awk -F: '{s+=$2} END {print s}'` prints 2, and `grep -v '^\s*//' ../sm-oauthserver-plugin/classes/mcp_verifier.go ../sm-oauthserver-plugin/classes/mcp_store.go | grep -c "issuedBeforeCutoff("` prints at least 2 - `grep -v '^\s*//' ../sm-demo-app/plugins/golem15/user/controllers/users_admin_controller.go | grep -c "ThrottleStates("` prints at least 2 (before and after BanUsers) A banned or password-reset user's MCP grants stop working at once and their sessions end, refresh cannot revive them, a banned user's link stops resolving, a backend grant cannot outlive or be re-targeted by a link change, and single-token or single-client revocations end only what they opened. Task 3: E-2 member token scopes: catalog from pact.HasFrontendTokenScopes, boot validation, mint, check, list and discovery Declared scope names are stored on `user_api_tokens` rows and the discovery route is a published contract of a core plugin. ../sm-demo-app/plugins/golem15/user/classes/api_token_scopes.go, ../sm-demo-app/plugins/golem15/user/classes/api_tokens.go, ../sm-demo-app/plugins/golem15/user/console/api_tokens.go, ../sm-demo-app/plugins/golem15/user/controllers/api_tokens.go, ../sm-demo-app/plugins/golem15/user/routes.go, ../sm-demo-app/plugins/golem15/user/plugin.go, ../sm-demo-app/plugins/golem15/user/lang/en/lang.yaml, ../sm-demo-app/plugins/golem15/user/lang/pl/lang.yaml, ../sm-demo-app/plugins/golem15/user/README.md, ../sm-demo-app/plugins/golem15/user/member_token_scopes_smoke_test.go - 19.7-GAP-INPUTS.md, section E-2 (the ask, "Not asked for", acceptance); .planning/notes/2026-10-23-frontend-token-scopes.md (decision P-30) - summercms.go modules/pact/capabilities.go (`FrontendTokenScope`, `HasFrontendTokenScopes`, `ValidTokenScopeName`) and modules/cabana/token_scopes.go (`validatePluginTokenScope`, `validateTokenScopeMessageKeys`: the validation style to mirror) - U classes/api_tokens.go (`AllowedAPITokenScopes`, `DefaultAPITokenScopes`, `MintAPIToken`), controllers/api_tokens.go (`APITokenStore`, `APITokenIndex`, `apiTokenScopes`, `apiTokenJSON`), middleware/api_token.go (`Scope`), models/api_token.go (`HasScope`), routes.go (the `/tokens` routes), plugin.go (`Boot`, `bootMCPGuard` as the publish pattern), classes/frontend_permission_catalog.go (`party.Activated` lookup), controllers/app_access.go (`appTranslator`) - U api_tokens_test.go and api_tokens_edge_test.go (harness for token routes) - ../fonoteka.go/plugins/golem15/fonoteka/classes/auth/api_token_manager.go (an application calling `MintAPIToken` directly; its call must keep compiling unchanged) and ../fonoteka.go/go.work (its workspace `use`s its own user checkout; the verify builds it through a scratch copy that swaps in this checkout; fonoteka's own go.work is never edited) Implement P-37 in a new file classes/api_token_scopes.go: - `APITokenScope` (Name, Label, Description, PluginID, BuiltIn). - `APITokenScopeCatalog` with `Scopes() []APITokenScope` (a copy, built-ins first, then declarations in activation order) and `Allowed(name string) bool`. - `CompileAPITokenScopes(plugins []party.Plugin) (*APITokenScopeCatalog, error)`. The built-ins `read`, `write` and `ai` carry the labels `golem15.user::lang.api_tokens.scope_` and `scope__description`. Each `pact.HasFrontendTokenScopes` declaration is checked: - the name is trimmed and must pass `pact.ValidTokenScopeName`; - it must not be a built-in; - it must not repeat another plugin's name; the error names both plugins, like cabana's; - label and description must be non-empty. - Every accepted declared name is added to an unexported process-wide set guarded by a `sync.RWMutex`. - `APITokenScopesFor(app *backpack.App) *APITokenScopeCatalog` returns the published catalog or a built-ins-only one. - Add `MintAPITokenFor(app *backpack.App, prefix string, userID uint, name string, scopes []string, expiresAt *time.Time, collectionIDs []uint) (string, *models.APIToken, error)`. It checks scopes with `APITokenScopesFor(app).Allowed` and shares the record-building body with `MintAPIToken` through an unexported helper that takes the allow-check as a func. - `MintAPIToken` keeps its signature, dedupe and default. Its check becomes "built-in, or in the process-wide declared set" (the legacy fallback; its doc points new code to `MintAPITokenFor`). - Add `ResetDeclaredAPITokenScopes()`, which clears the process-wide set. Document it as a test seam that production never calls. - The plugin's console token command (console/api_tokens.go) switches to `MintAPITokenFor` with its app. - `AllowedAPITokenScopes` stays, documented as the built-ins.
In plugin.go `Boot`:
- compile from `app.Lookup[party.Activated]()`;
- check every `::` label and description against the translator (`appTranslator` or `app.Lookup[*phrasebook.Translator]`), failing boot on a missing key;
- publish the catalog;
- return any error, so boot fails.

In controllers/api_tokens.go:
- `apiTokenScopes(raw any)` becomes `apiTokenScopes(catalog, raw)` (unexported, free to change) and checks `catalog.Allowed`. The 422 texts stay word for word.
- `APITokenStore` mints with `classes.MintAPITokenFor(app, ...)`.
- New handler `APITokenScopes(app)` answers `{"data":[{"name","label","description","built_in"}]}`, translating labels and descriptions with `appTranslator(app)` for the request locale.

In routes.go, add `g.Get("/tokens/scopes", controllers.APITokenScopes(p.app), "jwt.auth")` next to the token routes.

Lang en and pl gain the six built-in label and description keys:
- read: "Read" / "Odczyt";
- write: "Write" / "Zapis";
- ai: "AI" / "AI";
- each with a one-line description.

The README gets a "Member token scopes" section covering:
- declaring with `pact.HasFrontendTokenScopes`, with a short example declaring `inventory:read` and `inventory:write` (neutral names: a shared plugin README names no consuming application);
- the boot errors;
- mint, check and list behaviour, with `MintAPITokenFor` as the call applications should use and `MintAPIToken`'s process-wide fallback explained;
- the discovery route and its answer;
- that the admin `g15_` catalog never shows these scopes.

**New smoke `member_token_scopes_smoke_test.go`:**
- `-short` part: `CompileAPITokenScopes` with two test plugins declaring the same name fails; a plugin declaring `write` fails; a bad name fails. Call `ResetDeclaredAPITokenScopes()` in a `t.Cleanup`.
- Postgres part (created only when not `-short`):
  1. A test plugin declaring `servers:write` is activated.
  2. `POST /_user/api/v1/tokens` with `["servers:write"]` answers 201.
  3. A test route behind `APITokenGuard` plus `middleware.Scope("servers:write")` accepts the token.
  4. A `read`-only token gets 403 `Missing required scope: servers:write`.
  5. `["servers:nope"]` answers 422 `The selected scope is invalid.`.
  6. `GET /tokens/scopes` lists `read`, `write`, `ai` and `servers:write` with labels.
  7. A second application booted in the same test without the declaring plugin refuses `["servers:write"]` with the same 422, and `MintAPITokenFor` with that application refuses it.
GOWORK=off go -C ../sm-demo-app/plugins/golem15/user vet ./... && GOWORK=off go -C ../sm-demo-app/plugins/golem15/user test -count=1 -short ./... && GOWORK=off go -C ../sm-demo-app/plugins/golem15/user test -count=1 -run '^TestMemberTokenScopesSmoke$' -v . 2>&1 | grep -q -- '^--- PASS: TestMemberTokenScopesSmoke' && W="$(mktemp -d)" && trap 'rm -rf "$W"' EXIT && F="$(realpath ../fonoteka.go)" && U="$(realpath ../sm-demo-app/plugins/golem15/user)" && printf 'go 1.27.0

toolchain go1.27.0

use ( %s %s/plugins/golem15/feedback %s/plugins/golem15/fonoteka %s/plugins/golem15/golem %s )

replace git.golem15.com/golem15/summercms => %s ' "$F" "$F" "$F" "$F" "$U" "$(pwd)" > "$W/go.work" && test "$(GOWORK="$W/go.work" go -C ../fonoteka.go list -m -f '{{.Dir}}' git.golem15.com/golem15/sm-user-plugin)" = "$U" && GOWORK="$W/go.work" go -C ../fonoteka.go build ./... && rm -rf "$W" <fails_when>non-zero exit, "FAIL" in the output, the PASS line missing (SKIP without Docker counts as missing), the scratch workspace not resolving sm-user-plugin to the demo's user checkout, or fonoteka.go failing to build against the modified user plugin</fails_when> <acceptance_criteria> - grep -c "func CompileAPITokenScopes(\|func APITokenScopesFor(\|type APITokenScopeCatalog struct\|func ResetDeclaredAPITokenScopes(" ../sm-demo-app/plugins/golem15/user/classes/api_token_scopes.go prints 4 - grep -c "func MintAPITokenFor(" ../sm-demo-app/plugins/golem15/user/classes/api_tokens.go prints 1 and grep -v '^\s*//' ../sm-demo-app/plugins/golem15/user/controllers/api_tokens.go | grep -c "MintAPITokenFor(" prints 1 - git -C ../fonoteka.go status --short go.work | wc -l prints 0 (fonoteka's workspace untouched) - grep -c "pact.HasFrontendTokenScopes\|pact.ValidTokenScopeName" ../sm-demo-app/plugins/golem15/user/classes/api_token_scopes.go prints at least 2 - grep -c 'g.Get("/tokens/scopes"' ../sm-demo-app/plugins/golem15/user/routes.go prints 1 - grep -c "AllowedAPITokenScopes = \[\]string{\"read\", \"write\", \"ai\"}" ../sm-demo-app/plugins/golem15/user/classes/api_tokens.go prints 1 (the built-in list keeps its exported form) - grep -c "The selected scope is invalid." ../sm-demo-app/plugins/golem15/user/controllers/api_tokens.go prints at least 1 - grep -c "HasFrontendTokenScopes\|tokens/scopes" ../sm-demo-app/plugins/golem15/user/README.md prints at least 2 </acceptance_criteria> A plugin's declared member scopes can be minted, checked, listed and discovered; undeclared ones are refused at mint time; bad declarations fail boot; the admin token catalog is untouched; MintAPIToken's callers in applications compile unchanged.

Task 4: E-1 organisation logo; Journal's draft_post under the write ceiling; the demo's nginx MCP body cap; demo submodule checkouts on the local plugin commits The attachment relation name `logo` is stored in system_files.field and read by applications' payloads; renaming it needs a data update. ../sm-demo-app/plugins/golem15/user/models/organisation.go, ../sm-demo-app/plugins/golem15/user/models/organisation/fields.yaml, ../sm-demo-app/plugins/golem15/user/classes/organisation_logo.go, ../sm-demo-app/plugins/golem15/user/lang/en/lang.yaml, ../sm-demo-app/plugins/golem15/user/lang/pl/lang.yaml, ../sm-demo-app/plugins/golem15/user/README.md, ../sm-journal-plugin/mcp.go, ../sm-journal-plugin/README.md, ../sm-demo-app/deploy/nginx/demo.summercms.io.conf, ../sm-demo-app/scripts/check-deploy.sh, ../sm-demo-app/plugins/golem15/oauthserver, ../sm-demo-app/plugins/golem15/journal - 19.7-GAP-INPUTS.md, section E-1; 19.7-REVIEW.md, sections C-IN-01 and C-IN-03 - U models/organisation.go (`OrganisationAvatarField`, `AttachRelations`, `MorphName`), models/organisation/fields.yaml (the `avatar` fileupload), classes/avatar.go (`AvatarURL`: the attachment query, the bucket lookup, `f.Thumb`), controllers/api_controller.go `applyAvatar` (the `avatar`, `avatar_url`, `has_avatar` keys), admin_organisations_test.go (how the organisation form is exercised) - J mcp.go (the `draft_post` prompt at ~154-166) and README.md (the MCP section); summercms.go modules/pact/mcp.go (`MCPPrompt.Writes` from plan 06) - D deploy/nginx/demo.summercms.io.conf (`location = /mcp` at ~213-226, the server-level `client_max_body_size 2m`), scripts/check-deploy.sh (`mcp_locations` and the `/mcp` directive loop at ~224-256); summercms.go modules/pier/pier.go (`maxRequestBody = 4 << 20`) - `git -C ../sm-demo-app submodule status plugins/golem15/oauthserver plugins/golem15/journal` and `cat ../sm-demo-app/go.work` (the demo uses those checkouts) **E-1 (P-38), in U:** - In models/organisation.go, add the constant `OrganisationLogoField = "logo"` and a second relation `{Name: OrganisationLogoField, Public: true}` in `AttachRelations`. Keep `avatar` first and unchanged. - In fields.yaml, add a `logo` field after `avatar`: `type: fileupload`, `mode: image`, `label: golem15.user::lang.organisation.logo`, `comment: golem15.user::lang.organisation.logo_comment`, `imageWidth: 240`, `imageHeight: 120`. - New file classes/organisation_logo.go with: - `OrganisationLogoURL(ctx context.Context, app *backpack.App, org *models.Organisation, size int) (string, bool, error)`. Same lookup as `AvatarURL` for the organisation's morph name and the `logo` field: a thumbnail of `size` by `size` in mode `auto`; the file path when the thumbnail fails (logged); false when there is no logo or no bucket. Only a database failure is an error. - `OrganisationLogoFields(ctx context.Context, app *backpack.App, org *models.Organisation) (map[string]any, error)`, answering `has_logo` (bool), `logo` (disk name, or nil) and `logo_url` (the 256 px URL, or nil): the avatar keys of the user payload, renamed. - Lang en and pl gain `organisation.logo` ("Logo" / "Logo") and `organisation.logo_comment` (en "Shown wherever the site displays the organisation." / pl "Wyświetlane wszędzie, gdzie strona pokazuje organizację."). - The README's Organisations feature and Organisations screen paragraphs name the logo and the two helpers, with the keys. - No migration and no change to any existing payload.
**C-IN-01, in J:** set `Writes: true` on the `draft_post` prompt. The README's MCP section says the prompt is offered only to grants that may write. Commit in sm-journal-plugin.

**C-IN-03, in D:**
- Add `client_max_body_size 4m;` inside `location = /mcp`, with a comment naming pier's 4 MiB request cap.
- In scripts/check-deploy.sh, add `client_max_body_size 4m;` to the directives the `/mcp` location must carry, with the message "(pier refuses bodies over 4 MiB itself; nginx must not cut earlier)".
- Run `bash scripts/check-deploy.sh` in sm-demo-app.
- Commit those two files only.

**P-39, demo checkouts (working tree only, never committed):**
- `git -C ../sm-demo-app/plugins/golem15/oauthserver fetch "$(realpath ../sm-oauthserver-plugin)" master && git -C ../sm-demo-app/plugins/golem15/oauthserver checkout --detach FETCH_HEAD`.
- The same for `plugins/golem15/journal` from `../sm-journal-plugin`.
- Then `go -C ../sm-demo-app build -tags summercms_mcp ./...` and `go -C ../sm-demo-app test -count=1 -short ./...`.
- Record both new submodule HEADs in the SUMMARY and the deferred pointer bumps.
GOWORK=off go -C ../sm-demo-app/plugins/golem15/user vet ./... && GOWORK=off go -C ../sm-demo-app/plugins/golem15/user test -count=1 -short ./... && go -C ../sm-journal-plugin vet ./... && go -C ../sm-journal-plugin test -count=1 -short ./... && (cd ../sm-demo-app && bash scripts/check-deploy.sh && go build -tags summercms_mcp ./... && go test -count=1 -short ./...) && test "$(git -C ../sm-demo-app/plugins/golem15/oauthserver rev-parse HEAD)" = "$(git -C ../sm-oauthserver-plugin rev-parse HEAD)" && test "$(git -C ../sm-demo-app/plugins/golem15/journal rev-parse HEAD)" = "$(git -C ../sm-journal-plugin rev-parse HEAD)" non-zero exit, "FAIL" in the output, check-deploy.sh printing an error, or a demo submodule checkout not on its plugin repository's HEAD - `grep -c 'OrganisationLogoField = "logo"' ../sm-demo-app/plugins/golem15/user/models/organisation.go` prints 1 and `grep -c "OrganisationAvatarField" ../sm-demo-app/plugins/golem15/user/models/organisation.go` still prints at least 2 - `grep -A3 "^ logo:" ../sm-demo-app/plugins/golem15/user/models/organisation/fields.yaml | grep -c "fileupload"` prints 1 - `grep -c "func OrganisationLogoURL(\|func OrganisationLogoFields(" ../sm-demo-app/plugins/golem15/user/classes/organisation_logo.go` prints 2 and `grep -c '"has_logo"\|"logo_url"' ../sm-demo-app/plugins/golem15/user/classes/organisation_logo.go` prints at least 2 - `git -C ../sm-demo-app/plugins/golem15/user log --oneline 72de822..HEAD -- updates/ | wc -l` prints 0 (no migration added since the plugin HEAD before the gap closure) - `grep -A12 "Name: \"draft_post\"" ../sm-journal-plugin/mcp.go | grep -c "Writes: *true"` prints 1 - `grep -A16 "location = /mcp {" ../sm-demo-app/deploy/nginx/demo.summercms.io.conf | grep -c "client_max_body_size 4m;"` prints 1 and `grep -c "client_max_body_size 4m;" ../sm-demo-app/scripts/check-deploy.sh` prints 1 - `git -C ../sm-demo-app diff --cached --name-only | wc -l` prints 0 after the task's commits (the submodule moves stay unstaged) Organisations carry an editable logo that applications can expose under the avatar-style keys; Journal's drafting prompt follows the write ceiling; the demo's nginx no longer cuts MCP bodies below pier's cap; the demo runs this plan's plugin code for verification without committing unreleased pointers.

<artifacts_this_phase_produces>

Artifacts this plan produces

sm-user-plugin (local commits, untagged):

  • The account link:
    • auth_time-based confirm;
    • POST /_user/api/v1/backend-link/show (GET kept);
    • the #code= link with golem15.user.backend_links.page_path;
    • BackendLinksFor.
  • Access revocation:
    • AccessRevokedEvent and FireAccessRevoked (ban, password reset, admin-set password, self password change);
    • banned users excluded from LinkedBackendUser;
    • FireSubjectEvent and FireSubjectEventAfterCommit (token-specific revoke on DELETE /tokens/{id});
    • last_used_ip on the MCP personal-token path.
  • Member token scopes (E-2): APITokenScope, APITokenScopeCatalog, CompileAPITokenScopes, APITokenScopesFor, MintAPITokenFor, the test seam ResetDeclaredAPITokenScopes, GET /_user/api/v1/tokens/scopes, and boot validation.
  • Organisation logo (E-1): the attachOne logo and OrganisationLogoField, the form field, OrganisationLogoURL and OrganisationLogoFields.
  • README and lang updates.

sm-oauthserver-plugin (local commits, untagged):

  • The verifier and MCP refresh refuse banned and pre-cutoff tokens.
  • Cascade.OnAccessRevoked, OnBackendLinked, OnBackendUnlinked and OnBackendLinkChanged, all built on the one revocation function revokeUserGrants (OnAccessRevoked passes the MCP and OIDC kinds; the link handlers pass MCP with the backend scope only).
  • issuedBeforeCutoff, the whole-second-aware tokens_valid_after rule.
  • The client-specific revoke event.
  • Subject-event helpers delegate to the user plugin.
  • README.

sm-journal-plugin (local commit, untagged): draft_post with Writes: true; README.

vue-demo-app (local commit): /link-admin reads the fragment, uses POST show, shows the signed-in account, and keeps the code in sessionStorage; app/lib/linkCode.ts; i18n keys.

sm-demo-app (local commits):

  • the vue-demo-app pointer bump;
  • nginx client_max_body_size 4m on /mcp, enforced by check-deploy.sh;
  • the oauthserver and journal submodule checkouts moved to the local plugin commits (working tree only).

Smokes: TestBackendLinkAuthTimeSmoke, TestMemberTokenScopesSmoke (user plugin); TestMCPRevocationSmoke (oauthserver).

Decisions: P-34 to P-39. </artifacts_this_phase_produces>

<threat_model>

Trust Boundaries

Boundary Description
site browser to the link pages a signed-in browser (possibly shared) confirms a link code
web server logs and analytics to the link code anything that records request lines or query strings
user plugin to oauthserver (events) user state changes must reach the OAuth grants that act for the user
MCP verifier and refresh to the user record a grant is only as good as the account behind it
plugins to the member token catalog plugin-declared scope names are stored on member tokens and checked by route middleware
admins to organisation records backend editors upload organisation images that the frontend shows
nginx to pier request size limits in front of the MCP endpoint

STRIDE Threat Register

Threat ID Category Component Severity Disposition Mitigation Plan
T-19.7-57 Elevation of privilege banned or password-reset users keeping MCP grants and the linked admin's reach high mitigate verifier and refresh refuse banned users and tokens created before tokens_valid_after + 1s (whole-second cutoff, so the same second is covered); the revoke uses the untruncated instant; AccessRevokedEvent revokes MCP tokens and ends sessions; LinkedBackendUser excludes banned users; TestMCPRevocationSmoke here, TestMCPVerifierRevocation, TestMCPGrantRevocation and TestAccessRevocation in plan 09
T-19.7-58 Spoofing the one-shot link code exposed in access logs, request logs and browser history high mitigate #code= fragment; POST show; the code kept in sessionStorage across sign-in; the confirming account shown before the button; GET show kept only for compatibility and documented as deprecated
T-19.7-59 Elevation of privilege a backend grant re-targeted to an administrator the user never consented to high mitigate backend-scoped MCP tokens revoked on every link and unlink (P-36), sessions ended by client
T-19.7-60 Elevation of privilege a member token minted with an undeclared scope, or a declared scope shadowing a built-in or another plugin's medium mitigate catalog validation at boot (pattern, built-ins reserved, duplicates); the HTTP mint and MintAPITokenFor check the application's own catalog, so another application's declaration is refused; 422 unchanged; the legacy MintAPIToken fallback is process-wide and documented
T-19.7-61 Tampering organisation logo uploads low mitigate image-mode fileupload through lagoon/attach (the avatar's validation), behind the Organisations screen permission golem15.users.access_users
T-19.7-62 Denial of service nginx's 2 MiB cap answering HTML 413 before pier's 4 MiB JSON-RPC error low mitigate client_max_body_size 4m on location = /mcp, enforced by check-deploy.sh
T-19.7-63 Repudiation personal tokens used at /mcp showing a stale last_used_ip low mitigate MCPResolvePersonalToken stamps the client address from towel.ClientIP
T-19.7-SC Tampering package installs low mitigate no Go module or npm package added (go.mod and go.sum unchanged in the three plugins; vue-demo-app's pnpm-lock.yaml unchanged; only the existing lock is used for its test run)
</threat_model>
- User plugin: `GOWORK=off go vet ./... && GOWORK=off go test -count=1 ./...` on a Docker host - oauthserver: `go vet ./... && go test -count=1 ./...` on a Docker host, with the retargeted local go.work - Journal: `go vet ./... && go test -count=1 -short ./...` - Demo: `bash scripts/check-deploy.sh`, `go build -tags summercms_mcp ./...` and `go test -count=1 -tags summercms_mcp -run '^TestMCPEndToEnd$' .` on a Docker host - `bash scripts/check-phase19.7.sh --plugins` (the framework repository) prints `additive:` lines for all three plugins and PASS - fonoteka.go and sm-bm-app still build against their own pinned user checkouts: `(cd ../fonoteka.go && go build ./...) && (cd ../sm-bm-app && go build ./...)`. fonoteka.go also builds against this plan's user plugin through the scratch workspace of Task 3's verify.

<success_criteria>

  • C-CR-01 (user and oauthserver parts), C-CR-02 (plugin part), C-WR-01 and C-WR-02 are fixed; C-IN-01..C-IN-06 are fixed
  • E-1 and E-2 are delivered as the GAP-INPUTS ask states, including every E-2 acceptance item (proven by the smoke now and the named tests of plan 09)
  • Every change in the three plugins passes the gate's additive check; plugin go.mod require lines are unchanged
  • Nothing is tagged, pushed or deployed; the demo's plugin pointer bumps wait for the release </success_criteria>
Create `.planning/phases/19.7-generic-mcp-module/19.7-08-SUMMARY.md` when done. Commit it in the framework repository as a planning doc. It contains: - a commit table per repository, mapping each sha to its finding or escalation ids; - the previous and new go.work target in sm-oauthserver-plugin; - the detached submodule HEADs in sm-demo-app; - a "Delivered differently" note for E-1. The plugin serves no frontend organisation payload, so the escalation's "frontend organisation payloads gain the logo" is delivered as `OrganisationLogoURL` and `OrganisationLogoFields`. They give applications the `has_logo`, `logo` and `logo_url` keys for their own organisation payloads. Name this for the sm-servers-app hand-off; - the OIDC decision (ban and reset revoke OIDC grants too) and the rows it touches.

Release rule: this plan does not tag, push or deploy. Every repository works against the local framework (go.work, or replace ../summercms.go), and every plugin's go.mod require line stays at its current version. The plans may commit locally in every repository. The releases happen only after phase verification, in this order:

  1. framework v0.5.0;
  2. the plugin tags that require it (sm-user-plugin, sm-oauthserver-plugin, sm-journal-plugin);
  3. the application bumps: the demo's plugin pointers, and pushing vue-demo-app before sm-demo-app.