You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Make the server half of the v3 can() contract directly usable and authoritative. This is the second delivery stage of #173.
Current DX
StackServerAuthProvider exposes can, but the RC2 request path registers and invokes only getIdentity. An application can pass the same policy to client and server configuration and still has to recreate separate session/role checks in every lifecycle hook:
This creates false confidence, repeated session work, policy drift, and generic errors that do not distinguish unauthenticated from forbidden requests.
Proposed DX
Expose framework-neutral request-scoped primitives that resolve the memoized request identity and invoke the configured authoritative policy:
The server is the source of truth. A browser-safe pure evaluator may also be used by the client, but executing the same function in both environments is not required. Database-, tenant-, ownership-, or secret-dependent policies remain server-only.
Scope
Register the server auth provider and request alongside the existing memoized request identity resolver.
Invoke StackServerAuthProvider.can with the memoized identity, request headers, and server-derived resource/action/params request.
Define behavior when auth is absent, can is absent, identity resolution fails, the policy denies, or the policy throws.
Define consistent unauthenticated, forbidden, and internal-policy-error outcomes through a BTST HTTP error contract.
Keep the implementation based on standard Request, Response, and Headers rather than framework-specific request or redirect helpers.
Ensure record ids and security-relevant parameters are reconstructed from the route/body/loaded record rather than trusted from a client authorization claim.
Document lifecycle hooks adding ownership or domain rules after the base policy rather than duplicating it.
Prove that client gating cannot authorize a backend request and that configuring server can does not silently protect an endpoint that has not declared permission semantics.
Error semantics to define
No identity plus a policy denial must produce the documented unauthenticated result.
A resolved identity plus a policy denial must produce the documented forbidden result.
A policy exception must fail closed without being misreported as an authorization success; its HTTP/logging behavior must be explicit.
Current permissive behavior when auth or can is omitted must either be preserved and documented or changed only through an explicit v3 breaking decision.
Acceptance criteria
canRequest evaluates the configured server policy with the memoized identity and registered permission tuple.
requireRequestPermission returns normally on allow and produces the documented typed HTTP error on deny.
Multiple checks during one request resolve identity once.
Parent
Depends on
Related
Purpose
Make the server half of the v3
can()contract directly usable and authoritative. This is the second delivery stage of #173.Current DX
StackServerAuthProviderexposescan, but the RC2 request path registers and invokes onlygetIdentity. An application can pass the same policy to client and server configuration and still has to recreate separate session/role checks in every lifecycle hook:This creates false confidence, repeated session work, policy drift, and generic errors that do not distinguish unauthenticated from forbidden requests.
Proposed DX
Expose framework-neutral request-scoped primitives that resolve the memoized request identity and invoke the configured authoritative policy:
The server is the source of truth. A browser-safe pure evaluator may also be used by the client, but executing the same function in both environments is not required. Database-, tenant-, ownership-, or secret-dependent policies remain server-only.
Scope
canRequestandrequireRequestPermissionprimitives using the registered permission type from [v3 auth] Define the typed permission vocabulary and extension registry #176.StackServerAuthProvider.canwith the memoized identity, request headers, and server-derived resource/action/params request.canis absent, identity resolution fails, the policy denies, or the policy throws.Request,Response, andHeadersrather than framework-specific request or redirect helpers.candoes not silently protect an endpoint that has not declared permission semantics.Error semantics to define
canis omitted must either be preserved and documented or changed only through an explicit v3 breaking decision.Acceptance criteria
canRequestevaluates the configured server policy with the memoized identity and registered permission tuple.requireRequestPermissionreturns normally on allow and produces the documented typed HTTP error on deny.canhave explicit tests.Error("Unauthorized")strings.Non-goals
Blocks