@fuzdev/fuz_app 0.182.0 → 0.184.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/actions/CLAUDE.md +535 -1223
- package/dist/actions/action_codegen.d.ts +1 -1
- package/dist/actions/action_codegen.d.ts.map +1 -1
- package/dist/actions/action_codegen.js +3 -2
- package/dist/actions/connection_closer.d.ts +11 -9
- package/dist/actions/connection_closer.d.ts.map +1 -1
- package/dist/actions/connection_closer.js +11 -9
- package/dist/actions/frontend_rpc_client.d.ts +1 -1
- package/dist/actions/register_action_ws.d.ts +14 -1
- package/dist/actions/register_action_ws.d.ts.map +1 -1
- package/dist/actions/register_action_ws.js +2 -1
- package/dist/actions/ws_socket_session.d.ts +9 -1
- package/dist/actions/ws_socket_session.d.ts.map +1 -1
- package/dist/actions/ws_socket_session.js +43 -19
- package/dist/auth/CLAUDE.md +430 -1024
- package/dist/auth/account_queries.d.ts +1 -1
- package/dist/auth/account_queries.js +1 -1
- package/dist/auth/account_routes.d.ts +9 -8
- package/dist/auth/account_routes.d.ts.map +1 -1
- package/dist/auth/account_routes.js +78 -75
- package/dist/auth/admin_actions.d.ts.map +1 -1
- package/dist/auth/admin_actions.js +32 -28
- package/dist/auth/api_token.d.ts +20 -3
- package/dist/auth/api_token.d.ts.map +1 -1
- package/dist/auth/api_token.js +28 -9
- package/dist/auth/api_token_queries.d.ts +2 -2
- package/dist/auth/api_token_queries.js +2 -2
- package/dist/auth/audit_emitter.d.ts +75 -84
- package/dist/auth/audit_emitter.d.ts.map +1 -1
- package/dist/auth/audit_emitter.js +83 -71
- package/dist/auth/audit_log_schema.d.ts +25 -14
- package/dist/auth/audit_log_schema.d.ts.map +1 -1
- package/dist/auth/audit_log_schema.js +23 -8
- package/dist/auth/auth_guard_resolver.d.ts +1 -1
- package/dist/auth/auth_guard_resolver.js +1 -1
- package/dist/auth/bearer_auth.d.ts +2 -5
- package/dist/auth/bearer_auth.d.ts.map +1 -1
- package/dist/auth/bearer_auth.js +4 -13
- package/dist/auth/bootstrap_account.d.ts +42 -26
- package/dist/auth/bootstrap_account.d.ts.map +1 -1
- package/dist/auth/bootstrap_account.js +36 -19
- package/dist/auth/bootstrap_routes.d.ts +20 -21
- package/dist/auth/bootstrap_routes.d.ts.map +1 -1
- package/dist/auth/bootstrap_routes.js +26 -31
- package/dist/auth/bootstrap_token_store.d.ts +3 -4
- package/dist/auth/bootstrap_token_store.d.ts.map +1 -1
- package/dist/auth/bootstrap_token_store.js +1 -1
- package/dist/auth/daemon_token.d.ts +5 -1
- package/dist/auth/daemon_token.d.ts.map +1 -1
- package/dist/auth/daemon_token_middleware.d.ts +12 -8
- package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
- package/dist/auth/daemon_token_middleware.js +15 -21
- package/dist/auth/deps.d.ts +19 -5
- package/dist/auth/deps.d.ts.map +1 -1
- package/dist/auth/deps.js +3 -2
- package/dist/auth/invite_queries.d.ts +51 -3
- package/dist/auth/invite_queries.d.ts.map +1 -1
- package/dist/auth/invite_queries.js +81 -6
- package/dist/auth/invite_schema.d.ts +2 -1
- package/dist/auth/invite_schema.d.ts.map +1 -1
- package/dist/auth/middleware.d.ts +2 -3
- package/dist/auth/middleware.d.ts.map +1 -1
- package/dist/auth/middleware.js +3 -3
- package/dist/auth/request_context.d.ts +3 -3
- package/dist/auth/request_context.js +3 -3
- package/dist/auth/resolved_auth.d.ts +7 -7
- package/dist/auth/resolved_auth.d.ts.map +1 -1
- package/dist/auth/resolved_auth.js +4 -4
- package/dist/auth/role_grant_offer_actions.d.ts +27 -3
- package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_actions.js +42 -35
- package/dist/auth/role_grant_offer_queries.d.ts +60 -4
- package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_queries.js +79 -5
- package/dist/auth/role_grant_queries.d.ts +3 -52
- package/dist/auth/role_grant_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_queries.js +5 -80
- package/dist/auth/self_service_role_actions.d.ts.map +1 -1
- package/dist/auth/self_service_role_actions.js +11 -22
- package/dist/auth/session_cookie.d.ts +82 -174
- package/dist/auth/session_cookie.d.ts.map +1 -1
- package/dist/auth/session_cookie.js +80 -130
- package/dist/auth/session_middleware.d.ts +8 -17
- package/dist/auth/session_middleware.d.ts.map +1 -1
- package/dist/auth/session_middleware.js +14 -23
- package/dist/auth/session_queries.d.ts +15 -17
- package/dist/auth/session_queries.d.ts.map +1 -1
- package/dist/auth/session_queries.js +28 -20
- package/dist/auth/signup_routes.d.ts.map +1 -1
- package/dist/auth/signup_routes.js +93 -43
- package/dist/db/CLAUDE.md +5 -3
- package/dist/db/sql_columns.d.ts +1 -1
- package/dist/db/sql_columns.js +1 -1
- package/dist/dev/setup.d.ts +3 -1
- package/dist/dev/setup.d.ts.map +1 -1
- package/dist/dev/setup.js +3 -1
- package/dist/http/CLAUDE.md +315 -763
- package/dist/http/db_routes.d.ts +8 -23
- package/dist/http/db_routes.d.ts.map +1 -1
- package/dist/http/db_routes.js +73 -73
- package/dist/http/origin.d.ts +7 -8
- package/dist/http/origin.d.ts.map +1 -1
- package/dist/http/origin.js +7 -8
- package/dist/http/pending_effects.d.ts +118 -6
- package/dist/http/pending_effects.d.ts.map +1 -1
- package/dist/http/pending_effects.js +114 -6
- package/dist/http/route_result.d.ts +1 -1
- package/dist/http/route_spec.d.ts +14 -11
- package/dist/http/route_spec.d.ts.map +1 -1
- package/dist/realtime/sse.d.ts +4 -23
- package/dist/realtime/sse.d.ts.map +1 -1
- package/dist/realtime/sse.js +4 -25
- package/dist/server/app_backend.d.ts +4 -5
- package/dist/server/app_backend.d.ts.map +1 -1
- package/dist/server/app_backend.js +3 -1
- package/dist/server/app_server.d.ts +80 -16
- package/dist/server/app_server.d.ts.map +1 -1
- package/dist/server/app_server.js +113 -31
- package/dist/server/app_server_context.d.ts +1 -2
- package/dist/server/app_server_context.d.ts.map +1 -1
- package/dist/server/env.js +2 -2
- package/dist/testing/CLAUDE.md +265 -796
- package/dist/testing/admin_integration.d.ts +2 -3
- package/dist/testing/admin_integration.d.ts.map +1 -1
- package/dist/testing/admin_integration.js +3 -3
- package/dist/testing/adversarial_404.d.ts +6 -1
- package/dist/testing/adversarial_404.d.ts.map +1 -1
- package/dist/testing/adversarial_404.js +38 -17
- package/dist/testing/app_server.d.ts +23 -148
- package/dist/testing/app_server.d.ts.map +1 -1
- package/dist/testing/app_server.js +53 -131
- package/dist/testing/attack_surface.d.ts +1 -1
- package/dist/testing/attack_surface.d.ts.map +1 -1
- package/dist/testing/audit_completeness.d.ts +2 -3
- package/dist/testing/audit_completeness.d.ts.map +1 -1
- package/dist/testing/audit_completeness.js +1 -1
- package/dist/testing/audit_drift_guard.d.ts +11 -6
- package/dist/testing/audit_drift_guard.d.ts.map +1 -1
- package/dist/testing/audit_drift_guard.js +15 -8
- package/dist/testing/cross_backend/audit_cross_helpers.d.ts +12 -9
- package/dist/testing/cross_backend/audit_cross_helpers.d.ts.map +1 -1
- package/dist/testing/cross_backend/audit_cross_helpers.js +13 -14
- package/dist/testing/cross_backend/capabilities.d.ts +9 -6
- package/dist/testing/cross_backend/capabilities.d.ts.map +1 -1
- package/dist/testing/cross_backend/capabilities.js +11 -7
- package/dist/testing/cross_backend/capability_mounts.d.ts +103 -0
- package/dist/testing/cross_backend/capability_mounts.d.ts.map +1 -0
- package/dist/testing/cross_backend/capability_mounts.js +428 -0
- package/dist/testing/cross_backend/cell_moderate.js +2 -2
- package/dist/testing/cross_backend/cell_relations.d.ts.map +1 -1
- package/dist/testing/cross_backend/cell_relations.js +12 -11
- package/dist/testing/cross_backend/conformance_principal.d.ts +54 -0
- package/dist/testing/cross_backend/conformance_principal.d.ts.map +1 -0
- package/dist/testing/cross_backend/conformance_principal.js +283 -0
- package/dist/testing/cross_backend/conformance_table.d.ts +7 -56
- package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_table.js +6 -274
- package/dist/testing/cross_backend/cookie_attributes.js +1 -1
- package/dist/testing/cross_backend/credential_deadline.d.ts.map +1 -1
- package/dist/testing/cross_backend/credential_deadline.js +2 -0
- package/dist/testing/cross_backend/credential_wire.d.ts +1 -1
- package/dist/testing/cross_backend/credential_wire.d.ts.map +1 -1
- package/dist/testing/cross_backend/db_state_diff.d.ts +72 -0
- package/dist/testing/cross_backend/db_state_diff.d.ts.map +1 -0
- package/dist/testing/cross_backend/db_state_diff.js +444 -0
- package/dist/testing/cross_backend/declared_skips.d.ts +68 -0
- package/dist/testing/cross_backend/declared_skips.d.ts.map +1 -0
- package/dist/testing/cross_backend/declared_skips.js +132 -0
- package/dist/testing/cross_backend/default_backend_configs.d.ts +3 -3
- package/dist/testing/cross_backend/default_spine_surface.d.ts +0 -6
- package/dist/testing/cross_backend/default_spine_surface.d.ts.map +1 -1
- package/dist/testing/cross_backend/default_spine_surface.js +4 -9
- package/dist/testing/cross_backend/differential.d.ts +13 -5
- package/dist/testing/cross_backend/differential.d.ts.map +1 -1
- package/dist/testing/cross_backend/differential.js +35 -11
- package/dist/testing/cross_backend/differential_normalize.d.ts +12 -0
- package/dist/testing/cross_backend/differential_normalize.d.ts.map +1 -1
- package/dist/testing/cross_backend/differential_normalize.js +16 -0
- package/dist/testing/cross_backend/full_spine_mount.d.ts +1 -42
- package/dist/testing/cross_backend/full_spine_mount.d.ts.map +1 -1
- package/dist/testing/cross_backend/full_spine_mount.js +45 -4
- package/dist/testing/cross_backend/in_process_setup.d.ts +28 -19
- package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/in_process_setup.js +156 -142
- package/dist/testing/cross_backend/login_security.d.ts +12 -0
- package/dist/testing/cross_backend/login_security.d.ts.map +1 -1
- package/dist/testing/cross_backend/login_security.js +21 -4
- package/dist/testing/cross_backend/request_target_conformance_wire.d.ts +0 -2
- package/dist/testing/cross_backend/request_target_conformance_wire.d.ts.map +1 -1
- package/dist/testing/cross_backend/request_target_conformance_wire.js +3 -1
- package/dist/testing/cross_backend/revocation_drivers.d.ts +18 -5
- package/dist/testing/cross_backend/revocation_drivers.d.ts.map +1 -1
- package/dist/testing/cross_backend/revocation_drivers.js +18 -10
- package/dist/testing/cross_backend/role_grant_cross_helpers.d.ts +1 -1
- package/dist/testing/cross_backend/role_grant_cross_helpers.d.ts.map +1 -1
- package/dist/testing/cross_backend/role_grant_offer_lifecycle.d.ts.map +1 -1
- package/dist/testing/cross_backend/role_grant_offer_lifecycle.js +33 -1
- package/dist/testing/cross_backend/role_grant_participation.js +4 -4
- package/dist/testing/cross_backend/rpc_adversarial.js +1 -1
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts +3 -4
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
- package/dist/testing/cross_backend/rust_spine_consumer_surface.js +2 -2
- package/dist/testing/cross_backend/session_cap.d.ts +2 -2
- package/dist/testing/cross_backend/session_cap.d.ts.map +1 -1
- package/dist/testing/cross_backend/session_cap.js +22 -11
- package/dist/testing/cross_backend/setup.d.ts +32 -2
- package/dist/testing/cross_backend/setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/setup.js +32 -1
- package/dist/testing/cross_backend/spine_suites.d.ts +125 -15
- package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
- package/dist/testing/cross_backend/spine_suites.js +459 -62
- package/dist/testing/cross_backend/spine_surface_constants.d.ts +1 -1
- package/dist/testing/cross_backend/spine_surface_constants.d.ts.map +1 -1
- package/dist/testing/cross_backend/spine_surface_constants.js +1 -0
- package/dist/testing/cross_backend/sse_round_trip.d.ts +9 -1
- package/dist/testing/cross_backend/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/cross_backend/sse_round_trip.js +123 -27
- package/dist/testing/cross_backend/standard.d.ts +2 -3
- package/dist/testing/cross_backend/standard.d.ts.map +1 -1
- package/dist/testing/cross_backend/standard.js +3 -3
- package/dist/testing/cross_backend/testing_backdoor.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_backdoor.js +4 -2
- package/dist/testing/cross_backend/testing_credential_read.d.ts +10 -11
- package/dist/testing/cross_backend/testing_credential_read.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_credential_read.js +12 -12
- package/dist/testing/cross_backend/testing_reset_actions.d.ts +84 -47
- package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_reset_actions.js +95 -63
- package/dist/testing/cross_backend/testing_server_core.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_server_core.js +2 -3
- package/dist/testing/cross_backend/transport_composition.d.ts +1 -1
- package/dist/testing/cross_backend/transport_composition.d.ts.map +1 -1
- package/dist/testing/cross_backend/transport_composition.js +7 -3
- package/dist/testing/cross_backend/ws_round_trip.d.ts +5 -0
- package/dist/testing/cross_backend/ws_round_trip.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_round_trip.js +54 -8
- package/dist/testing/daemon_token_rotation.d.ts.map +1 -1
- package/dist/testing/daemon_token_rotation.js +2 -3
- package/dist/testing/data_exposure.d.ts.map +1 -1
- package/dist/testing/data_exposure.js +3 -0
- package/dist/testing/db.d.ts +0 -32
- package/dist/testing/db.d.ts.map +1 -1
- package/dist/testing/db.js +0 -86
- package/dist/testing/db_entities.d.ts +14 -0
- package/dist/testing/db_entities.d.ts.map +1 -1
- package/dist/testing/db_entities.js +17 -0
- package/dist/testing/db_invariant_queries.d.ts +259 -0
- package/dist/testing/db_invariant_queries.d.ts.map +1 -0
- package/dist/testing/db_invariant_queries.js +400 -0
- package/dist/testing/db_invariants.d.ts +106 -0
- package/dist/testing/db_invariants.d.ts.map +1 -0
- package/dist/testing/db_invariants.gen.sql.d.ts +11 -0
- package/dist/testing/db_invariants.gen.sql.d.ts.map +1 -0
- package/dist/testing/db_invariants.gen.sql.js +13 -0
- package/dist/testing/db_invariants.js +141 -0
- package/dist/testing/db_invariants.sql +152 -0
- package/dist/testing/describe_db.d.ts +36 -0
- package/dist/testing/describe_db.d.ts.map +1 -0
- package/dist/testing/describe_db.js +71 -0
- package/dist/testing/integration.d.ts +8 -12
- package/dist/testing/integration.d.ts.map +1 -1
- package/dist/testing/integration.js +13 -17
- package/dist/testing/integration_helpers.d.ts +1 -1
- package/dist/testing/integration_helpers.d.ts.map +1 -1
- package/dist/testing/rate_limiting.d.ts +3 -4
- package/dist/testing/rate_limiting.d.ts.map +1 -1
- package/dist/testing/rate_limiting.js +6 -5
- package/dist/testing/role_grant_helpers.d.ts +1 -1
- package/dist/testing/role_grant_helpers.d.ts.map +1 -1
- package/dist/testing/round_trip.d.ts.map +1 -1
- package/dist/testing/round_trip.js +3 -0
- package/dist/testing/rpc_attack_surface.d.ts +8 -6
- package/dist/testing/rpc_attack_surface.d.ts.map +1 -1
- package/dist/testing/rpc_attack_surface.js +69 -6
- package/dist/testing/rpc_helpers.d.ts +1 -2
- package/dist/testing/rpc_helpers.d.ts.map +1 -1
- package/dist/testing/rpc_helpers.js +3 -3
- package/dist/testing/rpc_round_trip.d.ts +3 -4
- package/dist/testing/rpc_round_trip.d.ts.map +1 -1
- package/dist/testing/rpc_round_trip.js +4 -1
- package/dist/testing/sse_round_trip.d.ts +3 -4
- package/dist/testing/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/sse_round_trip.js +15 -6
- package/dist/testing/stubs.d.ts +9 -8
- package/dist/testing/stubs.d.ts.map +1 -1
- package/dist/testing/stubs.js +20 -13
- package/dist/testing/test_app.d.ts +168 -0
- package/dist/testing/test_app.d.ts.map +1 -0
- package/dist/testing/test_app.js +123 -0
- package/dist/testing/ws_round_trip.d.ts.map +1 -1
- package/dist/testing/ws_round_trip.js +3 -0
- package/dist/ui/ui_format.d.ts.map +1 -1
- package/dist/ui/ui_format.js +1 -2
- package/package.json +1 -1
|
@@ -42,7 +42,9 @@ import { queue_connection_close } from '../actions/connection_closer.js';
|
|
|
42
42
|
import { jsonrpc_errors } from '../http/jsonrpc_errors.js';
|
|
43
43
|
import { builtin_role_specs, is_builtin_role, list_roles_with_grant_path, RoleName } from './role_schema.js';
|
|
44
44
|
import { GRANT_PATH_SELF_SERVICE } from './grant_path_schema.js';
|
|
45
|
-
import { query_create_role_grant
|
|
45
|
+
import { query_create_role_grant } from './role_grant_queries.js';
|
|
46
|
+
import { query_revoke_role_grant } from './role_grant_offer_queries.js';
|
|
47
|
+
import { emit_supersede_audits } from './role_grant_offer_actions.js';
|
|
46
48
|
import { is_role_grant_active } from './account_schema.js';
|
|
47
49
|
import { has_scoped_role } from './request_context.js';
|
|
48
50
|
import { queue_supersede_notifications } from './role_grant_offer_notifications.js';
|
|
@@ -189,27 +191,14 @@ export const create_self_service_role_actions = (deps, options = {}) => {
|
|
|
189
191
|
self_service: true
|
|
190
192
|
}
|
|
191
193
|
});
|
|
192
|
-
// Supersede cascade —
|
|
193
|
-
//
|
|
194
|
-
//
|
|
195
|
-
//
|
|
196
|
-
//
|
|
197
|
-
//
|
|
198
|
-
//
|
|
199
|
-
|
|
200
|
-
await deps.audit.emit_role_grant_target(ctx, auth, {
|
|
201
|
-
event_type: 'role_grant_offer_supersede',
|
|
202
|
-
target_account_id: offer.to_account_id,
|
|
203
|
-
target_actor_id: offer.to_actor_id,
|
|
204
|
-
metadata: {
|
|
205
|
-
offer_id: offer.id,
|
|
206
|
-
role: offer.role,
|
|
207
|
-
scope_id: offer.scope_id,
|
|
208
|
-
reason: 'role_grant_revoked',
|
|
209
|
-
cause_id: result.id
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
}
|
|
194
|
+
// Supersede cascade — the revoke ended the caller's pending offers of the
|
|
195
|
+
// role (only a role both offerable and self-service-eligible has any) and
|
|
196
|
+
// every offer the caller's actor made, whatever its role, as the admin
|
|
197
|
+
// revoke ends them (`query_revoke_role_grant`). Each gets its forensic row
|
|
198
|
+
// like the admin revoke's, and both parties of each are told: the caller
|
|
199
|
+
// is one party of every offer, but its answer lists none, so its other
|
|
200
|
+
// connections learn of them here.
|
|
201
|
+
await emit_supersede_audits(ctx, deps.audit, result.superseded_offers, 'role_grant_revoked', result.id);
|
|
213
202
|
const revoked_grant = { kind: 'id', id: result.id };
|
|
214
203
|
queue_supersede_notifications(ctx, result.superseded_offers, 'role_grant_revoked', {
|
|
215
204
|
grantor: revoked_grant,
|
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The signed session cookie: its name, value format, verification, and the
|
|
3
|
+
* exact `Set-Cookie` strings that set and clear it — byte for byte the Rust
|
|
4
|
+
* spine's `fuz_auth::session_cookie`.
|
|
3
5
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* Cookie value format: `${encode(identity)}:${expires_at}` (signed with HMAC-SHA256).
|
|
6
|
+
* Cookie value: `keyring.sign("${session_token}:${expires_at}")`. The signed
|
|
7
|
+
* payload carries the raw session token (whose blake3 hash is the
|
|
8
|
+
* `auth_session` row id) and its expiry, so one HMAC covers both the token
|
|
9
|
+
* bind and the freshness check.
|
|
9
10
|
*
|
|
10
11
|
* @module
|
|
11
12
|
*/
|
|
12
13
|
import type { Keyring } from './keyring.js';
|
|
14
|
+
/**
|
|
15
|
+
* The default session cookie name — the Rust spine's `SESSION_COOKIE_NAME`,
|
|
16
|
+
* so a cookie either spine mints reads on both. An app with its own name
|
|
17
|
+
* passes it as `session_cookie_name` wherever the spine takes one.
|
|
18
|
+
*/
|
|
19
|
+
export declare const SESSION_COOKIE_NAME = "fuz_session";
|
|
13
20
|
/**
|
|
14
21
|
* Cookie max age in seconds (30 days — aligned with AUTH_SESSION_LIFETIME_MS).
|
|
15
22
|
*
|
|
16
23
|
* This is an **absolute** session lifetime: the cookie is signed once at
|
|
17
|
-
* mint (`expires_at = mint +
|
|
24
|
+
* mint (`expires_at = mint + SESSION_AGE_MAX`) and never re-signed, matching the DB
|
|
18
25
|
* row's fixed `expires_at`. There is deliberately no sliding renewal on
|
|
19
26
|
* either leg — see `docs/security.md` §Session Security.
|
|
20
27
|
*/
|
|
@@ -49,9 +56,8 @@ export declare const is_cookie_name: (name: string) => boolean;
|
|
|
49
56
|
* what a reader that decodes nothing needs. Twin of the Rust spine's
|
|
50
57
|
* `is_cookie_value`.
|
|
51
58
|
*
|
|
52
|
-
* Anything but a string is refused, whatever its type says:
|
|
53
|
-
*
|
|
54
|
-
* read `undefined` as the text `undefined`.
|
|
59
|
+
* Anything but a string is refused, whatever its type says: a regex alone
|
|
60
|
+
* would read `undefined` as the text `undefined`.
|
|
55
61
|
*
|
|
56
62
|
* @param value - a cookie value
|
|
57
63
|
*/
|
|
@@ -67,7 +73,7 @@ export declare const is_cookie_value: (value: string) => boolean;
|
|
|
67
73
|
* @param value - the signed cookie value (`create_session_cookie_value`)
|
|
68
74
|
* @param max_age - the cookie's lifetime in seconds
|
|
69
75
|
* @returns the `Set-Cookie` header value
|
|
70
|
-
* @throws Error when the name is not an RFC 6265 `cookie-name`, the value holds anything but `cookie-octet`s (
|
|
76
|
+
* @throws Error when the name is not an RFC 6265 `cookie-name`, the value holds anything but `cookie-octet`s (a space, a `;`, a non-ASCII character), or `max_age` is not a non-negative safe integer — a header that would read back differently is never written
|
|
71
77
|
*/
|
|
72
78
|
export declare const format_session_set_cookie: (cookie_name: string, value: string, max_age: number) => string;
|
|
73
79
|
/**
|
|
@@ -81,181 +87,83 @@ export declare const format_session_set_cookie: (cookie_name: string, value: str
|
|
|
81
87
|
*/
|
|
82
88
|
export declare const format_session_clear_cookie: (cookie_name: string) => string;
|
|
83
89
|
/**
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* The `TIdentity` type parameter determines the trust model:
|
|
90
|
-
* - `string` (e.g. a session_id) — the cookie references a server-side session record,
|
|
91
|
-
* enabling per-session revocation and metadata. Use when you need admin controls
|
|
92
|
-
* like "revoke all sessions" or per-session audit trails.
|
|
93
|
-
* - `number` (e.g. an account_id) — the cookie directly encodes the user identity,
|
|
94
|
-
* requiring no server-side session state. Simpler, but individual sessions
|
|
95
|
-
* can only be invalidated by rotating the signing key (which invalidates all sessions).
|
|
96
|
-
*
|
|
97
|
-
* The cookie helpers here take either. The spine's session middleware and
|
|
98
|
-
* auth chain take `SessionOptions<string>` — the identity is the session token
|
|
99
|
-
* the session leg hashes to find its `auth_session` row (`create_session_config`).
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* ```ts
|
|
103
|
-
* // zap: 3-part format (admin:session_id)
|
|
104
|
-
* const zap_config: SessionOptions<string> = {
|
|
105
|
-
* cookie_name: 'zap_session',
|
|
106
|
-
* encode_identity: (session_id) => `admin:${session_id}`,
|
|
107
|
-
* decode_identity: (payload) => {
|
|
108
|
-
* const parts = payload.split(':');
|
|
109
|
-
* if (parts.length !== 2 || parts[0] !== 'admin') return null;
|
|
110
|
-
* return parts[1] || null;
|
|
111
|
-
* },
|
|
112
|
-
* };
|
|
113
|
-
*
|
|
114
|
-
* // visiones: 1-part format (account_id)
|
|
115
|
-
* const visiones_config: SessionOptions<number> = {
|
|
116
|
-
* cookie_name: 'session_id',
|
|
117
|
-
* encode_identity: (id) => String(id),
|
|
118
|
-
* decode_identity: (payload) => {
|
|
119
|
-
* const n = parseInt(payload, 10);
|
|
120
|
-
* return Number.isFinite(n) && n > 0 ? n : null;
|
|
121
|
-
* },
|
|
122
|
-
* };
|
|
123
|
-
* ```
|
|
124
|
-
*/
|
|
125
|
-
export interface SessionOptions<TIdentity> {
|
|
126
|
-
cookie_name: string;
|
|
127
|
-
/**
|
|
128
|
-
* Cookie lifetime in seconds. Single source of truth for both the embedded
|
|
129
|
-
* `expires_at` (via `create_session_cookie_value`) and the cookie's HTTP
|
|
130
|
-
* `Max-Age` attribute (via `session_cookie_header`). Defaults to
|
|
131
|
-
* `SESSION_AGE_MAX` (30 days). Every other attribute is fixed
|
|
132
|
-
* (`SESSION_COOKIE_ATTRIBUTES`).
|
|
133
|
-
*/
|
|
134
|
-
max_age?: number;
|
|
135
|
-
/**
|
|
136
|
-
* Encode identity into the cookie payload (before the `:expires_at` suffix).
|
|
137
|
-
* The payload goes into the cookie as written, so it must hold only RFC
|
|
138
|
-
* 6265 `cookie-octet`s (`is_cookie_value`) — `session_cookie_header` throws
|
|
139
|
-
* on anything else.
|
|
140
|
-
*/
|
|
141
|
-
encode_identity: (identity: TIdentity) => string;
|
|
142
|
-
/** Decode identity from cookie payload. Return null if invalid. */
|
|
143
|
-
decode_identity: (payload: string) => TIdentity | null;
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* The `Set-Cookie` value that sets the session cookie to `value`, a signed
|
|
147
|
-
* cookie value (`create_session_cookie_value`, or the `cookie_value` of
|
|
148
|
-
* `create_capped_session`) — what a success carries
|
|
149
|
-
* (`route_ok(value, {set_cookie: [...]})`). `options.max_age` sets `Max-Age`,
|
|
150
|
-
* as it set the value's embedded expiry; `SESSION_AGE_MAX` when unset. Twin of
|
|
151
|
-
* the Rust `session_cookie_header`, which signs the token itself.
|
|
90
|
+
* Sign a session token into a session cookie value: the keyring's signature
|
|
91
|
+
* of `${session_token}:${expires_at}`, the expiry `SESSION_AGE_MAX` from now —
|
|
92
|
+
* what a `Cookie` header carries after `<name>=`. Signed once, at mint: the
|
|
93
|
+
* lifetime is absolute, never renewed (`docs/security.md` §Session Security).
|
|
94
|
+
* Twin of the Rust `create_session_cookie_value`.
|
|
152
95
|
*
|
|
153
|
-
* @param
|
|
154
|
-
* @param
|
|
155
|
-
* @
|
|
156
|
-
* @
|
|
96
|
+
* @param keyring - key ring for signing
|
|
97
|
+
* @param session_token - the raw session token
|
|
98
|
+
* @param now_seconds - current time in seconds (for testing)
|
|
99
|
+
* @returns the signed cookie value
|
|
157
100
|
*/
|
|
158
|
-
export declare const
|
|
101
|
+
export declare const create_session_cookie_value: (keyring: Keyring, session_token: string, now_seconds?: number) => Promise<string>;
|
|
159
102
|
/**
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
* `
|
|
103
|
+
* Sign a session token and build the `Set-Cookie` header value that sets it
|
|
104
|
+
* under `cookie_name` — `format_session_set_cookie` over
|
|
105
|
+
* `create_session_cookie_value`, with `SESSION_AGE_MAX` as its lifetime. What
|
|
106
|
+
* a success that mints a session carries (`route_ok(value, {set_cookie})`).
|
|
107
|
+
* Twin of the Rust `sign_session_cookie`.
|
|
163
108
|
*
|
|
164
|
-
* @param
|
|
165
|
-
* @
|
|
166
|
-
* @
|
|
109
|
+
* @param keyring - key ring for signing
|
|
110
|
+
* @param session_token - the raw session token (`create_capped_session`'s `token`)
|
|
111
|
+
* @param cookie_name - the session cookie's name
|
|
112
|
+
* @returns the `Set-Cookie` header value
|
|
113
|
+
* @throws Error when the cookie name, or the signed value, is outside the RFC 6265 grammar
|
|
167
114
|
*/
|
|
168
|
-
export declare const
|
|
115
|
+
export declare const sign_session_cookie: (keyring: Keyring, session_token: string, cookie_name: string) => Promise<string>;
|
|
169
116
|
/**
|
|
170
|
-
*
|
|
117
|
+
* A verified, unexpired session cookie: the raw session token it carries and
|
|
118
|
+
* the expiry signed beside it. Twin of the Rust `SessionCookie`.
|
|
171
119
|
*/
|
|
172
|
-
export interface
|
|
173
|
-
/** The
|
|
174
|
-
|
|
175
|
-
/** Index of the key that verified the signature (0 = primary). */
|
|
176
|
-
key_index: number;
|
|
120
|
+
export interface SessionCookie {
|
|
121
|
+
/** The raw session token — its blake3 hash is the `auth_session` row id. */
|
|
122
|
+
token: string;
|
|
177
123
|
/** The signed expiry, in seconds since the Unix epoch — later than the parse. */
|
|
178
124
|
expires_at: number;
|
|
179
125
|
}
|
|
180
126
|
/**
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
127
|
+
* How a request's `Cookie` lines read for the session cookie — what the
|
|
128
|
+
* cookie alone shows, before any database work. Twin of the Rust
|
|
129
|
+
* `SessionCookieRead`.
|
|
130
|
+
*
|
|
131
|
+
* - `absent` — no pair names the cookie
|
|
132
|
+
* - `invalid` — a pair names it and its value fails verification: unreadable,
|
|
133
|
+
* a bad MAC, a signed expiry that has passed, an empty token, an empty
|
|
134
|
+
* value. What the session middleware clears.
|
|
135
|
+
* - `valid` — it verifies under the keyring and its signed expiry is ahead.
|
|
136
|
+
* Says nothing about the `auth_session` row.
|
|
137
|
+
*/
|
|
138
|
+
export type SessionCookieRead = {
|
|
139
|
+
kind: 'absent';
|
|
140
|
+
} | {
|
|
141
|
+
kind: 'invalid';
|
|
142
|
+
} | {
|
|
143
|
+
kind: 'valid';
|
|
144
|
+
cookie: SessionCookie;
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* Read the session cookie out of a request's `Cookie` lines: the
|
|
148
|
+
* `cookie_name` pair (`read_session_cookie_value` — the first, verbatim),
|
|
149
|
+
* verified under the keyring, its signed expiry checked, its session token
|
|
150
|
+
* answered with that expiry.
|
|
151
|
+
*
|
|
152
|
+
* The three answers are what the cookie alone shows (`SessionCookieRead`). An
|
|
153
|
+
* empty value (`name=`) is a cookie sent with none: present and invalid. A
|
|
154
|
+
* valid cookie whose `auth_session` row is gone is still valid here; nothing
|
|
155
|
+
* clears it. There is deliberately no refresh: a re-sign would compute a
|
|
156
|
+
* fresh expiry past the row's fixed `expires_at`, so the lifetime is the one
|
|
157
|
+
* signing at mint, on both spines.
|
|
158
|
+
*
|
|
159
|
+
* Twin of the Rust `parse_session_from_cookies`, which takes the request's
|
|
160
|
+
* headers.
|
|
161
|
+
*
|
|
162
|
+
* @param cookie_lines - the request's `Cookie` header lines
|
|
191
163
|
* @param keyring - key ring for verification
|
|
192
|
-
* @param
|
|
193
|
-
* @param now_seconds - current time in seconds (for testing)
|
|
194
|
-
* @returns `ParsedSession` if valid, null if invalid/expired (the empty string included), undefined if missing
|
|
195
|
-
*/
|
|
196
|
-
export declare const parse_session: <TIdentity>(signed_value: string | null | undefined, keyring: Keyring, options: SessionOptions<TIdentity>, now_seconds?: number) => Promise<ParsedSession<TIdentity> | null | undefined>;
|
|
197
|
-
/**
|
|
198
|
-
* Create a signed session cookie value.
|
|
199
|
-
*
|
|
200
|
-
* Format: `${encode(identity)}:${expires_at}` signed with HMAC-SHA256.
|
|
201
|
-
* Embeds expiration in the signed value itself for defense-in-depth.
|
|
202
|
-
*
|
|
203
|
-
* @param keyring - key ring for signing
|
|
204
|
-
* @param identity - the identity to encode
|
|
205
|
-
* @param options - session configuration with encode logic
|
|
206
|
-
* @param now_seconds - current time in seconds (for testing)
|
|
207
|
-
* @returns signed cookie value string
|
|
208
|
-
*/
|
|
209
|
-
export declare const create_session_cookie_value: <TIdentity>(keyring: Keyring, identity: TIdentity, options: SessionOptions<TIdentity>, now_seconds?: number) => Promise<string>;
|
|
210
|
-
/**
|
|
211
|
-
* Result of processing a session cookie.
|
|
212
|
-
*/
|
|
213
|
-
export interface ProcessSessionResult<TIdentity> {
|
|
214
|
-
/** Whether the session is valid. */
|
|
215
|
-
valid: boolean;
|
|
216
|
-
/** Action the adapter should take. */
|
|
217
|
-
action: 'none' | 'clear';
|
|
218
|
-
/** The decoded identity if the cookie was valid. */
|
|
219
|
-
identity?: TIdentity;
|
|
220
|
-
/** The cookie's signed expiry, epoch seconds, if the cookie was valid. */
|
|
221
|
-
expires_at?: number;
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Create a session config for raw session token identity.
|
|
225
|
-
*
|
|
226
|
-
* The standard pattern: cookie stores the raw session token,
|
|
227
|
-
* server hashes it (blake3) to look up the `auth_session` row.
|
|
228
|
-
* Only the `cookie_name` varies per app.
|
|
229
|
-
*
|
|
230
|
-
* @param cookie_name - cookie name (e.g. `'zap_session'`, `'visiones_session'`)
|
|
231
|
-
* @returns a `SessionOptions<string>` ready for use with session middleware
|
|
232
|
-
*/
|
|
233
|
-
export declare const create_session_config: (cookie_name: string) => SessionOptions<string>;
|
|
234
|
-
/** Canonical session config for fuz_app auth. */
|
|
235
|
-
export declare const fuz_session_config: SessionOptions<string>;
|
|
236
|
-
/**
|
|
237
|
-
* Process a session cookie and determine what action to take.
|
|
238
|
-
*
|
|
239
|
-
* There is deliberately no refresh action: any re-sign computes a fresh
|
|
240
|
-
* `now + max_age` expiry, extending the cookie past the DB row's fixed
|
|
241
|
-
* `expires_at` — the holder would go silently anonymous while carrying a
|
|
242
|
-
* self-perpetuating cookie. The absolute lifetime is one signing at mint,
|
|
243
|
-
* on both legs, matching the Rust spine. A cookie signed by a retired
|
|
244
|
-
* (non-primary) key keeps verifying until the key leaves the keyring;
|
|
245
|
-
* retired keys are safe to drop after `SESSION_AGE_MAX` (see
|
|
246
|
-
* `docs/security.md` §Cookie Key Rotation).
|
|
247
|
-
*
|
|
248
|
-
* The three outcomes are what the cookie alone shows: no cookie (`action:
|
|
249
|
-
* 'none'`), a cookie that fails verification — unreadable, a bad MAC, a signed
|
|
250
|
-
* expiry that has passed, an empty identity, an empty value — (`action:
|
|
251
|
-
* 'clear'`), and a valid one. A valid cookie whose `auth_session` row is gone
|
|
252
|
-
* is still valid here; nothing clears it.
|
|
253
|
-
*
|
|
254
|
-
* @param signed_value - the raw cookie value, nullish when the request carries no session cookie
|
|
255
|
-
* @param keyring - key ring for verification and signing
|
|
256
|
-
* @param options - session configuration
|
|
164
|
+
* @param cookie_name - the session cookie's name
|
|
257
165
|
* @param now_seconds - current time in seconds (for testing)
|
|
258
|
-
* @returns
|
|
166
|
+
* @returns the cookie's reading
|
|
259
167
|
*/
|
|
260
|
-
export declare const
|
|
168
|
+
export declare const parse_session_from_cookies: (cookie_lines: ReadonlyArray<string>, keyring: Keyring, cookie_name: string, now_seconds?: number) => Promise<SessionCookieRead>;
|
|
261
169
|
//# sourceMappingURL=session_cookie.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session_cookie.d.ts","sourceRoot":"","sources":["../../src/lib/auth/session_cookie.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"session_cookie.d.ts","sourceRoot":"","sources":["../../src/lib/auth/session_cookie.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAG5C;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,gBAAgB,CAAC;AAEjD;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,QAAoB,CAAC;AAWjD;;;;;;;;;GASG;AACH,eAAO,MAAM,yBAAyB,8CAA8C,CAAC;AAQrF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM,KAAG,OACW,CAAC;AAE1D;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,MAAM,KAAG,OACY,CAAC;AAgB7D;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,yBAAyB,GACrC,aAAa,MAAM,EACnB,OAAO,MAAM,EACb,SAAS,MAAM,KACb,MAeF,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,2BAA2B,GAAI,aAAa,MAAM,KAAG,MAGjE,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,2BAA2B,GACvC,SAAS,OAAO,EAChB,eAAe,MAAM,EACrB,cAAc,MAAM,KAClB,OAAO,CAAC,MAAM,CAGhB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,mBAAmB,GAC/B,SAAS,OAAO,EAChB,eAAe,MAAM,EACrB,aAAa,MAAM,KACjB,OAAO,CAAC,MAAM,CAKf,CAAC;AAEH;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC7B,4EAA4E;IAC5E,KAAK,EAAE,MAAM,CAAC;IACd,iFAAiF;IACjF,UAAU,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,iBAAiB,GAC5B;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,aAAa,CAAA;CAAE,CAAC;AAoCrF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,0BAA0B,GACtC,cAAc,aAAa,CAAC,MAAM,CAAC,EACnC,SAAS,OAAO,EAChB,aAAa,MAAM,EACnB,cAAc,MAAM,KAClB,OAAO,CAAC,iBAAiB,CAS3B,CAAC"}
|