Skip to content

feat(authz): step-up freshness for remote-mode admin-tier routes (wiki-v2 issue 713) - #71

Merged
PMQ9 merged 3 commits into
wiki-v2from
fix/713-step-up
Nov 6, 2026
Merged

PMQ9 merged 3 commits into
wiki-v2from
fix/713-step-up

Conversation

@PMQ9

@PMQ9 PMQ9 commented Nov 5, 2026 •

Copy link
Copy Markdown

TL;DR

In remote mode, permanent purge, the five page-restriction writes and spaces/update now need a recent sign-in. The check reads the platform's step-up window stored on the request's own wiki session row. A stale session gets 403 step_up_required (never 401), and the wiki sends the user to the console's confirm page.

This is the fork half of cccvu/wiki-v2 issue 713 (ADR 0034), paired with the super PR on branch fix/713-653-638-336-sessions-devstack.

What changed

Mint (service-bridge/)

  • POST /api/service/session accepts optional authTime and freshUntil (epoch seconds). Either both are sent or neither.
  • Validation, all checked before minting, any failure → 400:
    • safe integers;
    • authTime <= now+60;
    • freshUntil > authTime;
    • window ≤ 86400.
  • The pair is stamped onto the new user_sessions.metadata row, scoped by id + user, not revoked. If stamping fails, the session is revoked and the call returns 500.
  • SessionService is unchanged.
  • Contract (1.13.0): service-bridge.openapi.json declares the pair on MintSessionRequest, with the window ceiling and clock skew as x- values. The provider test pins the schema to MintSessionDto's own keys and those values to mintFreshness's constants; the platform's consumer test pins its mint body to the same schema (review fix).

Gate (authz/step-up/)

  • RemoteStepUpInterceptor + remote-step-up.table.ts, remote mode only. The gated routes:
    • PageController.delete and ConditionalPageOpsController.conditionalDelete, when permanentlyDelete is anything but absent, null or false;
    • the 5 PageRestrictionController writes;
    • SpaceController.updateSpace.
  • It reads the request's own row (findActiveById(req.raw.sessionId)), so freshness is per row and never per user. It fails closed on missing or garbled metadata, a future authTime, a window over 24h, or now >= freshUntil.
  • It is registered in app.module.ts (seam 4) after RemoteNativeRefusalInterceptor and before RemotePurgeInterceptor. The purge interceptor never calls the handler, so a later step-up check would be skipped. The ordering is pinned by AST.
  • The fitness spec pins the table both ways. It also keeps a reasoned NOT_STEPPED_UP list: exports are reads, and share writes are editor content operations.

Client

  • lib/api-client.ts (seam 7) → features/request-errors/step-up.ts. An /api 403 step_up_required triggers location.assign('/console/confirm?return=…'). It never fires on share or public routes. The error still rejects, and the 401 self-heal is untouched.
  • lib/app-route.ts (seam 8): safeRedirectPath now rejects dot-segment paths that normalize to //host. This was an older open redirect via /login?redirect=/..//evil.com, found in review.

Tests

  • Specs:
    • DTO and freshness validation, and the mint stamp;
    • interceptor allow/deny: fresh, stale, missing, garbled, future, the predicate, native-mode bypass;
    • per-row regression: an old row stays refused after a fresh re-mint;
    • fitness: table and keep list, ordering;
    • client step-up helper and safeRedirectPath.
  • pg spec: session-freshness.pg.spec.ts runs in the docmost-authz-pg lane; it self-skipped locally.
  • Mutation-proven, 13 mutants all red, including: read the newest session instead of the request's row; drop the purge predicate; register after the purge interceptor; answer 401.
  • Live, on an isolated stack:
    • a stale wiki purge → 403 → confirm page → OTP → retried delete 200;
    • the superseded fork token afterwards returns 401.
  • check-upstream-boundary.sh passes. Only seams 4, 7, 8 and 162 are touched, and UPSTREAM_MODIFICATIONS.md (super repo) is updated.

Merge order: this PR first (merge commit), then re-pin the super gitlink to the merge SHA, then the super PR.

🤖 Generated with Claude Code

…i-v2 docmost#713)

The platform's browser mint (/api/service/session) now passes the human's
token-bound auth_time and freshUntil. The service bridge validates both
(both or neither, safe ints, authTime <= now+60, window <= 24h) and stores
them on the new user_sessions row's metadata. Freshness is per row, never
per user.

RemoteStepUpInterceptor (remote mode only, registered before
RemotePurgeInterceptor) refuses with 403 step_up_required, never 401,
unless the request's own session row is inside its window. Gated:
- permanent purge (PageController.delete, conditionalDelete)
- the five page-restriction writes
- spaces/update
Reads (export) and share writes are recorded as not stepped up.
remote-step-up.fitness.spec.ts pins the table both ways.

The client redirects an /api 403 step_up_required to
/console/confirm?return=<path>. safeRedirectPath also rejects a
dot-segment path that normalizes to //host (an open redirect via
/login?redirect=).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@PMQ9 PMQ9 changed the title feat(authz): step-up freshness for remote-mode admin-tier routes (wiki-v2 #713) feat(authz): step-up freshness for remote-mode admin-tier routes (wiki-v2 issue 713) Nov 5, 2026
PMQ9 and others added 2 commits November 5, 2026 19:02
…3.0 (wiki-v2 docmost#713 review)

MintSessionRequest now declares authTime and freshUntil, plus the window
ceiling and clock skew as x- values. The provider test pins the schema
key set to MintSessionDto's own keys and the x- values to the constants
mintFreshness enforces, so a rename on either side fails a test instead
of the whitelist pipe silently stripping the platform's freshness.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@PMQ9
PMQ9 merged commit c4845f6 into wiki-v2 Nov 6, 2026
@PMQ9
PMQ9 deleted the fix/713-step-up branch November 6, 2026 05:13
PMQ9 added a commit that referenced this pull request Nov 6, 2026
Resolves the service-bridge contract version: docmost#704 took 1.12.0 and docmost#713
took 1.13.0, so the docmost#716 additions (actorIdentityId,
RateLimitedOrConversionBudget, ConversionBudgetExhaustedError) move to
1.14.0, with a 1.14.0 sentence in info.description and the README
paragraph renumbered to match.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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