fix: portal user headers only from the portal's service client #91

Merged
sharang merged 1 commits from fix/portal-actor-headers into main 2026-10-26 20:39:03 +00:00
Owner

X-Portal-User-Subject and X-Portal-User-Email named the acting person for any service client. This PR honours them only from the portal's service client.

Why

  • Any tenants.read client (werkmeister-svc, pruefwerk-svc, firmwerk-svc) could set the audit actor of a document download (downloadTenantDocument). Tenant scope still held, so this was wrong attribution, not data access.
  • On the team routes (teamActor) the gap was latent: only portal-svc-* holds tenants.write today. A future tenants.write client could have acted in a user's name.
  • projectActor and the trial extension (adminExtendTrial) used the same ungated pattern.

Change

  • portalUser(r) next to staffActor: the headers count only from a client that holds group users.act. The existing users grant satisfies it, and in stage and prod only portal-svc-* holds it, so no AUTHZ_RULES change.
  • A user token speaks for itself; the headers are ignored for it.
  • Without a principal (auth disabled, dev) the headers are taken as before.
  • Used by teamActor, projectActor/projectActorType, the download audit and the trial extension.

Tests

  • TestPortalUser_onlyFromThePortalClient covers the portal client, three other clients, a user token, no headers and no principal, through portalUser, projectActor, projectActorType and teamActor.
  • Mutation check: without the group check the test fails.
  • All existing tests pass unchanged.

Part of the R1 S0 work (docgen#1), decided by Sharang to go with S0. Stage only.

🤖 Generated with Claude Code

https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf

`X-Portal-User-Subject` and `X-Portal-User-Email` named the acting person for any service client. This PR honours them only from the portal's service client. ### Why - Any `tenants.read` client (`werkmeister-svc`, `pruefwerk-svc`, `firmwerk-svc`) could set the audit actor of a document download (`downloadTenantDocument`). Tenant scope still held, so this was wrong attribution, not data access. - On the team routes (`teamActor`) the gap was latent: only `portal-svc-*` holds `tenants.write` today. A future `tenants.write` client could have acted in a user's name. - `projectActor` and the trial extension (`adminExtendTrial`) used the same ungated pattern. ### Change - `portalUser(r)` next to `staffActor`: the headers count only from a client that holds group `users.act`. The existing `users` grant satisfies it, and in stage and prod only `portal-svc-*` holds it, so **no `AUTHZ_RULES` change**. - A user token speaks for itself; the headers are ignored for it. - Without a principal (auth disabled, dev) the headers are taken as before. - Used by `teamActor`, `projectActor`/`projectActorType`, the download audit and the trial extension. ### Tests - `TestPortalUser_onlyFromThePortalClient` covers the portal client, three other clients, a user token, no headers and no principal, through `portalUser`, `projectActor`, `projectActorType` and `teamActor`. - Mutation check: without the group check the test fails. - All existing tests pass unchanged. Part of the R1 S0 work (docgen#1), decided by Sharang to go with S0. Stage only. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf
sharang added 1 commit 2026-10-26 20:12:56 +00:00
fix: portal user headers only from the portal's service client
ci / shared (pull_request) Successful in 30s
ci / test (pull_request) Successful in 25m30s
ci / image (pull_request) Skipped
3fadfebbb0
X-Portal-User-Subject and X-Portal-User-Email named the acting person for
any service client. Any tenants.read client (werkmeister-svc, pruefwerk-svc,
firmwerk-svc) could thereby set the audit actor of a document download, and
a future tenants.write client could act in a user's name on the team routes.

portalUser honours the headers only from a client that holds the users
group (group users.act, satisfied by the existing users grant: only the
portal's service client in stage and prod), as staffActor does for
X-Staff-*. A user token speaks for itself and the headers are ignored.
Used by teamActor, projectActor/projectActorType, the document download
audit and the trial extension. No AUTHZ_RULES change is needed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf
sharang merged commit 9129e95538 into main 2026-10-26 20:39:03 +00:00
sharang deleted branch fix/portal-actor-headers 2026-10-26 20:39:03 +00:00
Sign in to join this conversation.