Skip to content

[M2.3d4b] Membership mutation HTTP endpoints with fresh proof and encrypted retries - #114

Merged
samuelmbabhazi merged 5 commits into
mainfrom
feat/m2.3d4b-membership-http
Nov 5, 2026
Merged

samuelmbabhazi merged 5 commits into
mainfrom
feat/m2.3d4b-membership-http

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

What changed

M2.3d4b: HTTP endpoints for organization membership changes, on top of the existing audited MembershipCommands (M2.3c4b).

  • Endpoints. All three are session-only: RequireTenant('member.manage', 'organization'), no bearer opt-in, Origin and CSRF required, and the password-attempt rate limit applies.
    • POST /organizations/{organizationId}/members (201): email, role, password and optional TOTP or recovery code.
    • POST /organizations/{organizationId}/members/{membershipId}/role (200).
    • POST /organizations/{organizationId}/members/{membershipId}/remove (200).
  • Response. Each route answers { membership, session? }:
    • membership is null after a removal;
    • session appears only when the caller changed their own role, with the rotated credentials set only in cookies;
    • changing another account advances that account's security version (in the existing command).
  • Retries. These three routes join the closed retry allowlist. Each replay rechecks live member.manage.
  • Code. BrowserHeaders() is extracted for session-only OpenAPI headers. membershipDto is an explicit mapper.
  • Generated code. openapi.json and the api-client types are regenerated.
  • SPEC and PLAN. The SPEC describes the routes, and M2.3d4b is ticked.

How it was tested

  • Unit tests: the replay route allowlist accepts the three exact routes and rejects malformed variants (upper-case ids, extra segments, /delete, a non-UUID membership id).
  • New membership-http.integration.spec.ts:
    • add with replay and conflicting replay; the subject's sessions are invalidated; no password or cookie in the response;
    • session, Origin, CSRF and password required; a bearer token with member.manage is rejected; DTO validation;
    • an unknown address with a correct password answers 404 and records nothing;
    • promotion, then self-demotion with rotated cookies (the old session gets 401);
    • the last owner cannot be demoted (409);
    • removal with replay; a plain member is denied;
    • rollback when the audit or retry write fails.
  • Not run locally: the integration tests (no Docker). CI is unavailable, so they run in CI-1.
  • Local gate: nx lint, typecheck, test and build; Go checks; generation drift; semgrep; prettier. All pass.

Security considerations

  • Privilege changes need a fresh password and MFA proof and are never reachable with API tokens.
  • Missing and hidden resources give the same answer.
  • Credentials rotate on self-changes, and other accounts' credentials are invalidated.

@samuelmbabhazi
samuelmbabhazi merged commit 1a826d9 into main Nov 5, 2026
@samuelmbabhazi
samuelmbabhazi deleted the feat/m2.3d4b-membership-http branch November 5, 2026 15:42
samuelmbabhazi added a commit that referenced this pull request Nov 5, 2026
…cceptance (#115)

## What changed

M2.3d4c: HTTP endpoints for project and environment role bindings, on
top of the existing audited `BindingCommands` (M2.3c4c1).

- **Endpoints.** All four are session-only:
`RequireTenant('member.manage', <exact scope>)`, no bearer opt-in,
Origin and CSRF required, and the password-attempt rate limit applies.
- `POST /organizations/{o}/projects/{p}/bindings` (200): email, role,
password and optional TOTP or recovery code.
- `POST /organizations/{o}/projects/{p}/bindings/{membershipId}/remove`
(200).
- `POST /organizations/{o}/projects/{p}/environments/{e}/bindings`
(200).
  - `POST .../environments/{e}/bindings/{membershipId}/remove` (200).
- **Response.** `{ binding, session? }`. Only canonical path ids reach
the command.
- **Retries.** The replay route allowlist is rewritten as a small
structured matcher and now covers these routes. Each replay rechecks
live `member.manage`.
- **Generated code.** `openapi.json` and the api-client types are
regenerated. The SPEC is updated and M2.3d4c is ticked.

**Fixes included:**
- **`membership-http.integration.spec.ts` (from #114).** The restricted
Prisma client cannot see tenant rows outside a tenant transaction
(row-level security), so counting memberships through it always returned
0, and `findFirstOrThrow` would have failed. Both specs now read tenant
rows through the administrative login, like the other tenant tests.
- **Intermittent CA unit test.** `rejects malformed, forged and
non-Ed25519 requests` edited the base64 text of the PEM. When the
signature's last byte was 0, the lenient decoder ignored the edit, so
the forged CSR still verified (about 1 run in 256; it failed once in
this gate). The test now flips one bit of the last DER byte. It passed 8
consecutive runs.

## How it was tested

- Unit tests for the replay route allowlist: the new routes are
accepted; wrong scopes, `/role` on bindings, non-UUID or upper-case ids,
`/delete` and extra segments are rejected.
- New `binding-http.integration.spec.ts`:
- a project grant takes effect after re-login; the subject's sessions
end; replay and conflicting replay;
- session, Origin, CSRF and password required; a bearer token with
`member.manage` is rejected; DTO validation;
  - unknown addresses and organization owners answer 404 with no write;
- an environment-only admin cannot override or remove a project admin,
while the project admin can narrow the environment admin;
  - removal revokes access and replays;
  - rollback when the audit or retry write fails.
- **Not run locally:** the integration tests (no Docker). They run in
CI-1.
- Local gate passes.

## Security considerations

- Privilege changes require fresh proof and are never reachable with API
tokens.
- Hidden, unknown and ineligible accounts give the same 404.
- The SPEC 7 rule against overriding a project admin is enforced and
tested over HTTP.
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.

1 participant