@fuzdev/fuz_app 0.180.0 → 0.182.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 +38 -20
- package/dist/actions/action_rpc.d.ts +25 -6
- package/dist/actions/action_rpc.d.ts.map +1 -1
- package/dist/actions/action_rpc.js +56 -48
- package/dist/actions/action_types.d.ts +31 -13
- package/dist/actions/action_types.d.ts.map +1 -1
- package/dist/actions/action_types.js +1 -1
- package/dist/actions/notification_sender.d.ts +83 -0
- package/dist/actions/notification_sender.d.ts.map +1 -0
- package/dist/actions/notification_sender.js +85 -0
- package/dist/actions/perform_action.d.ts +13 -4
- package/dist/actions/perform_action.d.ts.map +1 -1
- package/dist/actions/perform_action.js +27 -18
- package/dist/actions/register_action_ws.d.ts +20 -2
- package/dist/actions/register_action_ws.d.ts.map +1 -1
- package/dist/actions/register_action_ws.js +17 -5
- package/dist/actions/ws_socket_session.d.ts +3 -0
- package/dist/actions/ws_socket_session.d.ts.map +1 -1
- package/dist/actions/ws_socket_session.js +3 -2
- package/dist/auth/CLAUDE.md +84 -59
- package/dist/auth/account_actions.d.ts.map +1 -1
- package/dist/auth/account_actions.js +30 -3
- package/dist/auth/account_queries.d.ts +213 -2
- package/dist/auth/account_queries.d.ts.map +1 -1
- package/dist/auth/account_queries.js +255 -2
- 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 +5 -7
- package/dist/auth/account_routes.d.ts.map +1 -1
- package/dist/auth/account_routes.js +110 -89
- package/dist/auth/admin_actions.d.ts.map +1 -1
- package/dist/auth/admin_actions.js +117 -25
- package/dist/auth/api_token_queries.d.ts +29 -12
- package/dist/auth/api_token_queries.d.ts.map +1 -1
- package/dist/auth/api_token_queries.js +42 -27
- 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 +37 -32
- 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 +39 -30
- package/dist/auth/deps.d.ts +10 -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 +97 -76
- package/dist/auth/request_context.d.ts.map +1 -1
- package/dist/auth/request_context.js +93 -104
- package/dist/auth/resolved_auth.d.ts +10 -5
- package/dist/auth/resolved_auth.d.ts.map +1 -1
- package/dist/auth/resolved_auth.js +2 -2
- package/dist/auth/role_grant_offer_action_specs.d.ts +2 -2
- package/dist/auth/role_grant_offer_action_specs.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_action_specs.js +5 -3
- package/dist/auth/role_grant_offer_actions.d.ts +7 -11
- package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_actions.js +97 -106
- 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_notifications.d.ts +87 -38
- package/dist/auth/role_grant_offer_notifications.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_notifications.js +75 -22
- package/dist/auth/role_grant_offer_queries.d.ts +143 -9
- package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_queries.js +266 -66
- package/dist/auth/role_grant_offer_schema.js +1 -1
- package/dist/auth/role_grant_queries.d.ts +57 -10
- package/dist/auth/role_grant_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_queries.js +81 -22
- package/dist/auth/role_grant_sql.d.ts +21 -0
- package/dist/auth/role_grant_sql.d.ts.map +1 -1
- package/dist/auth/role_grant_sql.js +21 -0
- package/dist/auth/self_service_role_actions.d.ts.map +1 -1
- package/dist/auth/self_service_role_actions.js +9 -2
- 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 +95 -14
- package/dist/auth/session_queries.d.ts.map +1 -1
- package/dist/auth/session_queries.js +98 -19
- 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/standard_rpc_actions.d.ts +6 -19
- package/dist/auth/standard_rpc_actions.d.ts.map +1 -1
- package/dist/auth/standard_rpc_actions.js +5 -6
- package/dist/auth/token_scope.d.ts +6 -8
- package/dist/auth/token_scope.d.ts.map +1 -1
- package/dist/auth/token_scope.js +6 -9
- 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 +156 -48
- package/dist/http/auth_shape.d.ts +4 -4
- 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 +45 -22
- package/dist/http/error_schemas.d.ts.map +1 -1
- package/dist/http/error_schemas.js +53 -26
- 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 +299 -83
- 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 +4 -4
- package/dist/server/app_server.d.ts +54 -33
- package/dist/server/app_server.d.ts.map +1 -1
- package/dist/server/app_server.js +69 -41
- package/dist/server/serve_fact_route.d.ts +3 -3
- package/dist/server/serve_fact_route.d.ts.map +1 -1
- package/dist/server/serve_fact_route.js +59 -55
- 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 +406 -1202
- 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 +5 -9
- package/dist/testing/auth_apps.d.ts.map +1 -1
- package/dist/testing/auth_apps.js +3 -2
- 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 +320 -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.d.ts +1 -26
- package/dist/testing/cross_backend/default_spine_surface.d.ts.map +1 -1
- package/dist/testing/cross_backend/default_spine_surface.js +3 -7
- 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 +4 -10
- package/dist/testing/cross_backend/full_spine_mount.d.ts.map +1 -1
- package/dist/testing/cross_backend/full_spine_mount.js +11 -4
- 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 +5 -4
- 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 +185 -31
- 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 +82 -34
- 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 +3 -1
- package/dist/testing/middleware.d.ts.map +1 -1
- package/dist/testing/middleware.js +14 -7
- package/dist/testing/resolved_auth.d.ts +3 -1
- package/dist/testing/resolved_auth.d.ts.map +1 -1
- package/dist/testing/resolved_auth.js +4 -4
- 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 +13 -10
- 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/dist/testing/ws_round_trip.d.ts.map +1 -1
- package/dist/testing/ws_round_trip.js +8 -4
- package/package.json +1 -1
package/dist/auth/bearer_auth.js
CHANGED
|
@@ -18,10 +18,12 @@ import { DEV } from 'esm-env';
|
|
|
18
18
|
import { RESOLVED_AUTH_KEY } from '../hono_context.js';
|
|
19
19
|
import { credential_deadline_after } from './credential_deadline.js';
|
|
20
20
|
import { get_resolved_auth } from './resolved_auth.js';
|
|
21
|
-
import {
|
|
22
|
-
import { query_validate_api_token } from './api_token_queries.js';
|
|
21
|
+
import { read_bearer_token } from './credential_headers.js';
|
|
22
|
+
import { query_api_token_touch, query_validate_api_token } from './api_token_queries.js';
|
|
23
|
+
import { query_account_by_id } from './account_queries.js';
|
|
23
24
|
import { get_client_ip } from '../http/client_ip.js';
|
|
24
|
-
import {
|
|
25
|
+
import { get_header_lines } from '../http/header_lines.js';
|
|
26
|
+
import { is_browser_context } from '../http/request_headers.js';
|
|
25
27
|
/**
|
|
26
28
|
* Create middleware that authenticates via bearer token.
|
|
27
29
|
*
|
|
@@ -36,9 +38,10 @@ import { is_browser_context } from '../http/origin.js';
|
|
|
36
38
|
* Discards bearer tokens when an `Origin` or `Referer` header is present —
|
|
37
39
|
* `next()` with no identity, as for a bad token — so browsers must use cookie
|
|
38
40
|
* auth, reducing attack surface.
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
41
|
+
* The token is read by `read_bearer_token`: one `Authorization` line, the
|
|
42
|
+
* scheme in any case (RFC 7235), one space, an `is_api_token_shaped` value. A
|
|
43
|
+
* header that reads no token — sent twice included — soft-fails before the
|
|
44
|
+
* database is touched.
|
|
42
45
|
* On success, sets the `api_token` arm of `ResolvedAuth` (`RESOLVED_AUTH_KEY`):
|
|
43
46
|
* the account, the token id, its scope, and its deadline. The last leg of the
|
|
44
47
|
* chain, it skips when an earlier one (the daemon token or a session cookie)
|
|
@@ -67,19 +70,23 @@ export const create_bearer_auth_middleware = (deps, log) => {
|
|
|
67
70
|
await next();
|
|
68
71
|
return;
|
|
69
72
|
}
|
|
70
|
-
|
|
71
|
-
//
|
|
72
|
-
//
|
|
73
|
-
//
|
|
74
|
-
|
|
73
|
+
// The header's one shaped token, or nothing (`read_bearer_token`): absent,
|
|
74
|
+
// another scheme, an empty or malformed token, and a header sent as more
|
|
75
|
+
// than one line all read `null` and soft-fail before any database work —
|
|
76
|
+
// no pool checkout, no query — so junk bearers cost nothing to refuse.
|
|
77
|
+
const authorization_lines = get_header_lines(c, 'Authorization');
|
|
78
|
+
const raw_token = read_bearer_token(authorization_lines);
|
|
79
|
+
if (raw_token === null) {
|
|
80
|
+
if (authorization_lines.length > 0)
|
|
81
|
+
log.debug('bearer auth soft-fail: no token read');
|
|
75
82
|
await next();
|
|
76
83
|
return;
|
|
77
84
|
}
|
|
78
85
|
// Silently discard bearer tokens in browser context (`is_browser_context`
|
|
79
|
-
// — Origin or Referer present). Discards rather than returning 403 so that
|
|
86
|
+
// — an Origin or Referer line present). Discards rather than returning 403 so that
|
|
80
87
|
// the RPC dispatcher can still handle public actions or fall through to
|
|
81
88
|
// cookie auth.
|
|
82
|
-
if (is_browser_context(c)) {
|
|
89
|
+
if (is_browser_context(get_header_lines(c, 'origin'), get_header_lines(c, 'referer'))) {
|
|
83
90
|
log.debug('bearer auth rejected: browser context (Origin/Referer present)');
|
|
84
91
|
// The discard is silent on the wire by design (a stolen-token probe
|
|
85
92
|
// gets an indistinguishable 401, not a "your token was dropped"
|
|
@@ -91,24 +98,7 @@ export const create_bearer_auth_middleware = (deps, log) => {
|
|
|
91
98
|
await next();
|
|
92
99
|
return;
|
|
93
100
|
}
|
|
94
|
-
const
|
|
95
|
-
// Empty token body — soft-fail (treat as "no credential").
|
|
96
|
-
// (The Fetch API trims 'Bearer ' to 'Bearer' which skips this middleware entirely,
|
|
97
|
-
// but raw HTTP clients may send 'Bearer ' with an empty token.)
|
|
98
|
-
if (!raw_token) {
|
|
99
|
-
await next();
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
// A value that cannot be a token soft-fails before any database work —
|
|
103
|
-
// no pool checkout, no query — so junk bearers cost nothing to refuse.
|
|
104
|
-
if (!is_api_token_shaped(raw_token)) {
|
|
105
|
-
log.debug('bearer auth soft-fail: malformed token');
|
|
106
|
-
await next();
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
// `ip` feeds the token's `last_used_ip` bookkeeping, not a limiter.
|
|
110
|
-
const ip = get_client_ip(c);
|
|
111
|
-
const api_token = await query_validate_api_token({ ...deps, log }, raw_token, ip, c.var.pending_effects);
|
|
101
|
+
const api_token = await query_validate_api_token({ ...deps, log }, raw_token);
|
|
112
102
|
if (!api_token) {
|
|
113
103
|
// Invalid or expired token — soft-fail, indistinguishable from
|
|
114
104
|
// sending no credential at all.
|
|
@@ -116,9 +106,24 @@ export const create_bearer_auth_middleware = (deps, log) => {
|
|
|
116
106
|
await next();
|
|
117
107
|
return;
|
|
118
108
|
}
|
|
109
|
+
// a tombstoned account authenticates nothing — its token resolves as no
|
|
110
|
+
// credential, the anonymous caller, as on the Rust spine
|
|
111
|
+
const account = await query_account_by_id(deps, api_token.account_id);
|
|
112
|
+
if (!account) {
|
|
113
|
+
log.debug('bearer auth soft-fail: account not found or deleted');
|
|
114
|
+
await next();
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
// Fire-and-forget usage tracking, once the token has authenticated —
|
|
118
|
+
// after the account check, so a token on a tombstoned account records
|
|
119
|
+
// no use. `ip` feeds `last_used_ip`, not a limiter.
|
|
120
|
+
const touch = query_api_token_touch(deps, api_token.id, get_client_ip(c)).catch((err) => {
|
|
121
|
+
log.error('Failed to update last_used_at:', err);
|
|
122
|
+
});
|
|
123
|
+
c.var.pending_effects?.push(touch);
|
|
119
124
|
c.set(RESOLVED_AUTH_KEY, {
|
|
120
125
|
credential_type: 'api_token',
|
|
121
|
-
|
|
126
|
+
account,
|
|
122
127
|
api_token_id: api_token.id,
|
|
123
128
|
// Parsed by the query, which refuses a token whose stored scope is
|
|
124
129
|
// unreadable — there is no default to fall back to.
|
|
@@ -2,31 +2,44 @@
|
|
|
2
2
|
* Bootstrap flow for creating the first account.
|
|
3
3
|
*
|
|
4
4
|
* Uses an atomic `bootstrap_lock` table to prevent TOCTOU race conditions.
|
|
5
|
-
*
|
|
5
|
+
* The lock flip, the account, its keeper and admin grants, its session, and
|
|
6
|
+
* the burn of the one-shot token file all happen in one transaction, the burn
|
|
7
|
+
* last — so a live token never outlives a successful bootstrap, and a
|
|
8
|
+
* bootstrap whose token can't be burned never happened.
|
|
6
9
|
*
|
|
7
10
|
* @module
|
|
8
11
|
*/
|
|
9
12
|
import type { Logger } from '@fuzdev/fuz_util/log.ts';
|
|
10
13
|
import type { PasswordHashDeps } from './password.js';
|
|
11
|
-
import { ERROR_INVALID_TOKEN, ERROR_ALREADY_BOOTSTRAPPED, ERROR_TOKEN_FILE_MISSING } from '../http/error_schemas.js';
|
|
14
|
+
import { ERROR_INVALID_TOKEN, ERROR_ALREADY_BOOTSTRAPPED, ERROR_TOKEN_FILE_MISSING, ERROR_TOKEN_FILE_UNDELETABLE } from '../http/error_schemas.js';
|
|
12
15
|
import type { Account, Actor, RoleGrant } from './account_schema.js';
|
|
13
16
|
import type { Db } from '../db/db.js';
|
|
17
|
+
import type { BootstrapTokenStore } from './bootstrap_token_store.js';
|
|
18
|
+
import type { Keyring } from './keyring.js';
|
|
19
|
+
import type { SessionOptions } from './session_cookie.js';
|
|
14
20
|
/** Input for the bootstrap account creation. */
|
|
15
21
|
export interface BootstrapAccountInput {
|
|
16
22
|
username: string;
|
|
17
23
|
password: string;
|
|
18
24
|
}
|
|
19
|
-
/**
|
|
20
|
-
export interface
|
|
21
|
-
ok: true;
|
|
25
|
+
/** What a successful bootstrap created. */
|
|
26
|
+
export interface BootstrapAccountCreated {
|
|
22
27
|
account: Account;
|
|
23
28
|
actor: Actor;
|
|
24
29
|
role_grants: {
|
|
25
30
|
keeper: RoleGrant;
|
|
26
31
|
admin: RoleGrant;
|
|
27
32
|
};
|
|
28
|
-
|
|
29
|
-
|
|
33
|
+
}
|
|
34
|
+
/** Successful bootstrap result with the created entities and the new session. */
|
|
35
|
+
export interface BootstrapAccountSuccess extends BootstrapAccountCreated {
|
|
36
|
+
ok: true;
|
|
37
|
+
/**
|
|
38
|
+
* The signed cookie value of the session minted in the bootstrap
|
|
39
|
+
* transaction, for the caller to set on its response — it exists only
|
|
40
|
+
* because the transaction committed.
|
|
41
|
+
*/
|
|
42
|
+
session_cookie_value: string;
|
|
30
43
|
}
|
|
31
44
|
/** Bootstrap failure result. */
|
|
32
45
|
export type BootstrapAccountFailure = {
|
|
@@ -41,6 +54,10 @@ export type BootstrapAccountFailure = {
|
|
|
41
54
|
ok: false;
|
|
42
55
|
error: typeof ERROR_INVALID_TOKEN;
|
|
43
56
|
status: 401;
|
|
57
|
+
} | {
|
|
58
|
+
ok: false;
|
|
59
|
+
error: typeof ERROR_TOKEN_FILE_UNDELETABLE;
|
|
60
|
+
status: 500;
|
|
44
61
|
};
|
|
45
62
|
/** Bootstrap account result — either success or a bootstrap verification failure. */
|
|
46
63
|
export type BootstrapAccountResult = BootstrapAccountSuccess | BootstrapAccountFailure;
|
|
@@ -49,23 +66,25 @@ export type BootstrapAccountResult = BootstrapAccountSuccess | BootstrapAccountF
|
|
|
49
66
|
*/
|
|
50
67
|
export interface BootstrapAccountDeps {
|
|
51
68
|
db: Db;
|
|
52
|
-
/** Path to the bootstrap token file on disk. */
|
|
53
|
-
token_path: string;
|
|
54
69
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* every throw reads as `TOKEN_FILE_MISSING` upstream.
|
|
70
|
+
* The one-shot token: read through the hardened secret read (a symlinked,
|
|
71
|
+
* non-regular, group/other-readable, multiply-linked, or oversized file is
|
|
72
|
+
* refused — every refusal reads as `TOKEN_FILE_MISSING`), burned last inside the
|
|
73
|
+
* transaction.
|
|
60
74
|
*/
|
|
61
|
-
|
|
62
|
-
/** Delete a file. */
|
|
63
|
-
delete_file: (path: string) => Promise<void>;
|
|
75
|
+
token_store: BootstrapTokenStore;
|
|
64
76
|
/** Only hashing is needed — verification happens separately during login. */
|
|
65
77
|
password: Pick<PasswordHashDeps, 'hash_password'>;
|
|
78
|
+
/** Signs the session cookie minted in the transaction. */
|
|
79
|
+
keyring: Keyring;
|
|
66
80
|
/** Structured logger instance. */
|
|
67
81
|
log: Logger;
|
|
68
82
|
}
|
|
83
|
+
/** Static options for `bootstrap_account`. */
|
|
84
|
+
export interface BootstrapAccountOptions {
|
|
85
|
+
/** Session cookie configuration for the session the bootstrap mints. */
|
|
86
|
+
session_options: SessionOptions<string>;
|
|
87
|
+
}
|
|
69
88
|
/**
|
|
70
89
|
* The fewest bytes a bootstrap token holds, counted after its one optional
|
|
71
90
|
* trailing LF. A shorter file is read as unreadable: an empty or `"\n"` file
|
|
@@ -78,40 +97,49 @@ export interface BootstrapAccountDeps {
|
|
|
78
97
|
export declare const BOOTSTRAP_TOKEN_MIN_BYTES = 32;
|
|
79
98
|
/**
|
|
80
99
|
* Read the bootstrap token the way both the availability check and the
|
|
81
|
-
* request-time compare need it: the hardened
|
|
100
|
+
* request-time compare need it: the store's hardened read, less one trailing
|
|
82
101
|
* LF, refused when shorter than `BOOTSTRAP_TOKEN_MIN_BYTES`. A short token
|
|
83
102
|
* logs an error naming the file before the throw — it is a misconfiguration
|
|
84
103
|
* the operator must fix, never a quiet "unavailable". Twin of the Rust
|
|
85
104
|
* `bootstrap_token_from_file`.
|
|
86
105
|
*
|
|
87
|
-
* @param deps - the
|
|
88
|
-
* @param token_path - the bootstrap token file
|
|
106
|
+
* @param deps - the token store and a logger for the short-token error
|
|
89
107
|
* @returns the token bytes the provided token is compared against
|
|
90
|
-
* @throws Error when the
|
|
108
|
+
* @throws Error when the store refuses the file or the token is too short
|
|
91
109
|
*/
|
|
92
|
-
export declare const read_bootstrap_token: (deps: Pick<BootstrapAccountDeps, "
|
|
110
|
+
export declare const read_bootstrap_token: (deps: Pick<BootstrapAccountDeps, "token_store" | "log">) => Promise<Uint8Array>;
|
|
93
111
|
/**
|
|
94
112
|
* Bootstrap the first account with keeper and admin privileges.
|
|
95
113
|
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
* 1. Read and verify the bootstrap token (before transaction) — the file's
|
|
100
|
-
* raw bytes less one optional trailing LF, at least
|
|
114
|
+
* 1. Read and verify the bootstrap token (before the transaction) — the
|
|
115
|
+
* file's raw bytes less one optional trailing LF, at least
|
|
101
116
|
* `BOOTSTRAP_TOKEN_MIN_BYTES` long, compared in constant time
|
|
102
|
-
* 2. Hash the password (CPU-intensive, before transaction)
|
|
103
|
-
* 3.
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
117
|
+
* 2. Hash the password (CPU-intensive, before the transaction)
|
|
118
|
+
* 3. In one transaction: flip the `bootstrap_lock` atomically (zero rows is
|
|
119
|
+
* the race loser, `already_bootstrapped`, nothing burned); create the
|
|
120
|
+
* account + actor; grant keeper and admin (no expiry, `granted_by =
|
|
121
|
+
* null`); mint the session through the capped minter login uses (the cap
|
|
122
|
+
* evicts nothing on a new account); then burn the token file, last, just
|
|
123
|
+
* before the commit
|
|
124
|
+
*
|
|
125
|
+
* The burn comes after the lock, so only the lock winner burns (its row lock
|
|
126
|
+
* is held across the unlink, so a concurrent attempt waits on its UPDATE);
|
|
127
|
+
* after the inserts, so a failed insert spends nothing; last, so the window
|
|
128
|
+
* between a burn and a failed commit is one round trip. A burn that fails
|
|
129
|
+
* rolls everything back and answers `token_file_undeletable`: nothing was
|
|
130
|
+
* created and the token is still valid, so the operator fixes the directory
|
|
131
|
+
* and retries. A commit that fails after the burn is logged as an error — the
|
|
132
|
+
* token is gone and a new one must be written. Twin of the Rust
|
|
133
|
+
* `bootstrap_handler`.
|
|
107
134
|
*
|
|
108
|
-
* @param deps - database, token
|
|
135
|
+
* @param deps - database, token store, password hashing, keyring, and logger
|
|
109
136
|
* @param provided_token - the bootstrap token from the user
|
|
110
137
|
* @param input - username and password
|
|
111
|
-
* @
|
|
138
|
+
* @param options - the session cookie configuration
|
|
139
|
+
* @returns the created account, actor, role_grants, and session cookie value — or a bootstrap failure
|
|
112
140
|
* @mutates `bootstrap_lock` row - flips `bootstrapped` to `true` atomically
|
|
113
|
-
* @mutates `account` / `actor` / `role_grant` tables - inserts the bootstrap account, actor,
|
|
114
|
-
* @mutates filesystem -
|
|
141
|
+
* @mutates `account` / `actor` / `role_grant` / `auth_session` tables - inserts the bootstrap account, actor, keeper + admin role_grants, and session
|
|
142
|
+
* @mutates filesystem - burns the bootstrap token file inside the transaction
|
|
115
143
|
*/
|
|
116
|
-
export declare const bootstrap_account: (deps: BootstrapAccountDeps, provided_token: string, input: BootstrapAccountInput) => Promise<BootstrapAccountResult>;
|
|
144
|
+
export declare const bootstrap_account: (deps: BootstrapAccountDeps, provided_token: string, input: BootstrapAccountInput, options: BootstrapAccountOptions) => Promise<BootstrapAccountResult>;
|
|
117
145
|
//# sourceMappingURL=bootstrap_account.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap_account.d.ts","sourceRoot":"","sources":["../../src/lib/auth/bootstrap_account.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"bootstrap_account.d.ts","sourceRoot":"","sources":["../../src/lib/auth/bootstrap_account.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAGtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EACN,mBAAmB,EACnB,0BAA0B,EAC1B,wBAAwB,EACxB,4BAA4B,EAC5B,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAGrE,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAI1D,gDAAgD;AAChD,MAAM,WAAW,qBAAqB;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED,2CAA2C;AAC3C,MAAM,WAAW,uBAAuB;IACvC,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,KAAK,CAAC;IACb,WAAW,EAAE;QAAE,MAAM,EAAE,SAAS,CAAC;QAAC,KAAK,EAAE,SAAS,CAAA;KAAE,CAAC;CACrD;AAED,iFAAiF;AACjF,MAAM,WAAW,uBAAwB,SAAQ,uBAAuB;IACvE,EAAE,EAAE,IAAI,CAAC;IACT;;;;OAIG;IACH,oBAAoB,EAAE,MAAM,CAAC;CAC7B;AAED,gCAAgC;AAChC,MAAM,MAAM,uBAAuB,GAChC;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,OAAO,0BAA0B,CAAC;IAAC,MAAM,EAAE,GAAG,CAAA;CAAE,GACpE;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,OAAO,wBAAwB,CAAC;IAAC,MAAM,EAAE,GAAG,CAAA;CAAE,GAClE;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,OAAO,mBAAmB,CAAC;IAAC,MAAM,EAAE,GAAG,CAAA;CAAE,GAC7D;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,OAAO,4BAA4B,CAAC;IAAC,MAAM,EAAE,GAAG,CAAA;CAAE,CAAC;AAE1E,qFAAqF;AACrF,MAAM,MAAM,sBAAsB,GAAG,uBAAuB,GAAG,uBAAuB,CAAC;AAEvF;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACpC,EAAE,EAAE,EAAE,CAAC;IACP;;;;;OAKG;IACH,WAAW,EAAE,mBAAmB,CAAC;IACjC,6EAA6E;IAC7E,QAAQ,EAAE,IAAI,CAAC,gBAAgB,EAAE,eAAe,CAAC,CAAC;IAClD,0DAA0D;IAC1D,OAAO,EAAE,OAAO,CAAC;IACjB,kCAAkC;IAClC,GAAG,EAAE,MAAM,CAAC;CACZ;AAED,8CAA8C;AAC9C,MAAM,WAAW,uBAAuB;IACvC,wEAAwE;IACxE,eAAe,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC;CACxC;AAsBD;;;;;;;;GAQG;AACH,eAAO,MAAM,yBAAyB,KAAK,CAAC;AAE5C;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,oBAAoB,GAChC,MAAM,IAAI,CAAC,oBAAoB,EAAE,aAAa,GAAG,KAAK,CAAC,KACrD,OAAO,CAAC,UAAU,CASpB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,iBAAiB,GAC7B,MAAM,oBAAoB,EAC1B,gBAAgB,MAAM,EACtB,OAAO,qBAAqB,EAC5B,SAAS,uBAAuB,KAC9B,OAAO,CAAC,sBAAsB,CA0GhC,CAAC"}
|
|
@@ -2,16 +2,29 @@
|
|
|
2
2
|
* Bootstrap flow for creating the first account.
|
|
3
3
|
*
|
|
4
4
|
* Uses an atomic `bootstrap_lock` table to prevent TOCTOU race conditions.
|
|
5
|
-
*
|
|
5
|
+
* The lock flip, the account, its keeper and admin grants, its session, and
|
|
6
|
+
* the burn of the one-shot token file all happen in one transaction, the burn
|
|
7
|
+
* last — so a live token never outlives a successful bootstrap, and a
|
|
8
|
+
* bootstrap whose token can't be burned never happened.
|
|
6
9
|
*
|
|
7
10
|
* @module
|
|
8
11
|
*/
|
|
9
12
|
import { timingSafeEqual } from 'node:crypto';
|
|
10
13
|
import { to_error_message } from '@fuzdev/fuz_util/error.ts';
|
|
11
|
-
import { ERROR_INVALID_TOKEN, ERROR_ALREADY_BOOTSTRAPPED, ERROR_TOKEN_FILE_MISSING } from '../http/error_schemas.js';
|
|
14
|
+
import { ERROR_INVALID_TOKEN, ERROR_ALREADY_BOOTSTRAPPED, ERROR_TOKEN_FILE_MISSING, ERROR_TOKEN_FILE_UNDELETABLE } from '../http/error_schemas.js';
|
|
12
15
|
import { ROLE_ADMIN, ROLE_KEEPER } from './role_schema.js';
|
|
13
16
|
import { query_create_account_with_actor } from './account_queries.js';
|
|
14
17
|
import { query_create_role_grant } from './role_grant_queries.js';
|
|
18
|
+
import { create_capped_session } from './session_queries.js';
|
|
19
|
+
import { DEFAULT_MAX_SESSIONS } from './account_route_schema.js';
|
|
20
|
+
/**
|
|
21
|
+
* Thrown out of the bootstrap transaction when the token can't be burned, so
|
|
22
|
+
* the transaction rolls back — `db.transaction` commits when its callback
|
|
23
|
+
* returns. Caught around the transaction and mapped to
|
|
24
|
+
* `ERROR_TOKEN_FILE_UNDELETABLE`; never escapes `bootstrap_account`.
|
|
25
|
+
*/
|
|
26
|
+
class BootstrapTokenBurnError extends Error {
|
|
27
|
+
}
|
|
15
28
|
/**
|
|
16
29
|
* Strip exactly one trailing `\n` from the operator-written token bytes.
|
|
17
30
|
*
|
|
@@ -34,21 +47,21 @@ const strip_one_trailing_newline = (bytes) => bytes.at(-1) === 0x0a ? bytes.suba
|
|
|
34
47
|
export const BOOTSTRAP_TOKEN_MIN_BYTES = 32;
|
|
35
48
|
/**
|
|
36
49
|
* Read the bootstrap token the way both the availability check and the
|
|
37
|
-
* request-time compare need it: the hardened
|
|
50
|
+
* request-time compare need it: the store's hardened read, less one trailing
|
|
38
51
|
* LF, refused when shorter than `BOOTSTRAP_TOKEN_MIN_BYTES`. A short token
|
|
39
52
|
* logs an error naming the file before the throw — it is a misconfiguration
|
|
40
53
|
* the operator must fix, never a quiet "unavailable". Twin of the Rust
|
|
41
54
|
* `bootstrap_token_from_file`.
|
|
42
55
|
*
|
|
43
|
-
* @param deps - the
|
|
44
|
-
* @param token_path - the bootstrap token file
|
|
56
|
+
* @param deps - the token store and a logger for the short-token error
|
|
45
57
|
* @returns the token bytes the provided token is compared against
|
|
46
|
-
* @throws Error when the
|
|
58
|
+
* @throws Error when the store refuses the file or the token is too short
|
|
47
59
|
*/
|
|
48
|
-
export const read_bootstrap_token = async (deps
|
|
49
|
-
const
|
|
60
|
+
export const read_bootstrap_token = async (deps) => {
|
|
61
|
+
const { token_store } = deps;
|
|
62
|
+
const token = strip_one_trailing_newline(await token_store.read_token());
|
|
50
63
|
if (token.length < BOOTSTRAP_TOKEN_MIN_BYTES) {
|
|
51
|
-
const message = `bootstrap token at ${
|
|
64
|
+
const message = `bootstrap token at ${token_store.path} is ${token.length} bytes, under the ${BOOTSTRAP_TOKEN_MIN_BYTES}-byte minimum — regenerate it`;
|
|
52
65
|
deps.log.error(message);
|
|
53
66
|
throw new Error(message);
|
|
54
67
|
}
|
|
@@ -57,36 +70,46 @@ export const read_bootstrap_token = async (deps, token_path) => {
|
|
|
57
70
|
/**
|
|
58
71
|
* Bootstrap the first account with keeper and admin privileges.
|
|
59
72
|
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* 1. Read and verify the bootstrap token (before transaction) — the file's
|
|
64
|
-
* raw bytes less one optional trailing LF, at least
|
|
73
|
+
* 1. Read and verify the bootstrap token (before the transaction) — the
|
|
74
|
+
* file's raw bytes less one optional trailing LF, at least
|
|
65
75
|
* `BOOTSTRAP_TOKEN_MIN_BYTES` long, compared in constant time
|
|
66
|
-
* 2. Hash the password (CPU-intensive, before transaction)
|
|
67
|
-
* 3.
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
76
|
+
* 2. Hash the password (CPU-intensive, before the transaction)
|
|
77
|
+
* 3. In one transaction: flip the `bootstrap_lock` atomically (zero rows is
|
|
78
|
+
* the race loser, `already_bootstrapped`, nothing burned); create the
|
|
79
|
+
* account + actor; grant keeper and admin (no expiry, `granted_by =
|
|
80
|
+
* null`); mint the session through the capped minter login uses (the cap
|
|
81
|
+
* evicts nothing on a new account); then burn the token file, last, just
|
|
82
|
+
* before the commit
|
|
71
83
|
*
|
|
72
|
-
*
|
|
84
|
+
* The burn comes after the lock, so only the lock winner burns (its row lock
|
|
85
|
+
* is held across the unlink, so a concurrent attempt waits on its UPDATE);
|
|
86
|
+
* after the inserts, so a failed insert spends nothing; last, so the window
|
|
87
|
+
* between a burn and a failed commit is one round trip. A burn that fails
|
|
88
|
+
* rolls everything back and answers `token_file_undeletable`: nothing was
|
|
89
|
+
* created and the token is still valid, so the operator fixes the directory
|
|
90
|
+
* and retries. A commit that fails after the burn is logged as an error — the
|
|
91
|
+
* token is gone and a new one must be written. Twin of the Rust
|
|
92
|
+
* `bootstrap_handler`.
|
|
93
|
+
*
|
|
94
|
+
* @param deps - database, token store, password hashing, keyring, and logger
|
|
73
95
|
* @param provided_token - the bootstrap token from the user
|
|
74
96
|
* @param input - username and password
|
|
75
|
-
* @
|
|
97
|
+
* @param options - the session cookie configuration
|
|
98
|
+
* @returns the created account, actor, role_grants, and session cookie value — or a bootstrap failure
|
|
76
99
|
* @mutates `bootstrap_lock` row - flips `bootstrapped` to `true` atomically
|
|
77
|
-
* @mutates `account` / `actor` / `role_grant` tables - inserts the bootstrap account, actor,
|
|
78
|
-
* @mutates filesystem -
|
|
100
|
+
* @mutates `account` / `actor` / `role_grant` / `auth_session` tables - inserts the bootstrap account, actor, keeper + admin role_grants, and session
|
|
101
|
+
* @mutates filesystem - burns the bootstrap token file inside the transaction
|
|
79
102
|
*/
|
|
80
|
-
export const bootstrap_account = async (deps, provided_token, input) => {
|
|
81
|
-
const { db,
|
|
103
|
+
export const bootstrap_account = async (deps, provided_token, input, options) => {
|
|
104
|
+
const { db, token_store, password, keyring, log } = deps;
|
|
82
105
|
// 1. Read and verify token (non-destructive, before transaction). The
|
|
83
106
|
// secure read fails loud on a symlink / non-regular file / permissive mode /
|
|
84
|
-
// oversized file, and the read refuses a token under the minimum length —
|
|
107
|
+
// second hard link / oversized file, and the read refuses a token under the minimum length —
|
|
85
108
|
// every refusal masks as the same TOKEN_FILE_MISSING the wire always
|
|
86
109
|
// carried, with the specific reason logged for the operator.
|
|
87
110
|
let expected_token;
|
|
88
111
|
try {
|
|
89
|
-
expected_token = await read_bootstrap_token({
|
|
112
|
+
expected_token = await read_bootstrap_token({ token_store, log });
|
|
90
113
|
}
|
|
91
114
|
catch (err) {
|
|
92
115
|
log.warn(`bootstrap token file rejected: ${to_error_message(err)}`);
|
|
@@ -101,46 +124,72 @@ export const bootstrap_account = async (deps, provided_token, input) => {
|
|
|
101
124
|
}
|
|
102
125
|
// 2. Hash password (CPU-intensive, before transaction)
|
|
103
126
|
const password_hash = await password.hash_password(input.password);
|
|
104
|
-
// 3. Atomic transaction: lock
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (lock_rows.length === 0) {
|
|
108
|
-
return { ok: false, error: ERROR_ALREADY_BOOTSTRAPPED, status: 403 };
|
|
109
|
-
}
|
|
110
|
-
const tx_deps = { db: tx };
|
|
111
|
-
const { account, actor } = await query_create_account_with_actor(tx_deps, {
|
|
112
|
-
username: input.username,
|
|
113
|
-
password_hash
|
|
114
|
-
});
|
|
115
|
-
const keeper_role_grant = await query_create_role_grant(tx_deps, {
|
|
116
|
-
actor_id: actor.id,
|
|
117
|
-
role: ROLE_KEEPER,
|
|
118
|
-
granted_by: null,
|
|
119
|
-
expires_at: null
|
|
120
|
-
});
|
|
121
|
-
const admin_role_grant = await query_create_role_grant(tx_deps, {
|
|
122
|
-
actor_id: actor.id,
|
|
123
|
-
role: ROLE_ADMIN,
|
|
124
|
-
granted_by: null,
|
|
125
|
-
expires_at: null
|
|
126
|
-
});
|
|
127
|
-
return {
|
|
128
|
-
ok: true,
|
|
129
|
-
account,
|
|
130
|
-
actor,
|
|
131
|
-
role_grants: { keeper: keeper_role_grant, admin: admin_role_grant }
|
|
132
|
-
};
|
|
133
|
-
});
|
|
134
|
-
if (!tx_result.ok)
|
|
135
|
-
return tx_result;
|
|
136
|
-
// 4. Delete token file (after commit)
|
|
137
|
-
let token_file_deleted = true;
|
|
127
|
+
// 3. Atomic transaction: lock, create, mint, burn
|
|
128
|
+
let burned = false;
|
|
129
|
+
let tx_result;
|
|
138
130
|
try {
|
|
139
|
-
await
|
|
131
|
+
tx_result = await db.transaction(async (tx) => {
|
|
132
|
+
const lock_rows = await tx.query('UPDATE bootstrap_lock SET bootstrapped = true WHERE id = 1 AND bootstrapped = false RETURNING id');
|
|
133
|
+
if (lock_rows.length === 0) {
|
|
134
|
+
return { ok: false, error: ERROR_ALREADY_BOOTSTRAPPED, status: 403 };
|
|
135
|
+
}
|
|
136
|
+
const tx_deps = { db: tx };
|
|
137
|
+
const { account, actor } = await query_create_account_with_actor(tx_deps, {
|
|
138
|
+
username: input.username,
|
|
139
|
+
password_hash
|
|
140
|
+
});
|
|
141
|
+
const keeper_role_grant = await query_create_role_grant(tx_deps, {
|
|
142
|
+
actor_id: actor.id,
|
|
143
|
+
role: ROLE_KEEPER,
|
|
144
|
+
granted_by: null,
|
|
145
|
+
expires_at: null
|
|
146
|
+
});
|
|
147
|
+
const admin_role_grant = await query_create_role_grant(tx_deps, {
|
|
148
|
+
actor_id: actor.id,
|
|
149
|
+
role: ROLE_ADMIN,
|
|
150
|
+
granted_by: null,
|
|
151
|
+
expires_at: null
|
|
152
|
+
});
|
|
153
|
+
// The account was created above, so the cap evicts nothing. Routed
|
|
154
|
+
// through the shared minter anyway: the cap is a property of session
|
|
155
|
+
// creation, not of the login route.
|
|
156
|
+
const { cookie_value } = await create_capped_session({
|
|
157
|
+
keyring,
|
|
158
|
+
deps: tx_deps,
|
|
159
|
+
account_id: account.id,
|
|
160
|
+
session_options: options.session_options,
|
|
161
|
+
max_sessions: DEFAULT_MAX_SESSIONS
|
|
162
|
+
});
|
|
163
|
+
// the burn, last before the commit
|
|
164
|
+
let outcome;
|
|
165
|
+
try {
|
|
166
|
+
outcome = await token_store.burn_token();
|
|
167
|
+
}
|
|
168
|
+
catch (err) {
|
|
169
|
+
throw new BootstrapTokenBurnError(to_error_message(err), { cause: err });
|
|
170
|
+
}
|
|
171
|
+
burned = true;
|
|
172
|
+
if (outcome === 'already_gone') {
|
|
173
|
+
log.warn('bootstrap token file was already gone at the burn — counted as burned');
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
ok: true,
|
|
177
|
+
account,
|
|
178
|
+
actor,
|
|
179
|
+
role_grants: { keeper: keeper_role_grant, admin: admin_role_grant },
|
|
180
|
+
session_cookie_value: cookie_value
|
|
181
|
+
};
|
|
182
|
+
});
|
|
140
183
|
}
|
|
141
|
-
catch {
|
|
142
|
-
|
|
143
|
-
|
|
184
|
+
catch (err) {
|
|
185
|
+
if (err instanceof BootstrapTokenBurnError) {
|
|
186
|
+
log.error(`bootstrap rolled back: could not delete the token file at ${token_store.path} (${err.message}) — the server user needs write access to its directory; nothing was created and the token is still valid, retry`);
|
|
187
|
+
return { ok: false, error: ERROR_TOKEN_FILE_UNDELETABLE, status: 500 };
|
|
188
|
+
}
|
|
189
|
+
if (burned) {
|
|
190
|
+
log.error(`bootstrap rolled back after its token file at ${token_store.path} was deleted (${to_error_message(err)}) — write a new token and restart the server to bootstrap`);
|
|
191
|
+
}
|
|
192
|
+
throw err;
|
|
144
193
|
}
|
|
145
|
-
return
|
|
194
|
+
return tx_result;
|
|
146
195
|
};
|
|
@@ -57,7 +57,7 @@ export type BootstrapOutput = Infer<typeof BootstrapOutput>;
|
|
|
57
57
|
* (`attach_route_handler`); surface generation attaches a stub (handlers are never run
|
|
58
58
|
* during surface assembly, only the shape is read).
|
|
59
59
|
*/
|
|
60
|
-
export declare const bootstrap_route_shape: import("../http/route_spec.js").RouteShape<readonly [import("../http/error_schemas.js").RestErrorDef<401, "invalid_token", Record<never, never>>, import("../http/error_schemas.js").RestErrorDef<403, "already_bootstrapped", Record<never, never>>, import("../http/error_schemas.js").RestErrorDef<404, "token_file_missing", Record<never, never>>], import("@fuzdev/fuz_schema/schema.ts").ObjectSchema<{
|
|
60
|
+
export declare const bootstrap_route_shape: import("../http/route_spec.js").RouteShape<readonly [import("../http/error_schemas.js").RestErrorDef<401, "invalid_token", Record<never, never>>, import("../http/error_schemas.js").RestErrorDef<403, "already_bootstrapped", Record<never, never>>, import("../http/error_schemas.js").RestErrorDef<404, "token_file_missing", Record<never, never>>, import("../http/error_schemas.js").RestErrorDef<500, "token_file_undeletable", Record<never, never>>], import("@fuzdev/fuz_schema/schema.ts").ObjectSchema<{
|
|
61
61
|
ok: import("@fuzdev/fuz_schema/schema.ts").LiteralSchema<true>;
|
|
62
62
|
account: import("@fuzdev/fuz_schema/schema.ts").ObjectSchema<{
|
|
63
63
|
id: import("@fuzdev/fuz_schema/schema.ts").BrandSchema<import("@fuzdev/fuz_schema/schema.ts").PipeSchema<string, import("@fuzdev/fuz_schema/schema.ts").StringSchema>, "Uuid">;
|
|
@@ -69,5 +69,9 @@ export declare const bootstrap_route_shape: import("../http/route_spec.js").Rout
|
|
|
69
69
|
}>, {
|
|
70
70
|
readonly account: "none";
|
|
71
71
|
readonly actor: "none";
|
|
72
|
-
}, "ip"
|
|
72
|
+
}, "ip", import("@fuzdev/fuz_schema/schema.ts").ObjectSchema<{
|
|
73
|
+
token: import("@fuzdev/fuz_schema/schema.ts").PipeSchema<string, import("@fuzdev/fuz_schema/schema.ts").StringSchema>;
|
|
74
|
+
username: import("@fuzdev/fuz_schema/schema.ts").PipeSchema<string, import("@fuzdev/fuz_schema/schema.ts").PipeSchema<string, import("@fuzdev/fuz_schema/schema.ts").StringSchema>>;
|
|
75
|
+
password: import("@fuzdev/fuz_schema/schema.ts").PipeSchema<string, import("@fuzdev/fuz_schema/schema.ts").StringSchema>;
|
|
76
|
+
}>, undefined, undefined>;
|
|
73
77
|
//# sourceMappingURL=bootstrap_route_schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap_route_schema.d.ts","sourceRoot":"","sources":["../../src/lib/auth/bootstrap_route_schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAON,KAAK,KAAK,EACV,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"bootstrap_route_schema.d.ts","sourceRoot":"","sources":["../../src/lib/auth/bootstrap_route_schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAON,KAAK,KAAK,EACV,MAAM,8BAA8B,CAAC;AAatC;;;;;;;;GAQG;AACH,eAAO,MAAM,0BAA0B,OAAO,CAAC;AAE/C;;;;GAIG;AACH,eAAO,MAAM,cAAc;;;;EAMzB,CAAC;AACH,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAE1D;;;;GAIG;AACH,eAAO,MAAM,eAAe;;;;;;;;;EAI1B,CAAC;AACH,MAAM,MAAM,eAAe,GAAG,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAE5D;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;yBAgBhC,CAAC"}
|
|
@@ -18,7 +18,7 @@ import { literal, max_length, min_length, object, pipe, string } from '@fuzdev/f
|
|
|
18
18
|
import { Username, UsernameCanonical, Uuid } from '../primitive_schemas.js';
|
|
19
19
|
import { Password } from './password.js';
|
|
20
20
|
import { define_route_shape } from '../http/route_spec.js';
|
|
21
|
-
import { REST_ALREADY_BOOTSTRAPPED, REST_INVALID_TOKEN, REST_TOKEN_FILE_MISSING } from '../http/error_schemas.js';
|
|
21
|
+
import { REST_ALREADY_BOOTSTRAPPED, REST_INVALID_TOKEN, REST_TOKEN_FILE_MISSING, REST_TOKEN_FILE_UNDELETABLE } from '../http/error_schemas.js';
|
|
22
22
|
/**
|
|
23
23
|
* The longest `token` `POST /bootstrap` takes, in UTF-16 code units: the token
|
|
24
24
|
* file's cap, `MAX_SECURE_FILE_SIZE` bytes. A token that can match the file is
|
|
@@ -67,5 +67,10 @@ export const bootstrap_route_shape = define_route_shape({
|
|
|
67
67
|
input: BootstrapInput,
|
|
68
68
|
output: BootstrapOutput,
|
|
69
69
|
rate_limit: 'ip',
|
|
70
|
-
errors: [
|
|
70
|
+
errors: [
|
|
71
|
+
REST_INVALID_TOKEN,
|
|
72
|
+
REST_ALREADY_BOOTSTRAPPED,
|
|
73
|
+
REST_TOKEN_FILE_MISSING,
|
|
74
|
+
REST_TOKEN_FILE_UNDELETABLE
|
|
75
|
+
]
|
|
71
76
|
});
|