@fuzdev/fuz_app 0.180.0 → 0.181.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/dist/actions/CLAUDE.md +14 -14
- package/dist/actions/action_rpc.d.ts +14 -5
- package/dist/actions/action_rpc.d.ts.map +1 -1
- package/dist/actions/action_rpc.js +53 -46
- package/dist/actions/action_types.d.ts +15 -12
- package/dist/actions/action_types.d.ts.map +1 -1
- package/dist/actions/perform_action.d.ts +4 -4
- package/dist/actions/perform_action.d.ts.map +1 -1
- package/dist/actions/perform_action.js +6 -6
- package/dist/actions/register_action_ws.d.ts +6 -2
- package/dist/actions/register_action_ws.d.ts.map +1 -1
- package/dist/actions/register_action_ws.js +14 -3
- package/dist/actions/ws_socket_session.js +1 -1
- package/dist/auth/CLAUDE.md +36 -30
- package/dist/auth/account_actions.d.ts.map +1 -1
- package/dist/auth/account_actions.js +18 -1
- package/dist/auth/account_queries.d.ts +69 -0
- package/dist/auth/account_queries.d.ts.map +1 -1
- package/dist/auth/account_queries.js +82 -0
- package/dist/auth/account_route_schema.d.ts +26 -16
- package/dist/auth/account_route_schema.d.ts.map +1 -1
- package/dist/auth/account_route_schema.js +10 -24
- package/dist/auth/account_routes.d.ts +4 -6
- package/dist/auth/account_routes.d.ts.map +1 -1
- package/dist/auth/account_routes.js +86 -66
- package/dist/auth/admin_actions.d.ts.map +1 -1
- package/dist/auth/admin_actions.js +63 -14
- package/dist/auth/api_token_queries.d.ts +16 -7
- package/dist/auth/api_token_queries.d.ts.map +1 -1
- package/dist/auth/api_token_queries.js +18 -18
- package/dist/auth/audit_log_route_schema.d.ts +1 -1
- package/dist/auth/audit_log_route_schema.d.ts.map +1 -1
- package/dist/auth/audit_log_routes.d.ts +1 -1
- package/dist/auth/audit_log_routes.d.ts.map +1 -1
- package/dist/auth/audit_log_routes.js +10 -12
- package/dist/auth/audit_log_schema.js +4 -4
- package/dist/auth/bearer_auth.d.ts +4 -3
- package/dist/auth/bearer_auth.d.ts.map +1 -1
- package/dist/auth/bearer_auth.js +35 -31
- package/dist/auth/bootstrap_account.d.ts +65 -37
- package/dist/auth/bootstrap_account.d.ts.map +1 -1
- package/dist/auth/bootstrap_account.js +115 -66
- package/dist/auth/bootstrap_route_schema.d.ts +6 -2
- package/dist/auth/bootstrap_route_schema.d.ts.map +1 -1
- package/dist/auth/bootstrap_route_schema.js +7 -2
- package/dist/auth/bootstrap_routes.d.ts +50 -33
- package/dist/auth/bootstrap_routes.d.ts.map +1 -1
- package/dist/auth/bootstrap_routes.js +109 -87
- package/dist/auth/bootstrap_token_store.d.ts +60 -0
- package/dist/auth/bootstrap_token_store.d.ts.map +1 -0
- package/dist/auth/bootstrap_token_store.js +39 -0
- package/dist/auth/credential_headers.d.ts +71 -0
- package/dist/auth/credential_headers.d.ts.map +1 -0
- package/dist/auth/credential_headers.js +100 -0
- package/dist/auth/daemon_token.d.ts +13 -1
- package/dist/auth/daemon_token.d.ts.map +1 -1
- package/dist/auth/daemon_token.js +14 -2
- package/dist/auth/daemon_token_middleware.d.ts +10 -11
- package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
- package/dist/auth/daemon_token_middleware.js +27 -29
- package/dist/auth/deps.d.ts +0 -11
- package/dist/auth/deps.d.ts.map +1 -1
- package/dist/auth/invite_queries.d.ts +18 -0
- package/dist/auth/invite_queries.d.ts.map +1 -1
- package/dist/auth/invite_queries.js +24 -0
- package/dist/auth/request_context.d.ts +26 -5
- package/dist/auth/request_context.d.ts.map +1 -1
- package/dist/auth/request_context.js +17 -10
- package/dist/auth/role_grant_offer_action_specs.d.ts +1 -1
- package/dist/auth/role_grant_offer_action_specs.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_action_specs.js +3 -2
- package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_actions.js +37 -14
- package/dist/auth/role_grant_offer_ddl.d.ts +7 -1
- package/dist/auth/role_grant_offer_ddl.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_ddl.js +9 -2
- package/dist/auth/role_grant_offer_queries.d.ts +56 -3
- package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_queries.js +93 -8
- package/dist/auth/role_grant_queries.d.ts +7 -0
- package/dist/auth/role_grant_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_queries.js +8 -0
- package/dist/auth/session_cookie.d.ts +105 -25
- package/dist/auth/session_cookie.d.ts.map +1 -1
- package/dist/auth/session_cookie.js +124 -15
- package/dist/auth/session_middleware.d.ts +83 -54
- package/dist/auth/session_middleware.d.ts.map +1 -1
- package/dist/auth/session_middleware.js +92 -66
- package/dist/auth/session_queries.d.ts +64 -4
- package/dist/auth/session_queries.d.ts.map +1 -1
- package/dist/auth/session_queries.js +53 -4
- package/dist/auth/signup_route_schema.d.ts +5 -5
- package/dist/auth/signup_route_schema.d.ts.map +1 -1
- package/dist/auth/signup_route_schema.js +4 -4
- package/dist/auth/signup_routes.d.ts.map +1 -1
- package/dist/auth/signup_routes.js +17 -14
- package/dist/auth/token_scope.d.ts +5 -7
- package/dist/auth/token_scope.d.ts.map +1 -1
- package/dist/auth/token_scope.js +5 -8
- package/dist/dev/setup.d.ts +6 -1
- package/dist/dev/setup.d.ts.map +1 -1
- package/dist/dev/setup.js +42 -34
- package/dist/hono_context.d.ts +21 -0
- package/dist/hono_context.d.ts.map +1 -1
- package/dist/hono_context.js +17 -0
- package/dist/http/CLAUDE.md +150 -43
- package/dist/http/auth_shape.d.ts +3 -3
- package/dist/http/common_routes.js +1 -1
- package/dist/http/db_routes.d.ts +4 -3
- package/dist/http/db_routes.d.ts.map +1 -1
- package/dist/http/db_routes.js +14 -14
- package/dist/http/dev_route_error_check.d.ts +6 -3
- package/dist/http/dev_route_error_check.d.ts.map +1 -1
- package/dist/http/dev_route_error_check.js +6 -3
- package/dist/http/dev_set_cookie_check.d.ts +53 -0
- package/dist/http/dev_set_cookie_check.d.ts.map +1 -0
- package/dist/http/dev_set_cookie_check.js +80 -0
- package/dist/http/error_schemas.d.ts +36 -1
- package/dist/http/error_schemas.d.ts.map +1 -1
- package/dist/http/error_schemas.js +39 -2
- package/dist/http/header_lines.d.ts +42 -0
- package/dist/http/header_lines.d.ts.map +1 -0
- package/dist/http/header_lines.js +80 -0
- package/dist/http/host.d.ts +12 -9
- package/dist/http/host.d.ts.map +1 -1
- package/dist/http/host.js +25 -20
- package/dist/http/origin.d.ts +7 -22
- package/dist/http/origin.d.ts.map +1 -1
- package/dist/http/origin.js +11 -25
- package/dist/http/proxy.d.ts +1 -0
- package/dist/http/proxy.d.ts.map +1 -1
- package/dist/http/proxy.js +3 -0
- package/dist/http/request_headers.d.ts +95 -0
- package/dist/http/request_headers.d.ts.map +1 -0
- package/dist/http/request_headers.js +110 -0
- package/dist/http/request_target.d.ts +134 -0
- package/dist/http/request_target.d.ts.map +1 -0
- package/dist/http/request_target.js +193 -0
- package/dist/http/route_error_check.d.ts +4 -11
- package/dist/http/route_error_check.d.ts.map +1 -1
- package/dist/http/route_error_check.js +4 -21
- package/dist/http/route_result.d.ts +127 -23
- package/dist/http/route_result.d.ts.map +1 -1
- package/dist/http/route_result.js +97 -19
- package/dist/http/route_spec.d.ts +298 -82
- package/dist/http/route_spec.d.ts.map +1 -1
- package/dist/http/route_spec.js +548 -71
- package/dist/http/simple_request.d.ts +19 -14
- package/dist/http/simple_request.d.ts.map +1 -1
- package/dist/http/simple_request.js +17 -29
- package/dist/http/surface.d.ts +2 -0
- package/dist/http/surface.d.ts.map +1 -1
- package/dist/http/surface.js +4 -1
- package/dist/realtime/outbound_budget.d.ts +1 -2
- package/dist/realtime/outbound_budget.d.ts.map +1 -1
- package/dist/realtime/outbound_budget.js +1 -2
- package/dist/realtime/sse.d.ts +47 -17
- package/dist/realtime/sse.d.ts.map +1 -1
- package/dist/realtime/sse.js +115 -93
- package/dist/realtime/sse_constants.d.ts +7 -1
- package/dist/realtime/sse_constants.d.ts.map +1 -1
- package/dist/realtime/sse_constants.js +12 -1
- package/dist/realtime/sse_registry.d.ts +3 -3
- package/dist/realtime/sse_registry.js +3 -3
- package/dist/runtime/deps.d.ts +20 -4
- package/dist/runtime/deps.d.ts.map +1 -1
- package/dist/runtime/mock.d.ts +7 -1
- package/dist/runtime/mock.d.ts.map +1 -1
- package/dist/runtime/mock.js +33 -3
- package/dist/runtime/node.d.ts.map +1 -1
- package/dist/runtime/node.js +2 -1
- package/dist/runtime/secure_file.d.ts +71 -10
- package/dist/runtime/secure_file.d.ts.map +1 -1
- package/dist/runtime/secure_file.js +91 -11
- package/dist/server/app_backend.d.ts +0 -8
- package/dist/server/app_backend.d.ts.map +1 -1
- package/dist/server/app_backend.js +1 -3
- package/dist/server/app_server.d.ts +28 -17
- package/dist/server/app_server.d.ts.map +1 -1
- package/dist/server/app_server.js +52 -34
- package/dist/server/serve_fact_route.d.ts.map +1 -1
- package/dist/server/serve_fact_route.js +49 -45
- package/dist/server/static.d.ts +20 -0
- package/dist/server/static.d.ts.map +1 -1
- package/dist/server/static.js +56 -8
- package/dist/server/unmatched_route.d.ts +42 -0
- package/dist/server/unmatched_route.d.ts.map +1 -0
- package/dist/server/unmatched_route.js +64 -0
- package/dist/testing/CLAUDE.md +404 -1200
- package/dist/testing/app_server.d.ts +3 -1
- package/dist/testing/app_server.d.ts.map +1 -1
- package/dist/testing/app_server.js +4 -10
- package/dist/testing/auth_apps.d.ts.map +1 -1
- package/dist/testing/auth_apps.js +2 -1
- package/dist/testing/cross_backend/account_lifecycle.d.ts +11 -4
- package/dist/testing/cross_backend/account_lifecycle.d.ts.map +1 -1
- package/dist/testing/cross_backend/account_lifecycle.js +277 -6
- package/dist/testing/cross_backend/build_test_backend_paths.d.ts +4 -1
- package/dist/testing/cross_backend/build_test_backend_paths.d.ts.map +1 -1
- package/dist/testing/cross_backend/build_test_backend_paths.js +1 -1
- package/dist/testing/cross_backend/capabilities.d.ts +68 -5
- package/dist/testing/cross_backend/capabilities.d.ts.map +1 -1
- package/dist/testing/cross_backend/capabilities.js +20 -4
- package/dist/testing/cross_backend/cell_gated_create.js +1 -1
- package/dist/testing/cross_backend/conformance_case.d.ts +63 -21
- package/dist/testing/cross_backend/conformance_case.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_table.d.ts +54 -12
- package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_table.js +179 -23
- package/dist/testing/cross_backend/cookie_attributes.js +1 -1
- package/dist/testing/cross_backend/create_dual_spawn_global_setup.d.ts +7 -1
- package/dist/testing/cross_backend/create_dual_spawn_global_setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/create_dual_spawn_global_setup.js +3 -3
- package/dist/testing/cross_backend/credential_conformance.d.ts +196 -0
- package/dist/testing/cross_backend/credential_conformance.d.ts.map +1 -0
- package/dist/testing/cross_backend/credential_conformance.js +296 -0
- package/dist/testing/cross_backend/credential_conformance.json +1284 -0
- package/dist/testing/cross_backend/credential_conformance_wire.d.ts +40 -0
- package/dist/testing/cross_backend/credential_conformance_wire.d.ts.map +1 -0
- package/dist/testing/cross_backend/credential_conformance_wire.js +293 -0
- package/dist/testing/cross_backend/credential_header_robustness.d.ts +1 -3
- package/dist/testing/cross_backend/credential_header_robustness.d.ts.map +1 -1
- package/dist/testing/cross_backend/credential_header_robustness.js +24 -55
- package/dist/testing/cross_backend/credential_wire.d.ts +112 -0
- package/dist/testing/cross_backend/credential_wire.d.ts.map +1 -0
- package/dist/testing/cross_backend/credential_wire.js +188 -0
- package/dist/testing/cross_backend/default_backend_configs.d.ts.map +1 -1
- package/dist/testing/cross_backend/default_backend_configs.js +22 -2
- package/dist/testing/cross_backend/default_spine_surface.js +1 -1
- package/dist/testing/cross_backend/differential.d.ts +1 -1
- package/dist/testing/cross_backend/differential.d.ts.map +1 -1
- package/dist/testing/cross_backend/differential.js +3 -2
- package/dist/testing/cross_backend/differential_normalize.d.ts +23 -6
- package/dist/testing/cross_backend/differential_normalize.d.ts.map +1 -1
- package/dist/testing/cross_backend/differential_normalize.js +11 -5
- package/dist/testing/cross_backend/full_spine_mount.d.ts +1 -0
- package/dist/testing/cross_backend/full_spine_mount.d.ts.map +1 -1
- package/dist/testing/cross_backend/full_spine_mount.js +7 -0
- package/dist/testing/cross_backend/identity_parity.d.ts.map +1 -1
- package/dist/testing/cross_backend/identity_parity.js +4 -0
- package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/in_process_setup.js +78 -4
- package/dist/testing/cross_backend/login_security.d.ts.map +1 -1
- package/dist/testing/cross_backend/login_security.js +13 -10
- package/dist/testing/cross_backend/peer_ping_ws.d.ts +1 -1
- package/dist/testing/cross_backend/peer_ping_ws.js +2 -2
- package/dist/testing/cross_backend/request_header_conformance.d.ts +174 -0
- package/dist/testing/cross_backend/request_header_conformance.d.ts.map +1 -0
- package/dist/testing/cross_backend/request_header_conformance.js +196 -0
- package/dist/testing/cross_backend/request_header_conformance.json +1158 -0
- package/dist/testing/cross_backend/request_header_conformance_wire.d.ts +39 -0
- package/dist/testing/cross_backend/request_header_conformance_wire.d.ts.map +1 -0
- package/dist/testing/cross_backend/request_header_conformance_wire.js +284 -0
- package/dist/testing/cross_backend/request_target_conformance.d.ts +298 -0
- package/dist/testing/cross_backend/request_target_conformance.d.ts.map +1 -0
- package/dist/testing/cross_backend/request_target_conformance.js +186 -0
- package/dist/testing/cross_backend/request_target_conformance.json +3765 -0
- package/dist/testing/cross_backend/request_target_conformance_wire.d.ts +32 -0
- package/dist/testing/cross_backend/request_target_conformance_wire.d.ts.map +1 -0
- package/dist/testing/cross_backend/request_target_conformance_wire.js +278 -0
- package/dist/testing/cross_backend/role_grant_offer_lifecycle.d.ts.map +1 -1
- package/dist/testing/cross_backend/role_grant_offer_lifecycle.js +173 -1
- package/dist/testing/cross_backend/role_grant_offer_notification_ws.d.ts.map +1 -1
- package/dist/testing/cross_backend/role_grant_offer_notification_ws.js +2 -1
- package/dist/testing/cross_backend/rpc_adversarial.d.ts +6 -4
- package/dist/testing/cross_backend/rpc_adversarial.d.ts.map +1 -1
- package/dist/testing/cross_backend/rpc_adversarial.js +5 -2
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts +6 -7
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
- package/dist/testing/cross_backend/rust_spine_consumer_surface.js +4 -5
- package/dist/testing/cross_backend/session_cap.d.ts.map +1 -1
- package/dist/testing/cross_backend/session_cap.js +56 -29
- package/dist/testing/cross_backend/session_cookie_effect.d.ts +43 -0
- package/dist/testing/cross_backend/session_cookie_effect.d.ts.map +1 -0
- package/dist/testing/cross_backend/session_cookie_effect.js +103 -0
- package/dist/testing/cross_backend/session_login.d.ts +24 -0
- package/dist/testing/cross_backend/session_login.d.ts.map +1 -0
- package/dist/testing/cross_backend/session_login.js +31 -0
- package/dist/testing/cross_backend/setup.d.ts +117 -0
- package/dist/testing/cross_backend/setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/setup.js +193 -9
- package/dist/testing/cross_backend/simple_request.d.ts.map +1 -1
- package/dist/testing/cross_backend/simple_request.js +5 -0
- package/dist/testing/cross_backend/spine_suites.d.ts +9 -1
- package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
- package/dist/testing/cross_backend/spine_suites.js +88 -5
- 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 +8 -5
- package/dist/testing/cross_backend/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/cross_backend/sse_round_trip.js +205 -64
- package/dist/testing/cross_backend/testing_backdoor.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_backdoor.js +5 -2
- package/dist/testing/cross_backend/testing_credential_read.d.ts +165 -0
- package/dist/testing/cross_backend/testing_credential_read.d.ts.map +1 -0
- package/dist/testing/cross_backend/testing_credential_read.js +175 -0
- package/dist/testing/cross_backend/testing_reset_actions.d.ts +19 -0
- package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_reset_actions.js +22 -6
- package/dist/testing/cross_backend/token_lifetime.d.ts.map +1 -1
- package/dist/testing/cross_backend/token_lifetime.js +58 -2
- package/dist/testing/cross_backend/transport_composition.d.ts +2 -4
- package/dist/testing/cross_backend/transport_composition.d.ts.map +1 -1
- package/dist/testing/cross_backend/transport_composition.js +13 -10
- package/dist/testing/cross_backend/ts_spine_backend_config.d.ts.map +1 -1
- package/dist/testing/cross_backend/ts_spine_backend_config.js +5 -3
- package/dist/testing/cross_backend/ws_endpoint.d.ts +11 -1
- package/dist/testing/cross_backend/ws_endpoint.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_endpoint.js +19 -2
- package/dist/testing/cross_backend/ws_role_gated.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_role_gated.js +2 -3
- package/dist/testing/cross_backend/ws_round_trip.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_round_trip.js +28 -12
- package/dist/testing/cross_backend/xfail.d.ts +44 -11
- package/dist/testing/cross_backend/xfail.d.ts.map +1 -1
- package/dist/testing/cross_backend/xfail.js +68 -23
- package/dist/testing/data_exposure.d.ts.map +1 -1
- package/dist/testing/data_exposure.js +4 -3
- package/dist/testing/integration.d.ts +1 -2
- package/dist/testing/integration.d.ts.map +1 -1
- package/dist/testing/integration.js +14 -8
- package/dist/testing/integration_helpers.d.ts +50 -3
- package/dist/testing/integration_helpers.d.ts.map +1 -1
- package/dist/testing/integration_helpers.js +87 -9
- package/dist/testing/middleware.d.ts +2 -0
- package/dist/testing/middleware.d.ts.map +1 -1
- package/dist/testing/middleware.js +9 -2
- package/dist/testing/round_trip.d.ts +6 -2
- package/dist/testing/round_trip.d.ts.map +1 -1
- package/dist/testing/round_trip.js +17 -6
- package/dist/testing/rpc_envelope_cases.d.ts.map +1 -1
- package/dist/testing/rpc_envelope_cases.js +7 -0
- package/dist/testing/rpc_helpers.d.ts +4 -2
- package/dist/testing/rpc_helpers.d.ts.map +1 -1
- package/dist/testing/rpc_helpers.js +6 -1
- package/dist/testing/rpc_round_trip.d.ts +13 -2
- package/dist/testing/rpc_round_trip.d.ts.map +1 -1
- package/dist/testing/rpc_round_trip.js +25 -6
- package/dist/testing/schema_generators.d.ts +2 -2
- package/dist/testing/schema_generators.d.ts.map +1 -1
- package/dist/testing/schema_generators.js +4 -4
- package/dist/testing/stubs.d.ts +2 -2
- package/dist/testing/stubs.d.ts.map +1 -1
- package/dist/testing/stubs.js +8 -8
- package/dist/testing/transports/fetch_transport.d.ts +6 -3
- package/dist/testing/transports/fetch_transport.d.ts.map +1 -1
- package/dist/testing/transports/fetch_transport.js +31 -19
- package/dist/testing/transports/raw_http.d.ts +61 -1
- package/dist/testing/transports/raw_http.d.ts.map +1 -1
- package/dist/testing/transports/raw_http.js +61 -1
- package/dist/testing/transports/ws_raw_client.d.ts +20 -0
- package/dist/testing/transports/ws_raw_client.d.ts.map +1 -1
- package/dist/testing/transports/ws_raw_client.js +10 -4
- package/dist/testing/transports/ws_transport.d.ts +21 -1
- package/dist/testing/transports/ws_transport.d.ts.map +1 -1
- package/dist/testing/transports/ws_transport.js +58 -20
- package/package.json +1 -1
|
@@ -25,34 +25,137 @@ const EXPIRES_AT_INTEGER_RE = /^\d+$/;
|
|
|
25
25
|
/** The largest `expires_at` the Rust spine's `u64` parse accepts. */
|
|
26
26
|
const EXPIRES_AT_MAX = 18446744073709551615n;
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
28
|
+
* The attributes every session `Set-Cookie` carries, in the order written —
|
|
29
|
+
* the Rust spine's `SESSION_COOKIE_ATTRIBUTES`, byte for byte. Fixed: the
|
|
30
|
+
* spine writes one cookie.
|
|
29
31
|
*
|
|
30
|
-
*
|
|
31
|
-
* - `
|
|
32
|
-
* - `
|
|
33
|
-
* - `
|
|
32
|
+
* - `Path=/` - sent to every path of the origin
|
|
33
|
+
* - `HttpOnly` - out of reach of page script
|
|
34
|
+
* - `Secure` - HTTPS only (Chrome and Firefox treat `localhost` as secure)
|
|
35
|
+
* - `SameSite=Strict` - never sent on a cross-site request
|
|
34
36
|
*/
|
|
35
|
-
export const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
export const SESSION_COOKIE_ATTRIBUTES = 'Path=/; HttpOnly; Secure; SameSite=Strict';
|
|
38
|
+
/** RFC 6265's `cookie-name`: an RFC 2616 `token`, one or more characters. */
|
|
39
|
+
const COOKIE_NAME_REGEX = /^[!#$%&'*+\-.0-9A-Z^_`a-z|~]+$/;
|
|
40
|
+
/** RFC 6265's unquoted `cookie-value`: zero or more `cookie-octet`s. */
|
|
41
|
+
const COOKIE_VALUE_REGEX = /^[\x21\x23-\x2B\x2D-\x3A\x3C-\x5B\x5D-\x7E]*$/;
|
|
42
|
+
/**
|
|
43
|
+
* Whether `name` is an RFC 6265 `cookie-name` — an HTTP `token`: visible
|
|
44
|
+
* ASCII less the separators (`=`, `;`, `,`, space, quotes, brackets and the
|
|
45
|
+
* rest). Twin of the Rust spine's `is_cookie_name`.
|
|
46
|
+
*
|
|
47
|
+
* Anything but a string is refused, whatever its type says: the name is a
|
|
48
|
+
* consumer's option, and a regex alone would read `undefined` as the text
|
|
49
|
+
* `undefined`.
|
|
50
|
+
*
|
|
51
|
+
* @param name - a cookie name
|
|
52
|
+
*/
|
|
53
|
+
export const is_cookie_name = (name) => typeof name === 'string' && COOKIE_NAME_REGEX.test(name);
|
|
54
|
+
/**
|
|
55
|
+
* Whether `value` is an RFC 6265 `cookie-value` in its unquoted form — only
|
|
56
|
+
* `cookie-octet`s: visible ASCII less `"`, `,`, `;` and `\`. Such a value
|
|
57
|
+
* reads back out of a `Cookie` header exactly as it was written, which is
|
|
58
|
+
* what a reader that decodes nothing needs. Twin of the Rust spine's
|
|
59
|
+
* `is_cookie_value`.
|
|
60
|
+
*
|
|
61
|
+
* Anything but a string is refused, whatever its type says: the value comes
|
|
62
|
+
* out of a consumer's `encode_identity` and keyring, and a regex alone would
|
|
63
|
+
* read `undefined` as the text `undefined`.
|
|
64
|
+
*
|
|
65
|
+
* @param value - a cookie value
|
|
66
|
+
*/
|
|
67
|
+
export const is_cookie_value = (value) => typeof value === 'string' && COOKIE_VALUE_REGEX.test(value);
|
|
68
|
+
/**
|
|
69
|
+
* Refuse a session cookie name the `Cookie` grammar cannot carry.
|
|
70
|
+
*
|
|
71
|
+
* @param cookie_name - the session cookie's name
|
|
72
|
+
* @throws Error when `cookie_name` is not an RFC 6265 `cookie-name`
|
|
73
|
+
*/
|
|
74
|
+
const assert_cookie_name = (cookie_name) => {
|
|
75
|
+
if (!is_cookie_name(cookie_name)) {
|
|
76
|
+
throw new Error(`session cookie name ${JSON.stringify(cookie_name)} is not an RFC 6265 cookie-name`);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Build the `Set-Cookie` header value that sets the session cookie:
|
|
81
|
+
* `<name>=<value>; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=<max_age>`,
|
|
82
|
+
* the Rust spine's string. The value is written as given — never
|
|
83
|
+
* percent-encoded or quoted — so the cookie either spine mints verifies on
|
|
84
|
+
* both.
|
|
85
|
+
*
|
|
86
|
+
* @param cookie_name - the session cookie's name
|
|
87
|
+
* @param value - the signed cookie value (`create_session_cookie_value`)
|
|
88
|
+
* @param max_age - the cookie's lifetime in seconds
|
|
89
|
+
* @returns the `Set-Cookie` header value
|
|
90
|
+
* @throws Error when the name is not an RFC 6265 `cookie-name`, the value holds anything but `cookie-octet`s (an `encode_identity` that emits a space, a `;`, or a non-ASCII character), or `max_age` is not a non-negative safe integer — a header that would read back differently is never written
|
|
91
|
+
*/
|
|
92
|
+
export const format_session_set_cookie = (cookie_name, value, max_age) => {
|
|
93
|
+
assert_cookie_name(cookie_name);
|
|
94
|
+
if (!is_cookie_value(value)) {
|
|
95
|
+
// the value is a credential: say what is wrong with it, never what it is
|
|
96
|
+
throw new Error(`session cookie '${cookie_name}': the signed value holds a character outside RFC 6265's ` +
|
|
97
|
+
'cookie-octets — `encode_identity` must emit only visible ASCII without `"`, `,`, `;` or `\\`');
|
|
98
|
+
}
|
|
99
|
+
if (!Number.isSafeInteger(max_age) || max_age < 0) {
|
|
100
|
+
throw new Error(`session cookie '${cookie_name}': max_age ${max_age} is not a whole number of seconds`);
|
|
101
|
+
}
|
|
102
|
+
return `${cookie_name}=${value}; ${SESSION_COOKIE_ATTRIBUTES}; Max-Age=${max_age}`;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Build the `Set-Cookie` header value that clears the session cookie:
|
|
106
|
+
* `<name>=; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=0`, the Rust
|
|
107
|
+
* spine's string.
|
|
108
|
+
*
|
|
109
|
+
* @param cookie_name - the session cookie's name
|
|
110
|
+
* @returns the `Set-Cookie` header value
|
|
111
|
+
* @throws Error when the name is not an RFC 6265 `cookie-name`
|
|
112
|
+
*/
|
|
113
|
+
export const format_session_clear_cookie = (cookie_name) => {
|
|
114
|
+
assert_cookie_name(cookie_name);
|
|
115
|
+
return `${cookie_name}=; ${SESSION_COOKIE_ATTRIBUTES}; Max-Age=0`;
|
|
41
116
|
};
|
|
117
|
+
/**
|
|
118
|
+
* The `Set-Cookie` value that sets the session cookie to `value`, a signed
|
|
119
|
+
* cookie value (`create_session_cookie_value`, or the `cookie_value` of
|
|
120
|
+
* `create_capped_session`) — what a success carries
|
|
121
|
+
* (`route_ok(value, {set_cookie: [...]})`). `options.max_age` sets `Max-Age`,
|
|
122
|
+
* as it set the value's embedded expiry; `SESSION_AGE_MAX` when unset. Twin of
|
|
123
|
+
* the Rust `session_cookie_header`, which signs the token itself.
|
|
124
|
+
*
|
|
125
|
+
* @param value - the signed cookie value
|
|
126
|
+
* @param options - the cookie name and lifetime
|
|
127
|
+
* @returns the `Set-Cookie` header value (`format_session_set_cookie`)
|
|
128
|
+
* @throws Error when the cookie name or the value is outside the RFC 6265 grammar
|
|
129
|
+
*/
|
|
130
|
+
export const session_cookie_header = (value, options) => format_session_set_cookie(options.cookie_name, value, options.max_age ?? SESSION_AGE_MAX);
|
|
131
|
+
/**
|
|
132
|
+
* The `Set-Cookie` value that clears the session cookie — what a logout or a
|
|
133
|
+
* password change carries on its success. Twin of the Rust
|
|
134
|
+
* `clear_session_cookie_header`.
|
|
135
|
+
*
|
|
136
|
+
* @param options - the cookie name
|
|
137
|
+
* @returns the `Set-Cookie` header value (`format_session_clear_cookie`)
|
|
138
|
+
* @throws Error when the cookie name is outside the RFC 6265 grammar
|
|
139
|
+
*/
|
|
140
|
+
export const clear_session_cookie_header = (options) => format_session_clear_cookie(options.cookie_name);
|
|
42
141
|
/**
|
|
43
142
|
* Parse a signed session cookie value.
|
|
44
143
|
*
|
|
45
144
|
* The signed value format is `${encode(identity)}:${expires_at}`.
|
|
46
145
|
* Tries all keys in order to support key rotation.
|
|
47
146
|
*
|
|
48
|
-
*
|
|
147
|
+
* An empty string is a cookie that was sent with no value (`name=`): present
|
|
148
|
+
* and invalid, like any other value that fails verification. Only a nullish
|
|
149
|
+
* `signed_value` is "no cookie".
|
|
150
|
+
*
|
|
151
|
+
* @param signed_value - the raw cookie value (signed), nullish when the request carries no session cookie
|
|
49
152
|
* @param keyring - key ring for verification
|
|
50
153
|
* @param options - session configuration with decode logic
|
|
51
154
|
* @param now_seconds - current time in seconds (for testing)
|
|
52
|
-
* @returns `ParsedSession` if valid, null if invalid/expired, undefined if
|
|
155
|
+
* @returns `ParsedSession` if valid, null if invalid/expired (the empty string included), undefined if missing
|
|
53
156
|
*/
|
|
54
157
|
export const parse_session = async (signed_value, keyring, options, now_seconds) => {
|
|
55
|
-
if (
|
|
158
|
+
if (signed_value == null)
|
|
56
159
|
return undefined;
|
|
57
160
|
const result = await keyring.verify(signed_value);
|
|
58
161
|
if (!result)
|
|
@@ -133,7 +236,13 @@ export const fuz_session_config = create_session_config('fuz_session');
|
|
|
133
236
|
* retired keys are safe to drop after `SESSION_AGE_MAX` (see
|
|
134
237
|
* `docs/security.md` §Cookie Key Rotation).
|
|
135
238
|
*
|
|
136
|
-
*
|
|
239
|
+
* The three outcomes are what the cookie alone shows: no cookie (`action:
|
|
240
|
+
* 'none'`), a cookie that fails verification — unreadable, a bad MAC, a signed
|
|
241
|
+
* expiry that has passed, an empty identity, an empty value — (`action:
|
|
242
|
+
* 'clear'`), and a valid one. A valid cookie whose `auth_session` row is gone
|
|
243
|
+
* is still valid here; nothing clears it.
|
|
244
|
+
*
|
|
245
|
+
* @param signed_value - the raw cookie value, nullish when the request carries no session cookie
|
|
137
246
|
* @param keyring - key ring for verification and signing
|
|
138
247
|
* @param options - session configuration
|
|
139
248
|
* @param now_seconds - current time in seconds (for testing)
|
|
@@ -1,32 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Hono session boundary — cookie
|
|
3
|
-
*
|
|
2
|
+
* Hono session boundary — the session cookie read off a request, and the
|
|
3
|
+
* request-time middleware that resolves it and clears a stale one.
|
|
4
|
+
*
|
|
5
|
+
* The cookie is read from the request's `Cookie` lines by
|
|
6
|
+
* `read_session_cookie_value` and written as the exact `Set-Cookie` strings of
|
|
7
|
+
* `auth/session_cookie.ts` — no framework cookie parser or serializer sits on
|
|
8
|
+
* the credential path, so nothing is percent-decoded on the way in or
|
|
9
|
+
* percent-encoded on the way out. A route sets or clears the cookie by
|
|
10
|
+
* returning the line on its success (`route_ok(value, {set_cookie})`, the
|
|
11
|
+
* lines from `session_cookie_header` and `clear_session_cookie_header`), never
|
|
12
|
+
* by writing on the context.
|
|
4
13
|
*
|
|
5
14
|
* @module
|
|
6
15
|
*/
|
|
7
16
|
import type { Context, MiddlewareHandler } from 'hono';
|
|
8
17
|
import type { Keyring } from './keyring.js';
|
|
9
18
|
import { type SessionOptions } from './session_cookie.js';
|
|
10
|
-
import type { QueryDeps } from '../db/query_deps.js';
|
|
11
|
-
/**
|
|
12
|
-
* Read the session cookie value from a request.
|
|
13
|
-
*/
|
|
14
|
-
export declare const get_session_cookie: <T>(c: Context, options: SessionOptions<T>) => string | undefined;
|
|
15
19
|
/**
|
|
16
|
-
*
|
|
20
|
+
* Read the session cookie's value from a request, as sent
|
|
21
|
+
* (`read_session_cookie_value` over the request's `Cookie` lines).
|
|
17
22
|
*
|
|
18
|
-
* `
|
|
19
|
-
* drives both the embedded `expires_at` (via `create_session_cookie_value`)
|
|
20
|
-
* and the cookie's HTTP `Max-Age` attribute set here. Falls back to
|
|
21
|
-
* `session_cookie_options.maxAge` (= `SESSION_AGE_MAX`) when unset.
|
|
22
|
-
* `options.cookie_options` cannot carry `maxAge` (omitted in the type) so
|
|
23
|
-
* the two values can't drift.
|
|
24
|
-
*/
|
|
25
|
-
export declare const set_session_cookie: <T>(c: Context, value: string, options: SessionOptions<T>) => void;
|
|
26
|
-
/**
|
|
27
|
-
* Clear the session cookie on a response.
|
|
23
|
+
* @returns the value — `''` for a cookie sent with none — or `null` when the request carries no session cookie
|
|
28
24
|
*/
|
|
29
|
-
export declare const
|
|
25
|
+
export declare const get_session_cookie: <T>(c: Context, options: SessionOptions<T>) => string | null;
|
|
30
26
|
/**
|
|
31
27
|
* Create session middleware that parses cookies and sets the session token on
|
|
32
28
|
* context.
|
|
@@ -36,43 +32,76 @@ export declare const clear_session_cookie: <T>(c: Context, options: SessionOptio
|
|
|
36
32
|
* reads. The identity is the session token, so the options are a
|
|
37
33
|
* `SessionOptions<string>`.
|
|
38
34
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
*
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
*
|
|
35
|
+
* A cookie that is present and fails verification is cleared — an empty value
|
|
36
|
+
* (`name=`) included; a request with no session cookie clears nothing. The
|
|
37
|
+
* clear is a `Set-Cookie` line put on the context's headers before the
|
|
38
|
+
* handler runs, whichever credential goes on to authenticate the request, and
|
|
39
|
+
* every response built through the context carries it once, ahead of any
|
|
40
|
+
* other `Set-Cookie`:
|
|
41
|
+
*
|
|
42
|
+
* - **Every response a route spec answers** — a success, a failure, a raw
|
|
43
|
+
* answer of any body, an SSE stream — since `apply_route_specs` builds each
|
|
44
|
+
* through the context (`emit_route_response`) and a handler, which receives
|
|
45
|
+
* a `RouteContext` and never the Hono context, can neither return a
|
|
46
|
+
* `Response` of its own nor write a header on the one built. A success's own lines follow the clear: a login
|
|
47
|
+
* carrying a stale cookie answers the clear, then the new cookie, and the
|
|
48
|
+
* browser keeps the new one. A logout or password change clears a cookie
|
|
49
|
+
* that verified, which this middleware leaves alone, so its response
|
|
50
|
+
* carries one clear.
|
|
51
|
+
* - **Every refusal of the middleware behind this one** — the auth gates, the
|
|
52
|
+
* input checks, the error catch's 500, the not-found handler's answer, the
|
|
53
|
+
* error handler's (a thrown `HTTPException`'s own response is re-issued
|
|
54
|
+
* through the context), a refused WebSocket upgrade.
|
|
55
|
+
*
|
|
56
|
+
* What carries none is what is built outside the context: a response a
|
|
57
|
+
* consumer's own middleware (a `transform_middleware` layer, a
|
|
58
|
+
* `post_route_middleware`) or a raw Hono route builds by hand —
|
|
59
|
+
* `new Response(...)`, `Response.redirect(...)`, a fetched response passed
|
|
60
|
+
* through — and the placeholder a runtime adapter answers an accepted
|
|
61
|
+
* WebSocket upgrade with — unless a layer read `c.res` before it answered,
|
|
62
|
+
* when Hono rebuilds such a response over the context's own, the context's
|
|
63
|
+
* `Set-Cookie` lines in place of its. Where a response carries none, the
|
|
64
|
+
* stale cookie stays until the next response under the same scope that does.
|
|
65
|
+
* The clear is recorded on the context (`EXPECTED_FIRST_SET_COOKIE_KEY`), and
|
|
66
|
+
* in DEV a response that does not lead with it is logged
|
|
67
|
+
* (`create_dev_set_cookie_check`) — all but an accepted upgrade's
|
|
68
|
+
* placeholder, which the check knows by its shape, a bodiless `200` to an
|
|
69
|
+
* `Upgrade: websocket` request, since no adapter hands Hono a `101`.
|
|
70
|
+
*
|
|
71
|
+
* The middleware never reads, changes, or rebuilds a response it did not
|
|
72
|
+
* build, because none of that is neutral. A handler may return one object to
|
|
73
|
+
* every request: a line written onto it is sent to every later caller, and a
|
|
74
|
+
* rebuild takes its body, so on `@hono/node-server` the next request for it
|
|
75
|
+
* without a stale cookie fails. Reading has effects of its own: on that
|
|
76
|
+
* adapter reading `res.headers` alone changes the header lines it writes, a
|
|
77
|
+
* response rebuilt around a body is sent chunked in place of its
|
|
78
|
+
* `Content-Length`, and a bodiless status the handler gave an empty body is
|
|
79
|
+
* refused; on Bun, reading a string body stops its `Content-Type` being
|
|
80
|
+
* derived. A stale cookie would change what a route answers.
|
|
63
81
|
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* and
|
|
82
|
+
* A line on the context's headers is neutral in what a client reads, not byte
|
|
83
|
+
* for byte: with it, `@hono/node-server` can write a response's header names
|
|
84
|
+
* in another case and order, and Bun spells a bare `c.text`'s `Content-Type`
|
|
85
|
+
* with a space. The status, the framing, the set of headers and the body are
|
|
86
|
+
* the same.
|
|
67
87
|
*
|
|
68
|
-
* The
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
* created in the same transaction (signup, bootstrap) evicts nothing.
|
|
88
|
+
* The Rust spine's clear is a response layer: it reaches every response but
|
|
89
|
+
* an accepted upgrade's `101`, ahead of whatever `Set-Cookie` lines the
|
|
90
|
+
* handler wrote. So the two spines differ only on responses built outside the
|
|
91
|
+
* context above — none of which a spine route answers with.
|
|
73
92
|
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
93
|
+
* The middleware runs where it is mounted — `AUTH_MIDDLEWARE_PATH` in the
|
|
94
|
+
* assembled server — so the clear's scope is the router's reading of the
|
|
95
|
+
* path: raw, nothing percent-decoded (`get_request_path`), as the Rust
|
|
96
|
+
* spine's clear reads it, so `/%61pi/x` is cleared on neither. Dot segments
|
|
97
|
+
* are the one difference, and it is the runtime's: Node and Bun resolve them
|
|
98
|
+
* before the app sees the request, so `/./api/x` is cleared here and not
|
|
99
|
+
* there, `/api/../health` there and not here — each spine clears exactly
|
|
100
|
+
* where its own router puts the auth scope.
|
|
101
|
+
*
|
|
102
|
+
* @param keyring - key ring for cookie verification
|
|
103
|
+
* @param options - session configuration
|
|
104
|
+
* @mutates Hono context - sets `SESSION_TOKEN_KEY` and `SESSION_COOKIE_EXPIRES_AT_KEY`, and may put the clearing `Set-Cookie` on the context's headers, recording it under `EXPECTED_FIRST_SET_COOKIE_KEY`
|
|
76
105
|
*/
|
|
77
|
-
export declare const
|
|
106
|
+
export declare const create_session_middleware: (keyring: Keyring, options: SessionOptions<string>) => MiddlewareHandler;
|
|
78
107
|
//# sourceMappingURL=session_middleware.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session_middleware.d.ts","sourceRoot":"","sources":["../../src/lib/auth/session_middleware.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"session_middleware.d.ts","sourceRoot":"","sources":["../../src/lib/auth/session_middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAEvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,EACN,KAAK,cAAc,EAGnB,MAAM,qBAAqB,CAAC;AAQ7B;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAAI,CAAC,EAAE,GAAG,OAAO,EAAE,SAAS,cAAc,CAAC,CAAC,CAAC,KAAG,MAAM,GAAG,IACV,CAAC;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+EG;AACH,eAAO,MAAM,yBAAyB,GACrC,SAAS,OAAO,EAChB,SAAS,cAAc,CAAC,MAAM,CAAC,KAC7B,iBAoBF,CAAC"}
|
|
@@ -1,47 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Hono session boundary — cookie
|
|
3
|
-
*
|
|
2
|
+
* Hono session boundary — the session cookie read off a request, and the
|
|
3
|
+
* request-time middleware that resolves it and clears a stale one.
|
|
4
|
+
*
|
|
5
|
+
* The cookie is read from the request's `Cookie` lines by
|
|
6
|
+
* `read_session_cookie_value` and written as the exact `Set-Cookie` strings of
|
|
7
|
+
* `auth/session_cookie.ts` — no framework cookie parser or serializer sits on
|
|
8
|
+
* the credential path, so nothing is percent-decoded on the way in or
|
|
9
|
+
* percent-encoded on the way out. A route sets or clears the cookie by
|
|
10
|
+
* returning the line on its success (`route_ok(value, {set_cookie})`, the
|
|
11
|
+
* lines from `session_cookie_header` and `clear_session_cookie_header`), never
|
|
12
|
+
* by writing on the context.
|
|
4
13
|
*
|
|
5
14
|
* @module
|
|
6
15
|
*/
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
/**
|
|
12
|
-
* Read the session cookie value from a request.
|
|
13
|
-
*/
|
|
14
|
-
export const get_session_cookie = (c, options) => {
|
|
15
|
-
return getCookie(c, options.cookie_name);
|
|
16
|
-
};
|
|
16
|
+
import { read_session_cookie_value } from './credential_headers.js';
|
|
17
|
+
import { format_session_clear_cookie, process_session_cookie } from './session_cookie.js';
|
|
18
|
+
import { EXPECTED_FIRST_SET_COOKIE_KEY, SESSION_COOKIE_EXPIRES_AT_KEY, SESSION_TOKEN_KEY } from '../hono_context.js';
|
|
19
|
+
import { get_header_lines } from '../http/header_lines.js';
|
|
17
20
|
/**
|
|
18
|
-
*
|
|
21
|
+
* Read the session cookie's value from a request, as sent
|
|
22
|
+
* (`read_session_cookie_value` over the request's `Cookie` lines).
|
|
19
23
|
*
|
|
20
|
-
* `
|
|
21
|
-
* drives both the embedded `expires_at` (via `create_session_cookie_value`)
|
|
22
|
-
* and the cookie's HTTP `Max-Age` attribute set here. Falls back to
|
|
23
|
-
* `session_cookie_options.maxAge` (= `SESSION_AGE_MAX`) when unset.
|
|
24
|
-
* `options.cookie_options` cannot carry `maxAge` (omitted in the type) so
|
|
25
|
-
* the two values can't drift.
|
|
26
|
-
*/
|
|
27
|
-
export const set_session_cookie = (c, value, options) => {
|
|
28
|
-
const cookie_options = {
|
|
29
|
-
...session_cookie_options,
|
|
30
|
-
...options.cookie_options,
|
|
31
|
-
maxAge: options.max_age ?? session_cookie_options.maxAge
|
|
32
|
-
};
|
|
33
|
-
setCookie(c, options.cookie_name, value, cookie_options);
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* Clear the session cookie on a response.
|
|
24
|
+
* @returns the value — `''` for a cookie sent with none — or `null` when the request carries no session cookie
|
|
37
25
|
*/
|
|
38
|
-
export const
|
|
39
|
-
const cookie_options = {
|
|
40
|
-
...session_cookie_options,
|
|
41
|
-
...options.cookie_options
|
|
42
|
-
};
|
|
43
|
-
deleteCookie(c, options.cookie_name, cookie_options);
|
|
44
|
-
};
|
|
26
|
+
export const get_session_cookie = (c, options) => read_session_cookie_value(get_header_lines(c, 'Cookie'), options.cookie_name);
|
|
45
27
|
/**
|
|
46
28
|
* Create session middleware that parses cookies and sets the session token on
|
|
47
29
|
* context.
|
|
@@ -51,9 +33,76 @@ export const clear_session_cookie = (c, options) => {
|
|
|
51
33
|
* reads. The identity is the session token, so the options are a
|
|
52
34
|
* `SessionOptions<string>`.
|
|
53
35
|
*
|
|
36
|
+
* A cookie that is present and fails verification is cleared — an empty value
|
|
37
|
+
* (`name=`) included; a request with no session cookie clears nothing. The
|
|
38
|
+
* clear is a `Set-Cookie` line put on the context's headers before the
|
|
39
|
+
* handler runs, whichever credential goes on to authenticate the request, and
|
|
40
|
+
* every response built through the context carries it once, ahead of any
|
|
41
|
+
* other `Set-Cookie`:
|
|
42
|
+
*
|
|
43
|
+
* - **Every response a route spec answers** — a success, a failure, a raw
|
|
44
|
+
* answer of any body, an SSE stream — since `apply_route_specs` builds each
|
|
45
|
+
* through the context (`emit_route_response`) and a handler, which receives
|
|
46
|
+
* a `RouteContext` and never the Hono context, can neither return a
|
|
47
|
+
* `Response` of its own nor write a header on the one built. A success's own lines follow the clear: a login
|
|
48
|
+
* carrying a stale cookie answers the clear, then the new cookie, and the
|
|
49
|
+
* browser keeps the new one. A logout or password change clears a cookie
|
|
50
|
+
* that verified, which this middleware leaves alone, so its response
|
|
51
|
+
* carries one clear.
|
|
52
|
+
* - **Every refusal of the middleware behind this one** — the auth gates, the
|
|
53
|
+
* input checks, the error catch's 500, the not-found handler's answer, the
|
|
54
|
+
* error handler's (a thrown `HTTPException`'s own response is re-issued
|
|
55
|
+
* through the context), a refused WebSocket upgrade.
|
|
56
|
+
*
|
|
57
|
+
* What carries none is what is built outside the context: a response a
|
|
58
|
+
* consumer's own middleware (a `transform_middleware` layer, a
|
|
59
|
+
* `post_route_middleware`) or a raw Hono route builds by hand —
|
|
60
|
+
* `new Response(...)`, `Response.redirect(...)`, a fetched response passed
|
|
61
|
+
* through — and the placeholder a runtime adapter answers an accepted
|
|
62
|
+
* WebSocket upgrade with — unless a layer read `c.res` before it answered,
|
|
63
|
+
* when Hono rebuilds such a response over the context's own, the context's
|
|
64
|
+
* `Set-Cookie` lines in place of its. Where a response carries none, the
|
|
65
|
+
* stale cookie stays until the next response under the same scope that does.
|
|
66
|
+
* The clear is recorded on the context (`EXPECTED_FIRST_SET_COOKIE_KEY`), and
|
|
67
|
+
* in DEV a response that does not lead with it is logged
|
|
68
|
+
* (`create_dev_set_cookie_check`) — all but an accepted upgrade's
|
|
69
|
+
* placeholder, which the check knows by its shape, a bodiless `200` to an
|
|
70
|
+
* `Upgrade: websocket` request, since no adapter hands Hono a `101`.
|
|
71
|
+
*
|
|
72
|
+
* The middleware never reads, changes, or rebuilds a response it did not
|
|
73
|
+
* build, because none of that is neutral. A handler may return one object to
|
|
74
|
+
* every request: a line written onto it is sent to every later caller, and a
|
|
75
|
+
* rebuild takes its body, so on `@hono/node-server` the next request for it
|
|
76
|
+
* without a stale cookie fails. Reading has effects of its own: on that
|
|
77
|
+
* adapter reading `res.headers` alone changes the header lines it writes, a
|
|
78
|
+
* response rebuilt around a body is sent chunked in place of its
|
|
79
|
+
* `Content-Length`, and a bodiless status the handler gave an empty body is
|
|
80
|
+
* refused; on Bun, reading a string body stops its `Content-Type` being
|
|
81
|
+
* derived. A stale cookie would change what a route answers.
|
|
82
|
+
*
|
|
83
|
+
* A line on the context's headers is neutral in what a client reads, not byte
|
|
84
|
+
* for byte: with it, `@hono/node-server` can write a response's header names
|
|
85
|
+
* in another case and order, and Bun spells a bare `c.text`'s `Content-Type`
|
|
86
|
+
* with a space. The status, the framing, the set of headers and the body are
|
|
87
|
+
* the same.
|
|
88
|
+
*
|
|
89
|
+
* The Rust spine's clear is a response layer: it reaches every response but
|
|
90
|
+
* an accepted upgrade's `101`, ahead of whatever `Set-Cookie` lines the
|
|
91
|
+
* handler wrote. So the two spines differ only on responses built outside the
|
|
92
|
+
* context above — none of which a spine route answers with.
|
|
93
|
+
*
|
|
94
|
+
* The middleware runs where it is mounted — `AUTH_MIDDLEWARE_PATH` in the
|
|
95
|
+
* assembled server — so the clear's scope is the router's reading of the
|
|
96
|
+
* path: raw, nothing percent-decoded (`get_request_path`), as the Rust
|
|
97
|
+
* spine's clear reads it, so `/%61pi/x` is cleared on neither. Dot segments
|
|
98
|
+
* are the one difference, and it is the runtime's: Node and Bun resolve them
|
|
99
|
+
* before the app sees the request, so `/./api/x` is cleared here and not
|
|
100
|
+
* there, `/api/../health` there and not here — each spine clears exactly
|
|
101
|
+
* where its own router puts the auth scope.
|
|
102
|
+
*
|
|
54
103
|
* @param keyring - key ring for cookie verification
|
|
55
104
|
* @param options - session configuration
|
|
56
|
-
* @mutates Hono context - sets `SESSION_TOKEN_KEY` and `SESSION_COOKIE_EXPIRES_AT_KEY`, and may
|
|
105
|
+
* @mutates Hono context - sets `SESSION_TOKEN_KEY` and `SESSION_COOKIE_EXPIRES_AT_KEY`, and may put the clearing `Set-Cookie` on the context's headers, recording it under `EXPECTED_FIRST_SET_COOKIE_KEY`
|
|
57
106
|
*/
|
|
58
107
|
export const create_session_middleware = (keyring, options) => {
|
|
59
108
|
return async (c, next) => {
|
|
@@ -63,36 +112,13 @@ export const create_session_middleware = (keyring, options) => {
|
|
|
63
112
|
c.set(SESSION_TOKEN_KEY, result.identity ?? null);
|
|
64
113
|
// the signed expiry rides beside it, for the credential deadline
|
|
65
114
|
c.set(SESSION_COOKIE_EXPIRES_AT_KEY, result.expires_at ?? null);
|
|
115
|
+
// ahead of the handler, so it precedes any `Set-Cookie` a success carries;
|
|
116
|
+
// recorded, so the DEV `Set-Cookie` check can see a response that lost it
|
|
66
117
|
if (result.action === 'clear') {
|
|
67
|
-
|
|
118
|
+
const clear = format_session_clear_cookie(options.cookie_name);
|
|
119
|
+
c.header('Set-Cookie', clear, { append: true });
|
|
120
|
+
c.set(EXPECTED_FIRST_SET_COOKIE_KEY, clear);
|
|
68
121
|
}
|
|
69
122
|
await next();
|
|
70
123
|
};
|
|
71
124
|
};
|
|
72
|
-
/**
|
|
73
|
-
* Create an auth session and set the session cookie on the response.
|
|
74
|
-
*
|
|
75
|
-
* Shared by login, signup, and bootstrap — generates a token, hashes it,
|
|
76
|
-
* persists the session row, optionally enforces a per-account session limit,
|
|
77
|
-
* and sets the signed cookie.
|
|
78
|
-
*
|
|
79
|
-
* The cap deletes the sessions it evicts, but not the connections they
|
|
80
|
-
* opened. A caller that passes `max_sessions` closes the returned sessions'
|
|
81
|
-
* connections once its transaction commits — `queue_connection_close` with a
|
|
82
|
-
* `session` target, as `POST /login` does. A caller that mints for an account
|
|
83
|
-
* created in the same transaction (signup, bootstrap) evicts nothing.
|
|
84
|
-
*
|
|
85
|
-
* @returns the token hashes of the sessions the cap evicted, empty without a cap
|
|
86
|
-
* @mutates `auth_session` table - inserts the new session row (and evicts older rows when `max_sessions` is set)
|
|
87
|
-
*/
|
|
88
|
-
export const create_session_and_set_cookie = async (options) => {
|
|
89
|
-
const { keyring, deps, c, account_id, session_options, max_sessions } = options;
|
|
90
|
-
const session_token = generate_session_token();
|
|
91
|
-
const token_hash = hash_session_token(session_token);
|
|
92
|
-
const expires_at = new Date(Date.now() + AUTH_SESSION_LIFETIME_MS);
|
|
93
|
-
await query_create_session(deps, token_hash, account_id, expires_at);
|
|
94
|
-
const evicted = max_sessions != null ? await query_session_enforce_limit(deps, account_id, max_sessions) : [];
|
|
95
|
-
const cookie_value = await create_session_cookie_value(keyring, session_token, session_options);
|
|
96
|
-
set_session_cookie(c, cookie_value, session_options);
|
|
97
|
-
return evicted;
|
|
98
|
-
};
|
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
* @module
|
|
8
8
|
*/
|
|
9
9
|
import type { QueryDeps } from '../db/query_deps.js';
|
|
10
|
+
import type { Keyring } from './keyring.js';
|
|
11
|
+
import { type SessionOptions } from './session_cookie.js';
|
|
10
12
|
import type { AuthSession, SessionId } from './account_schema.js';
|
|
11
13
|
/**
|
|
12
14
|
* Session lifetime in milliseconds (30 days).
|
|
@@ -78,6 +80,26 @@ export interface ValidAuthSession extends AuthSession {
|
|
|
78
80
|
* @param token_hash - blake3 hash of the session token
|
|
79
81
|
*/
|
|
80
82
|
export declare const query_session_get_valid: (deps: QueryDeps, token_hash: string) => Promise<ValidAuthSession | undefined>;
|
|
83
|
+
/**
|
|
84
|
+
* Whether the session that authorized a credential mint still lives, read in
|
|
85
|
+
* the mint's transaction after `query_account_lock_live`.
|
|
86
|
+
*
|
|
87
|
+
* The session was resolved before the transaction, so a password change can
|
|
88
|
+
* commit in between and revoke it. The account lock orders the two — the
|
|
89
|
+
* change writes the account row before it revokes — so this read either sees
|
|
90
|
+
* the change's revoke (it committed before the lock was granted) or runs
|
|
91
|
+
* ahead of it (the change then waits on the lock, and its revoke takes what
|
|
92
|
+
* the mint wrote). The row is not locked: a plain revoke of one session
|
|
93
|
+
* touches no account row, and a token minted just before a logout outlives it
|
|
94
|
+
* anyway, so ordering against one buys nothing. Twin of the Rust
|
|
95
|
+
* `fuz_auth::query_session_is_live`.
|
|
96
|
+
*
|
|
97
|
+
* @param deps - query dependencies (must be the mint's transaction)
|
|
98
|
+
* @param id - the session's id, its token hash
|
|
99
|
+
* @param account_id - the account the session must belong to
|
|
100
|
+
* @returns `true` when the session exists, belongs to the account, and has not expired
|
|
101
|
+
*/
|
|
102
|
+
export declare const query_session_is_live: (deps: QueryDeps, id: string, account_id: string) => Promise<boolean>;
|
|
81
103
|
/**
|
|
82
104
|
* Revoke (delete) a session by its token hash, with no account scoping.
|
|
83
105
|
*
|
|
@@ -121,12 +143,11 @@ export declare const query_session_list_for_account: (deps: QueryDeps, account_i
|
|
|
121
143
|
*
|
|
122
144
|
* Race safety: this function must run inside a transaction alongside the
|
|
123
145
|
* INSERT that created the new session. All callers satisfy this requirement:
|
|
124
|
-
* - `POST /login` uses the default `transaction: true` (framework-managed
|
|
125
|
-
* transaction wrapping in `apply_route_specs`)
|
|
126
146
|
* - The `account_token_create` RPC handler runs under the dispatcher's
|
|
127
147
|
* transaction path because its spec declares `side_effects: true`
|
|
128
|
-
* - `POST /bootstrap` and `POST /signup` manage their own
|
|
129
|
-
* and pass the transaction-scoped `deps` to
|
|
148
|
+
* - `POST /login`, `POST /bootstrap` and `POST /signup` manage their own
|
|
149
|
+
* transactions and pass the transaction-scoped `deps` to
|
|
150
|
+
* `create_capped_session`
|
|
130
151
|
*
|
|
131
152
|
* The transaction makes one creator's INSERT + enforce_limit pair atomic, but it
|
|
132
153
|
* does **not** serialize concurrent creators. Under Read Committed, two
|
|
@@ -202,4 +223,43 @@ export declare const query_session_list_all_active: (deps: QueryDeps, limit?: nu
|
|
|
202
223
|
* @mutates `auth_session` table - deletes every row past `expires_at`
|
|
203
224
|
*/
|
|
204
225
|
export declare const query_session_cleanup_expired: (deps: QueryDeps) => Promise<Array<string>>;
|
|
226
|
+
/**
|
|
227
|
+
* Options for `create_capped_session`.
|
|
228
|
+
*/
|
|
229
|
+
export interface CreateCappedSessionOptions {
|
|
230
|
+
/** Keyring for cookie signing. */
|
|
231
|
+
keyring: Keyring;
|
|
232
|
+
/** Query deps (needs db for session creation). */
|
|
233
|
+
deps: QueryDeps;
|
|
234
|
+
/** The account to create a session for. */
|
|
235
|
+
account_id: string;
|
|
236
|
+
/** Session cookie configuration. */
|
|
237
|
+
session_options: SessionOptions<string>;
|
|
238
|
+
/** Per-account session cap (`null` to skip enforcement). */
|
|
239
|
+
max_sessions?: number | null;
|
|
240
|
+
}
|
|
241
|
+
/** What `create_capped_session` minted. */
|
|
242
|
+
export interface CappedSession {
|
|
243
|
+
/** The signed session cookie value, for `session_cookie_header`. */
|
|
244
|
+
cookie_value: string;
|
|
245
|
+
/** The token hashes of the sessions the cap evicted, empty without a cap. */
|
|
246
|
+
evicted: Array<string>;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Mint an auth session: generate a token, persist its hashed row, enforce
|
|
250
|
+
* the per-account cap when given one, and sign the cookie value — without
|
|
251
|
+
* touching a response, so a caller minting inside a transaction sets the
|
|
252
|
+
* cookie only once that transaction has succeeded. Twin of the Rust
|
|
253
|
+
* `fuz_auth::create_capped_session`.
|
|
254
|
+
*
|
|
255
|
+
* The cap deletes the sessions it evicts, but not the connections they
|
|
256
|
+
* opened. A caller that passes `max_sessions` closes the returned sessions'
|
|
257
|
+
* connections once its transaction commits — `queue_connection_close` with a
|
|
258
|
+
* `session` target, as `POST /login` does. A caller that mints for an account
|
|
259
|
+
* created in the same transaction (signup, bootstrap) evicts nothing.
|
|
260
|
+
*
|
|
261
|
+
* @returns the signed cookie value and the evicted sessions' token hashes
|
|
262
|
+
* @mutates `auth_session` table - inserts the new session row (and evicts older rows when `max_sessions` is set)
|
|
263
|
+
*/
|
|
264
|
+
export declare const create_capped_session: (options: CreateCappedSessionOptions) => Promise<CappedSession>;
|
|
205
265
|
//# sourceMappingURL=session_queries.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session_queries.d.ts","sourceRoot":"","sources":["../../src/lib/auth/session_queries.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"session_queries.d.ts","sourceRoot":"","sources":["../../src/lib/auth/session_queries.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAA+B,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAEvF,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAGlE;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,QAA2B,CAAC;AAEjE;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,GAAI,OAAO,MAAM,KAAG,SAElD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,QAAO,MAEzC,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,GAChC,MAAM,SAAS,EACf,YAAY,MAAM,EAClB,YAAY,MAAM,EAClB,YAAY,IAAI,KACd,OAAO,CAAC,IAAI,CAMd,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,2DAKoB,CAAC;AAQtD;;;GAGG;AACH,MAAM,WAAW,gBAAiB,SAAQ,WAAW;IACpD;;;;OAIG;IACH,aAAa,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,uBAAuB,GACnC,MAAM,SAAS,EACf,YAAY,MAAM,KAChB,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAKtC,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,qBAAqB,GACjC,MAAM,SAAS,EACf,IAAI,MAAM,EACV,YAAY,MAAM,KAChB,OAAO,CAAC,OAAO,CAMjB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,qCAAqC,GACjD,MAAM,SAAS,EACf,YAAY,MAAM,KAChB,OAAO,CAAC,IAAI,CAEd,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,gCAAgC,GAC5C,MAAM,SAAS,EACf,YAAY,MAAM,EAClB,YAAY,MAAM,KAChB,OAAO,CAAC,OAAO,CAMjB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,oCAAoC,GAChD,MAAM,SAAS,EACf,YAAY,MAAM,KAChB,OAAO,CAAC,MAAM,CAMhB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,8BAA8B,GAC1C,MAAM,SAAS,EACf,YAAY,MAAM,EAClB,cAAU,KACR,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,CAK5B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,eAAO,MAAM,2BAA2B,GACvC,MAAM,SAAS,EACf,YAAY,MAAM,EAClB,cAAc,MAAM,KAClB,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAYvB,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,6BAA6B,GACzC,MAAM,SAAS,EACf,cAAW,KACT,OAAO,CAAC,KAAK,CAAC,WAAW,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CASnD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,6BAA6B,GAAU,MAAM,SAAS,KAAG,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAK1F,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,0BAA0B;IAC1C,kCAAkC;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,kDAAkD;IAClD,IAAI,EAAE,SAAS,CAAC;IAChB,2CAA2C;IAC3C,UAAU,EAAE,MAAM,CAAC;IACnB,oCAAoC;IACpC,eAAe,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC;IACxC,4DAA4D;IAC5D,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED,2CAA2C;AAC3C,MAAM,WAAW,aAAa;IAC7B,oEAAoE;IACpE,YAAY,EAAE,MAAM,CAAC;IACrB,6EAA6E;IAC7E,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CACvB;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,qBAAqB,GACjC,SAAS,0BAA0B,KACjC,OAAO,CAAC,aAAa,CAYvB,CAAC"}
|