@fuzdev/fuz_app 0.179.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 +5 -5
|
@@ -7,144 +7,172 @@
|
|
|
7
7
|
* @module
|
|
8
8
|
*/
|
|
9
9
|
import { to_error_message } from '@fuzdev/fuz_util/error.ts';
|
|
10
|
-
import {
|
|
10
|
+
import { session_cookie_header } from './session_cookie.js';
|
|
11
11
|
import { bootstrap_account, read_bootstrap_token } from './bootstrap_account.js';
|
|
12
12
|
import { bootstrap_route_shape } from './bootstrap_route_schema.js';
|
|
13
|
-
import { attach_route_handler
|
|
13
|
+
import { attach_route_handler } from '../http/route_spec.js';
|
|
14
14
|
import { route_fail, route_ok } from '../http/route_result.js';
|
|
15
|
-
import { get_client_ip } from '../http/client_ip.js';
|
|
16
15
|
import { rate_limit_ip_key } from '../http/ip_canonical.js';
|
|
17
16
|
import { reserve_optional } from '../rate_limiter.js';
|
|
18
|
-
import { ERROR_ALREADY_BOOTSTRAPPED, ERROR_TOKEN_FILE_MISSING, REST_ALREADY_BOOTSTRAPPED, REST_INVALID_TOKEN, REST_RATE_LIMIT_EXCEEDED, REST_TOKEN_FILE_MISSING } from '../http/error_schemas.js';
|
|
17
|
+
import { ERROR_ALREADY_BOOTSTRAPPED, ERROR_TOKEN_FILE_MISSING, ERROR_TOKEN_FILE_UNDELETABLE, REST_ALREADY_BOOTSTRAPPED, REST_INVALID_TOKEN, REST_RATE_LIMIT_EXCEEDED, REST_TOKEN_FILE_MISSING, REST_TOKEN_FILE_UNDELETABLE } from '../http/error_schemas.js';
|
|
19
18
|
/**
|
|
20
19
|
* Check bootstrap availability at startup.
|
|
21
20
|
*
|
|
22
|
-
* Bootstrap is available when
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* `BOOTSTRAP_TOKEN_MIN_BYTES` (a shorter one logs an error)
|
|
27
|
-
* 3. The `bootstrap_lock` table shows `bootstrapped = false`
|
|
21
|
+
* Bootstrap is available when a token store is configured, the
|
|
22
|
+
* `bootstrap_lock` row shows `bootstrapped = false`, and the token file
|
|
23
|
+
* passes the same `read_bootstrap_token` the request makes — so "bootstrap
|
|
24
|
+
* is available" and "the token file can actually be read" can't drift apart.
|
|
28
25
|
*
|
|
29
|
-
* The
|
|
30
|
-
* read uses**, so "bootstrap is available" and "the token file can actually
|
|
31
|
-
* be read" can't drift apart — an availability check laxer than the read it
|
|
32
|
-
* gates is the misconfiguration that reports green at boot and fails at
|
|
33
|
-
* request time. Twin of the Rust spine's `is_bootstrap_available`.
|
|
26
|
+
* The lock is read first, so the report fits the state:
|
|
34
27
|
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
28
|
+
* - a missing `bootstrap_lock` row is unavailable, logged as an `error` — the
|
|
29
|
+
* migration seeds it, and without it every bootstrap would be refused in
|
|
30
|
+
* its transaction while `/status` advertised an open window
|
|
31
|
+
* - bootstrapped, no readable token file: `info`, the steady state
|
|
32
|
+
* - bootstrapped with a readable token file: a `warn` naming it — it would
|
|
33
|
+
* reopen bootstrap on an empty database, so the operator should delete it
|
|
34
|
+
* - not bootstrapped and the file unreadable: a `warn` with the reason (and
|
|
35
|
+
* the `error` a short token logs)
|
|
36
|
+
*
|
|
37
|
+
* Twin of the Rust spine's `is_bootstrap_available`, which logs the same
|
|
38
|
+
* states at the same levels. A failed lock read throws here (boot fails)
|
|
39
|
+
* where the Rust twin reads it as unavailable.
|
|
40
|
+
*
|
|
41
|
+
* @param deps - the lock read and a logger
|
|
42
|
+
* @param options - the token store, `null` when bootstrap is not configured
|
|
43
|
+
* @returns the initial `BootstrapStatus`
|
|
38
44
|
*/
|
|
39
45
|
export const check_bootstrap_status = async (deps, options) => {
|
|
40
|
-
const {
|
|
41
|
-
const {
|
|
42
|
-
if (!
|
|
43
|
-
return { available: false
|
|
46
|
+
const { db, log } = deps;
|
|
47
|
+
const { token_store } = options;
|
|
48
|
+
if (!token_store)
|
|
49
|
+
return { available: false };
|
|
50
|
+
const lock_row = await db.query_one('SELECT bootstrapped FROM bootstrap_lock WHERE id = 1');
|
|
51
|
+
if (!lock_row) {
|
|
52
|
+
log.error('Bootstrap unavailable: the bootstrap_lock row is missing — the auth migration seeds it; restore it to bootstrap');
|
|
53
|
+
return { available: false };
|
|
54
|
+
}
|
|
55
|
+
if (lock_row.bootstrapped) {
|
|
56
|
+
let present = true;
|
|
57
|
+
try {
|
|
58
|
+
await token_store.read_token();
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
present = false;
|
|
62
|
+
}
|
|
63
|
+
if (present) {
|
|
64
|
+
log.warn(`Bootstrap token file present on a bootstrapped server at ${token_store.path} — it would reopen bootstrap on an empty database; delete it`);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
log.info('Bootstrap unavailable: already bootstrapped');
|
|
68
|
+
}
|
|
69
|
+
return { available: false };
|
|
44
70
|
}
|
|
45
71
|
try {
|
|
46
|
-
await read_bootstrap_token({
|
|
72
|
+
await read_bootstrap_token({ token_store, log });
|
|
47
73
|
}
|
|
48
74
|
catch (err) {
|
|
49
|
-
log.
|
|
50
|
-
return { available: false
|
|
51
|
-
}
|
|
52
|
-
const lock_row = await db.query_one('SELECT bootstrapped FROM bootstrap_lock WHERE id = 1');
|
|
53
|
-
if (lock_row?.bootstrapped) {
|
|
54
|
-
log.info('Bootstrap unavailable: already bootstrapped');
|
|
55
|
-
return { available: false, token_path };
|
|
75
|
+
log.warn(`Bootstrap unavailable: token file unreadable: ${to_error_message(err)}`);
|
|
76
|
+
return { available: false };
|
|
56
77
|
}
|
|
57
|
-
log.info(`Bootstrap token available: ${
|
|
58
|
-
return { available: true
|
|
78
|
+
log.info(`Bootstrap token available: ${token_store.path}`);
|
|
79
|
+
return { available: true };
|
|
59
80
|
};
|
|
60
81
|
/**
|
|
61
82
|
* Create bootstrap route specs for first-time account creation.
|
|
62
83
|
*
|
|
63
|
-
* @param deps - stateless capabilities
|
|
64
|
-
* @param options - per-factory configuration (session, token
|
|
84
|
+
* @param deps - stateless capabilities (keyring, password, audit, log)
|
|
85
|
+
* @param options - per-factory configuration (session, token store, bootstrap status, limiter)
|
|
65
86
|
* @returns route specs (not yet applied to Hono)
|
|
66
87
|
*/
|
|
67
88
|
export const create_bootstrap_route_specs = (deps, options) => {
|
|
68
|
-
const {
|
|
69
|
-
const { session_options, bootstrap_status, on_bootstrap, bootstrap_ip_rate_limiter } = options;
|
|
70
|
-
const { token_path } = bootstrap_status;
|
|
89
|
+
const { session_options, bootstrap_status, token_store, on_bootstrap, bootstrap_ip_rate_limiter } = options;
|
|
71
90
|
return [
|
|
72
|
-
attach_route_handler(bootstrap_route_shape, async (
|
|
91
|
+
attach_route_handler(bootstrap_route_shape, async (route) => {
|
|
73
92
|
// Short-circuit if bootstrap already completed or surface-only mounted.
|
|
74
|
-
// In 'surface_only' mode `
|
|
75
|
-
// `available
|
|
76
|
-
//
|
|
77
|
-
|
|
93
|
+
// In 'surface_only' mode `token_store === null`; in 'live' mode after
|
|
94
|
+
// the window closes `available` is `false`. Either way the wire shape
|
|
95
|
+
// is 403 ALREADY_BOOTSTRAPPED, and no audit row is written: the route
|
|
96
|
+
// stays mounted for the life of the process, so an emit here would be
|
|
97
|
+
// an unauthenticated, unbounded write channel.
|
|
98
|
+
if (!bootstrap_status.available || token_store === null) {
|
|
78
99
|
return route_fail(REST_ALREADY_BOOTSTRAPPED);
|
|
79
100
|
}
|
|
80
101
|
// Per-IP rate limit (before any token/DB work). Reserved, not
|
|
81
102
|
// checked: the attempt counts against the cap until it settles, so
|
|
82
103
|
// a concurrent burst of token guesses can't all pass before any of
|
|
83
|
-
// it records.
|
|
84
|
-
//
|
|
85
|
-
|
|
104
|
+
// it records. A refusal records it; the race loser, a success, and
|
|
105
|
+
// a throw release it in the `finally`.
|
|
106
|
+
// keyed by the address's rate-limit key (an IPv6 client's /64). With
|
|
107
|
+
// no resolved client IP that is one shared `'unknown'` bucket, where
|
|
108
|
+
// the Rust twin skips the limiter — the difference signup has too, and
|
|
109
|
+
// one only an app mounted without the proxy middleware can show.
|
|
110
|
+
const ip_key = bootstrap_ip_rate_limiter ? rate_limit_ip_key(route.client_ip) : null;
|
|
86
111
|
const ip_reserved = await reserve_optional(bootstrap_ip_rate_limiter, ip_key, {
|
|
87
|
-
signal:
|
|
112
|
+
signal: route.signal
|
|
88
113
|
});
|
|
89
114
|
if (!ip_reserved.ok) {
|
|
90
115
|
return route_fail(REST_RATE_LIMIT_EXCEEDED, { retry_after: ip_reserved.retry_after });
|
|
91
116
|
}
|
|
92
117
|
try {
|
|
93
|
-
const input =
|
|
118
|
+
const input = route.input;
|
|
94
119
|
// `transaction: false` makes `route.db` the pool. `bootstrap_account`
|
|
95
120
|
// manages its own transaction internally.
|
|
96
121
|
const result = await bootstrap_account({
|
|
97
122
|
db: route.db,
|
|
98
|
-
|
|
99
|
-
read_secure_file: deps.read_secure_file,
|
|
100
|
-
delete_file: deps.delete_file,
|
|
123
|
+
token_store,
|
|
101
124
|
password: deps.password,
|
|
125
|
+
keyring: deps.keyring,
|
|
102
126
|
log: deps.log
|
|
103
|
-
}, input.token, input);
|
|
127
|
+
}, input.token, input, { session_options });
|
|
104
128
|
if (!result.ok) {
|
|
129
|
+
// The lock-race loser — the window open here, the lock already
|
|
130
|
+
// flipped in the database. Close the window so the next caller
|
|
131
|
+
// takes the short-circuit, and write nothing and charge nothing:
|
|
132
|
+
// it is reachable only by a concurrent legitimate attempt, and
|
|
133
|
+
// folding it into the silent closed-window refusal keeps the
|
|
134
|
+
// post-bootstrap probe channel write-free. Twin of the Rust
|
|
135
|
+
// spine's `bootstrap_handler`.
|
|
136
|
+
if (result.error === ERROR_ALREADY_BOOTSTRAPPED) {
|
|
137
|
+
bootstrap_status.available = false;
|
|
138
|
+
return route_fail(REST_ALREADY_BOOTSTRAPPED);
|
|
139
|
+
}
|
|
105
140
|
// An unreadable token file closes the window. Bootstrap cannot
|
|
106
141
|
// succeed without one, and `check_bootstrap_status` already reads
|
|
107
142
|
// an unreadable file as unavailable at startup — so leaving the
|
|
108
143
|
// flag set means the two disagree, and every later request takes
|
|
109
|
-
// this leg and writes another audit row.
|
|
110
|
-
//
|
|
111
|
-
//
|
|
112
|
-
// Rust spine's `bootstrap_handler`, which does the same.
|
|
144
|
+
// this leg and writes another audit row. A wrong token and an
|
|
145
|
+
// undeletable file leave it open (the operator retries); the
|
|
146
|
+
// limiter bounds those.
|
|
113
147
|
if (result.error === ERROR_TOKEN_FILE_MISSING)
|
|
114
148
|
bootstrap_status.available = false;
|
|
115
149
|
ip_reserved.reservation.record();
|
|
116
150
|
await deps.audit.emit(route, {
|
|
117
151
|
event_type: 'bootstrap',
|
|
118
152
|
outcome: 'failure',
|
|
119
|
-
ip:
|
|
153
|
+
ip: route.client_ip,
|
|
120
154
|
metadata: { error: result.error }
|
|
121
155
|
});
|
|
122
|
-
return route_fail(result.error ===
|
|
123
|
-
?
|
|
124
|
-
: result.error ===
|
|
125
|
-
?
|
|
156
|
+
return route_fail(result.error === ERROR_TOKEN_FILE_MISSING
|
|
157
|
+
? REST_TOKEN_FILE_MISSING
|
|
158
|
+
: result.error === ERROR_TOKEN_FILE_UNDELETABLE
|
|
159
|
+
? REST_TOKEN_FILE_UNDELETABLE
|
|
126
160
|
: REST_INVALID_TOKEN);
|
|
127
161
|
}
|
|
128
|
-
// Successful bootstrap —
|
|
162
|
+
// Successful bootstrap — committed, its token burned. Nothing is
|
|
129
163
|
// reset: bootstrap has no account-grain bucket to forgive (it
|
|
130
164
|
// predates any account), and the IP bucket is never refunded on
|
|
131
|
-
// success (see `RateLimiter.reset`).
|
|
132
|
-
//
|
|
133
|
-
//
|
|
134
|
-
// survive — and they sit on this route's own limiter, not
|
|
135
|
-
// login's, so a fumbled token can't spend the operator's login
|
|
136
|
-
// budget on a deployment where their account is the only one.
|
|
165
|
+
// success (see `RateLimiter.reset`). Bootstrap is one-shot, so at
|
|
166
|
+
// most `max_attempts - 1` residual entries survive — and they sit
|
|
167
|
+
// on this route's own limiter, not login's.
|
|
137
168
|
bootstrap_status.available = false;
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
account_id: result.account.id,
|
|
143
|
-
session_options
|
|
144
|
-
});
|
|
169
|
+
// the session was minted in the transaction; its cookie rides the
|
|
170
|
+
// success
|
|
171
|
+
const set_cookie = session_cookie_header(result.session_cookie_value, session_options);
|
|
172
|
+
const { account, actor, role_grants } = result;
|
|
145
173
|
if (on_bootstrap) {
|
|
146
174
|
try {
|
|
147
|
-
await on_bootstrap(
|
|
175
|
+
await on_bootstrap({ account, actor, role_grants });
|
|
148
176
|
}
|
|
149
177
|
catch (err) {
|
|
150
178
|
deps.log.error(`on_bootstrap callback failed: ${to_error_message(err)}`);
|
|
@@ -152,21 +180,15 @@ export const create_bootstrap_route_specs = (deps, options) => {
|
|
|
152
180
|
}
|
|
153
181
|
await deps.audit.emit(route, {
|
|
154
182
|
event_type: 'bootstrap',
|
|
155
|
-
actor_id:
|
|
156
|
-
account_id:
|
|
157
|
-
ip:
|
|
183
|
+
actor_id: actor.id,
|
|
184
|
+
account_id: account.id,
|
|
185
|
+
ip: route.client_ip
|
|
158
186
|
});
|
|
159
|
-
// CRITICAL: If token file deletion failed, throw to force operator attention.
|
|
160
|
-
// All success work (session, on_bootstrap, audit) has completed above.
|
|
161
|
-
// The error response alerts the operator to delete the token file manually.
|
|
162
|
-
if (!result.token_file_deleted) {
|
|
163
|
-
throw new Error(`Bootstrap succeeded but token file was not deleted at ${token_path}. Delete it manually and log in.`);
|
|
164
|
-
}
|
|
165
187
|
return route_ok({
|
|
166
188
|
ok: true,
|
|
167
|
-
account: { id:
|
|
168
|
-
actor: { id:
|
|
169
|
-
});
|
|
189
|
+
account: { id: account.id, username: account.username },
|
|
190
|
+
actor: { id: actor.id }
|
|
191
|
+
}, { set_cookie: [set_cookie] });
|
|
170
192
|
}
|
|
171
193
|
finally {
|
|
172
194
|
ip_reserved.reservation.release();
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Narrow filesystem seam for bootstrap token I/O.
|
|
3
|
+
*
|
|
4
|
+
* Bootstrap reads a one-shot token file on each request and burns it inside
|
|
5
|
+
* the transaction the token authorized, just before the commit. The store
|
|
6
|
+
* scopes to exactly those two operations so tests can swap in an in-memory
|
|
7
|
+
* one without reaching for a general filesystem abstraction. Twin of the Rust
|
|
8
|
+
* spine's `fuz_auth::BootstrapTokenStore`.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
import type { FsSecureBurnDeps, FsSecureReadDeps } from '../runtime/deps.js';
|
|
13
|
+
import type { BurnOutcome } from '../runtime/secure_file.js';
|
|
14
|
+
/**
|
|
15
|
+
* Two-operation seam for the one-shot bootstrap token file.
|
|
16
|
+
*
|
|
17
|
+
* Implementations must not trim or normalize the bytes `read_token` returns —
|
|
18
|
+
* the caller strips one trailing LF and compares in constant time.
|
|
19
|
+
*
|
|
20
|
+
* Twin of the Rust `BootstrapTokenStore` trait, which has no `path`: the Rust
|
|
21
|
+
* boot check (`is_bootstrap_available`) takes the path itself, while
|
|
22
|
+
* `check_bootstrap_status` reads through this store and names the file in its
|
|
23
|
+
* log lines from here.
|
|
24
|
+
*/
|
|
25
|
+
export interface BootstrapTokenStore {
|
|
26
|
+
/** Where the token lives, named in operator log lines — never the token itself. */
|
|
27
|
+
readonly path: string;
|
|
28
|
+
/**
|
|
29
|
+
* Read the raw token bytes.
|
|
30
|
+
*
|
|
31
|
+
* @throws Error when the file is missing or refused
|
|
32
|
+
*/
|
|
33
|
+
read_token: () => Promise<Uint8Array>;
|
|
34
|
+
/**
|
|
35
|
+
* Burn the token so it can never be presented again. Required, not
|
|
36
|
+
* best-effort: `bootstrap_account` calls it last inside the bootstrap
|
|
37
|
+
* transaction, and a throw rolls the bootstrap back
|
|
38
|
+
* (`token_file_undeletable`). `'already_gone'` — nothing was there — is a
|
|
39
|
+
* burn: the token can't be presented either way.
|
|
40
|
+
*
|
|
41
|
+
* @throws Error when the token can't be durably removed
|
|
42
|
+
*/
|
|
43
|
+
burn_token: () => Promise<BurnOutcome>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The production `BootstrapTokenStore`: the hardened secret read
|
|
47
|
+
* (`read_secure_file` — a symlinked, non-regular, group/other-readable,
|
|
48
|
+
* multiply-linked, or oversized file is refused, never read) and the durable
|
|
49
|
+
* burn (`burn_secure_file` — unlink, then fsync the directory). The read
|
|
50
|
+
* alone of the runtime's secure reads asks for a single link
|
|
51
|
+
* (`BOOTSTRAP_TOKEN_READ_OPTIONS`): both of bootstrap's reads, the boot check
|
|
52
|
+
* (`check_bootstrap_status`) and the request's, go through it. Twin of the
|
|
53
|
+
* Rust `FileBootstrapTokenStore`.
|
|
54
|
+
*
|
|
55
|
+
* @param deps - the runtime's secure read and burn (`create_node_runtime()` satisfies both)
|
|
56
|
+
* @param path - the bootstrap token file, `FUZ_BOOTSTRAP_TOKEN_PATH`
|
|
57
|
+
* @returns a store over the file at `path`
|
|
58
|
+
*/
|
|
59
|
+
export declare const create_file_bootstrap_token_store: (deps: FsSecureReadDeps & FsSecureBurnDeps, path: string) => BootstrapTokenStore;
|
|
60
|
+
//# sourceMappingURL=bootstrap_token_store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootstrap_token_store.d.ts","sourceRoot":"","sources":["../../src/lib/auth/bootstrap_token_store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC7E,OAAO,KAAK,EAAE,WAAW,EAAqB,MAAM,2BAA2B,CAAC;AAEhF;;;;;;;;;;GAUG;AACH,MAAM,WAAW,mBAAmB;IACnC,mFAAmF;IACnF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,UAAU,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;IACtC;;;;;;;;OAQG;IACH,UAAU,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC;CACvC;AAYD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,iCAAiC,GAC7C,MAAM,gBAAgB,GAAG,gBAAgB,EACzC,MAAM,MAAM,KACV,mBAID,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Narrow filesystem seam for bootstrap token I/O.
|
|
3
|
+
*
|
|
4
|
+
* Bootstrap reads a one-shot token file on each request and burns it inside
|
|
5
|
+
* the transaction the token authorized, just before the commit. The store
|
|
6
|
+
* scopes to exactly those two operations so tests can swap in an in-memory
|
|
7
|
+
* one without reaching for a general filesystem abstraction. Twin of the Rust
|
|
8
|
+
* spine's `fuz_auth::BootstrapTokenStore`.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* The secure read's strictness for the bootstrap token: a link count of 1,
|
|
14
|
+
* beside the default checks, so the burn's unlink leaves no other name the
|
|
15
|
+
* token can still be read under. Twin of the Rust
|
|
16
|
+
* `BOOTSTRAP_TOKEN_READ_OPTIONS`.
|
|
17
|
+
*/
|
|
18
|
+
const BOOTSTRAP_TOKEN_READ_OPTIONS = Object.freeze({
|
|
19
|
+
require_single_link: true
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* The production `BootstrapTokenStore`: the hardened secret read
|
|
23
|
+
* (`read_secure_file` — a symlinked, non-regular, group/other-readable,
|
|
24
|
+
* multiply-linked, or oversized file is refused, never read) and the durable
|
|
25
|
+
* burn (`burn_secure_file` — unlink, then fsync the directory). The read
|
|
26
|
+
* alone of the runtime's secure reads asks for a single link
|
|
27
|
+
* (`BOOTSTRAP_TOKEN_READ_OPTIONS`): both of bootstrap's reads, the boot check
|
|
28
|
+
* (`check_bootstrap_status`) and the request's, go through it. Twin of the
|
|
29
|
+
* Rust `FileBootstrapTokenStore`.
|
|
30
|
+
*
|
|
31
|
+
* @param deps - the runtime's secure read and burn (`create_node_runtime()` satisfies both)
|
|
32
|
+
* @param path - the bootstrap token file, `FUZ_BOOTSTRAP_TOKEN_PATH`
|
|
33
|
+
* @returns a store over the file at `path`
|
|
34
|
+
*/
|
|
35
|
+
export const create_file_bootstrap_token_store = (deps, path) => ({
|
|
36
|
+
path,
|
|
37
|
+
read_token: () => deps.read_secure_file(path, BOOTSTRAP_TOKEN_READ_OPTIONS),
|
|
38
|
+
burn_token: () => deps.burn_secure_file(path)
|
|
39
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The grammar of the three credential headers — the session cookie in
|
|
3
|
+
* `Cookie`, the API token in `Authorization: Bearer`, the daemon token in
|
|
4
|
+
* `X-Daemon-Token` — as pure readers over header lines.
|
|
5
|
+
*
|
|
6
|
+
* One spelling per credential, the Rust spine's `fuz_auth::credential_headers`
|
|
7
|
+
* reading the same one: a value either reads exactly, or it is not that
|
|
8
|
+
* credential. Nothing is decoded, unquoted, or repaired — a lenient side
|
|
9
|
+
* would authenticate a request the other refuses. The shared table
|
|
10
|
+
* `testing/cross_backend/credential_conformance.json` holds both to the same
|
|
11
|
+
* rows.
|
|
12
|
+
*
|
|
13
|
+
* Each reader takes the header's lines — one field value per header line, in
|
|
14
|
+
* the order sent, outer SP and HTAB already stripped (`get_header_lines` of
|
|
15
|
+
* `http/header_lines.ts` on a request) — so "sent twice" is something a reader
|
|
16
|
+
* can see and decide on.
|
|
17
|
+
*
|
|
18
|
+
* Hono-free: the middleware legs call these, and so does the
|
|
19
|
+
* `_testing_credential_read` action.
|
|
20
|
+
*
|
|
21
|
+
* @module
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* Read the session cookie's value out of the request's `Cookie` lines.
|
|
25
|
+
*
|
|
26
|
+
* Several `Cookie` lines read as one value joined with `; ` — what Node and
|
|
27
|
+
* Bun hand a handler, and RFC 9113's rule for HTTP/2 cookie crumbs. The value
|
|
28
|
+
* is split on `;`, each pair is stripped of SP and HTAB at both ends (no other
|
|
29
|
+
* byte — not the U+00A0 a `0xA0` arrives as), and the first pair that begins
|
|
30
|
+
* with exactly `<cookie_name>=` wins. Its value is the rest of the pair,
|
|
31
|
+
* verbatim: not percent-decoded, not unquoted, whitespace after the `=` kept.
|
|
32
|
+
* A first pair that will not verify is not skipped for a later one.
|
|
33
|
+
*
|
|
34
|
+
* A pair with an empty value (`name=`) is present, and reads `''` — an
|
|
35
|
+
* invalid cookie to whatever verifies it, not an absent one.
|
|
36
|
+
*
|
|
37
|
+
* @param cookie_lines - the `Cookie` header's lines
|
|
38
|
+
* @param cookie_name - the session cookie's name
|
|
39
|
+
* @returns the cookie's value as sent, or `null` when no pair names it
|
|
40
|
+
*/
|
|
41
|
+
export declare const read_session_cookie_value: (cookie_lines: ReadonlyArray<string>, cookie_name: string) => string | null;
|
|
42
|
+
/**
|
|
43
|
+
* Read the API token out of the request's `Authorization` lines.
|
|
44
|
+
*
|
|
45
|
+
* The header must be exactly one line: the scheme `Bearer` in any ASCII case,
|
|
46
|
+
* one SP, and a value `is_api_token_shaped` accepts — nothing before, between,
|
|
47
|
+
* or after. A header sent twice is discarded whatever its lines hold, never
|
|
48
|
+
* resolved to one of them.
|
|
49
|
+
*
|
|
50
|
+
* A runtime that shows no per-line view (`get_header_lines`) hands repeated
|
|
51
|
+
* lines over as one, joined with `, `. No token holds a comma, so the join
|
|
52
|
+
* fails the shape and is discarded as the repeat it is; a lone line that
|
|
53
|
+
* happens to hold `, ` reads the same on both spines.
|
|
54
|
+
*
|
|
55
|
+
* @param authorization_lines - the `Authorization` header's lines
|
|
56
|
+
* @returns the token to look up, or `null` when the header carries none
|
|
57
|
+
*/
|
|
58
|
+
export declare const read_bearer_token: (authorization_lines: ReadonlyArray<string>) => string | null;
|
|
59
|
+
/**
|
|
60
|
+
* Read the daemon token out of the request's `X-Daemon-Token` lines.
|
|
61
|
+
*
|
|
62
|
+
* The header must be exactly one line holding a value
|
|
63
|
+
* `is_daemon_token_shaped` accepts. A header sent twice is discarded — an
|
|
64
|
+
* empty second line included — and, as for `read_bearer_token`, a join with
|
|
65
|
+
* `, ` fails the shape.
|
|
66
|
+
*
|
|
67
|
+
* @param daemon_token_lines - the `X-Daemon-Token` header's lines
|
|
68
|
+
* @returns the token to compare, or `null` when the header carries none
|
|
69
|
+
*/
|
|
70
|
+
export declare const read_daemon_token: (daemon_token_lines: ReadonlyArray<string>) => string | null;
|
|
71
|
+
//# sourceMappingURL=credential_headers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credential_headers.d.ts","sourceRoot":"","sources":["../../src/lib/auth/credential_headers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AASH;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,yBAAyB,GACrC,cAAc,aAAa,CAAC,MAAM,CAAC,EACnC,aAAa,MAAM,KACjB,MAAM,GAAG,IAWX,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,iBAAiB,GAAI,qBAAqB,aAAa,CAAC,MAAM,CAAC,KAAG,MAAM,GAAG,IAMvF,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iBAAiB,GAAI,oBAAoB,aAAa,CAAC,MAAM,CAAC,KAAG,MAAM,GAAG,IAItF,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The grammar of the three credential headers — the session cookie in
|
|
3
|
+
* `Cookie`, the API token in `Authorization: Bearer`, the daemon token in
|
|
4
|
+
* `X-Daemon-Token` — as pure readers over header lines.
|
|
5
|
+
*
|
|
6
|
+
* One spelling per credential, the Rust spine's `fuz_auth::credential_headers`
|
|
7
|
+
* reading the same one: a value either reads exactly, or it is not that
|
|
8
|
+
* credential. Nothing is decoded, unquoted, or repaired — a lenient side
|
|
9
|
+
* would authenticate a request the other refuses. The shared table
|
|
10
|
+
* `testing/cross_backend/credential_conformance.json` holds both to the same
|
|
11
|
+
* rows.
|
|
12
|
+
*
|
|
13
|
+
* Each reader takes the header's lines — one field value per header line, in
|
|
14
|
+
* the order sent, outer SP and HTAB already stripped (`get_header_lines` of
|
|
15
|
+
* `http/header_lines.ts` on a request) — so "sent twice" is something a reader
|
|
16
|
+
* can see and decide on.
|
|
17
|
+
*
|
|
18
|
+
* Hono-free: the middleware legs call these, and so does the
|
|
19
|
+
* `_testing_credential_read` action.
|
|
20
|
+
*
|
|
21
|
+
* @module
|
|
22
|
+
*/
|
|
23
|
+
import { trim_optional_whitespace } from '../http/header_lines.js';
|
|
24
|
+
import { is_api_token_shaped } from './api_token.js';
|
|
25
|
+
import { is_daemon_token_shaped } from './daemon_token.js';
|
|
26
|
+
/** The `Authorization` scheme of an API token, with the one SP that follows it. */
|
|
27
|
+
const BEARER_PREFIX = 'bearer ';
|
|
28
|
+
/**
|
|
29
|
+
* Read the session cookie's value out of the request's `Cookie` lines.
|
|
30
|
+
*
|
|
31
|
+
* Several `Cookie` lines read as one value joined with `; ` — what Node and
|
|
32
|
+
* Bun hand a handler, and RFC 9113's rule for HTTP/2 cookie crumbs. The value
|
|
33
|
+
* is split on `;`, each pair is stripped of SP and HTAB at both ends (no other
|
|
34
|
+
* byte — not the U+00A0 a `0xA0` arrives as), and the first pair that begins
|
|
35
|
+
* with exactly `<cookie_name>=` wins. Its value is the rest of the pair,
|
|
36
|
+
* verbatim: not percent-decoded, not unquoted, whitespace after the `=` kept.
|
|
37
|
+
* A first pair that will not verify is not skipped for a later one.
|
|
38
|
+
*
|
|
39
|
+
* A pair with an empty value (`name=`) is present, and reads `''` — an
|
|
40
|
+
* invalid cookie to whatever verifies it, not an absent one.
|
|
41
|
+
*
|
|
42
|
+
* @param cookie_lines - the `Cookie` header's lines
|
|
43
|
+
* @param cookie_name - the session cookie's name
|
|
44
|
+
* @returns the cookie's value as sent, or `null` when no pair names it
|
|
45
|
+
*/
|
|
46
|
+
export const read_session_cookie_value = (cookie_lines, cookie_name) => {
|
|
47
|
+
const prefix = `${cookie_name}=`;
|
|
48
|
+
// walking the lines in order is reading their `; ` join: the separator
|
|
49
|
+
// holds the `;` the split is on
|
|
50
|
+
for (const line of cookie_lines) {
|
|
51
|
+
for (const part of line.split(';')) {
|
|
52
|
+
const pair = trim_optional_whitespace(part);
|
|
53
|
+
if (pair.startsWith(prefix))
|
|
54
|
+
return pair.slice(prefix.length);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Read the API token out of the request's `Authorization` lines.
|
|
61
|
+
*
|
|
62
|
+
* The header must be exactly one line: the scheme `Bearer` in any ASCII case,
|
|
63
|
+
* one SP, and a value `is_api_token_shaped` accepts — nothing before, between,
|
|
64
|
+
* or after. A header sent twice is discarded whatever its lines hold, never
|
|
65
|
+
* resolved to one of them.
|
|
66
|
+
*
|
|
67
|
+
* A runtime that shows no per-line view (`get_header_lines`) hands repeated
|
|
68
|
+
* lines over as one, joined with `, `. No token holds a comma, so the join
|
|
69
|
+
* fails the shape and is discarded as the repeat it is; a lone line that
|
|
70
|
+
* happens to hold `, ` reads the same on both spines.
|
|
71
|
+
*
|
|
72
|
+
* @param authorization_lines - the `Authorization` header's lines
|
|
73
|
+
* @returns the token to look up, or `null` when the header carries none
|
|
74
|
+
*/
|
|
75
|
+
export const read_bearer_token = (authorization_lines) => {
|
|
76
|
+
if (authorization_lines.length !== 1)
|
|
77
|
+
return null;
|
|
78
|
+
const value = authorization_lines[0];
|
|
79
|
+
if (value.slice(0, BEARER_PREFIX.length).toLowerCase() !== BEARER_PREFIX)
|
|
80
|
+
return null;
|
|
81
|
+
const token = value.slice(BEARER_PREFIX.length);
|
|
82
|
+
return is_api_token_shaped(token) ? token : null;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Read the daemon token out of the request's `X-Daemon-Token` lines.
|
|
86
|
+
*
|
|
87
|
+
* The header must be exactly one line holding a value
|
|
88
|
+
* `is_daemon_token_shaped` accepts. A header sent twice is discarded — an
|
|
89
|
+
* empty second line included — and, as for `read_bearer_token`, a join with
|
|
90
|
+
* `, ` fails the shape.
|
|
91
|
+
*
|
|
92
|
+
* @param daemon_token_lines - the `X-Daemon-Token` header's lines
|
|
93
|
+
* @returns the token to compare, or `null` when the header carries none
|
|
94
|
+
*/
|
|
95
|
+
export const read_daemon_token = (daemon_token_lines) => {
|
|
96
|
+
if (daemon_token_lines.length !== 1)
|
|
97
|
+
return null;
|
|
98
|
+
const value = daemon_token_lines[0];
|
|
99
|
+
return is_daemon_token_shaped(value) ? value : null;
|
|
100
|
+
};
|
|
@@ -8,7 +8,19 @@
|
|
|
8
8
|
* @module
|
|
9
9
|
*/
|
|
10
10
|
import { type Infer } from '@fuzdev/fuz_schema/schema.ts';
|
|
11
|
-
/**
|
|
11
|
+
/** Regex for a daemon token: exactly 43 base64url characters (256 bits). */
|
|
12
|
+
export declare const DAEMON_TOKEN_REGEX: RegExp;
|
|
13
|
+
/**
|
|
14
|
+
* Whether `raw` has the shape of a daemon token — the daemon leg's precheck,
|
|
15
|
+
* ahead of the constant-time compare, so an off-form value is discarded
|
|
16
|
+
* without one. A `true` says nothing about whether the token is the current
|
|
17
|
+
* one. Twin of the Rust spine's `is_daemon_token_shaped`.
|
|
18
|
+
*
|
|
19
|
+
* @param raw - the value of an `X-Daemon-Token` line
|
|
20
|
+
* @returns `true` when `raw` matches `DAEMON_TOKEN_REGEX`
|
|
21
|
+
*/
|
|
22
|
+
export declare const is_daemon_token_shaped: (raw: string) => boolean;
|
|
23
|
+
/** Daemon token format, a `@fuzdev/fuz_schema` schema over `DAEMON_TOKEN_REGEX`. */
|
|
12
24
|
export declare const DaemonToken: import("@fuzdev/fuz_schema/schema.ts").PipeSchema<string, import("@fuzdev/fuz_schema/schema.ts").StringSchema>;
|
|
13
25
|
export type DaemonToken = Infer<typeof DaemonToken>;
|
|
14
26
|
/** The `X-Daemon-Token` header name. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"daemon_token.d.ts","sourceRoot":"","sources":["../../src/lib/auth/daemon_token.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAgC,KAAK,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAIxF,
|
|
1
|
+
{"version":3,"file":"daemon_token.d.ts","sourceRoot":"","sources":["../../src/lib/auth/daemon_token.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAgC,KAAK,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAIxF,4EAA4E;AAC5E,eAAO,MAAM,kBAAkB,QAAwB,CAAC;AAExD;;;;;;;;GAQG;AACH,eAAO,MAAM,sBAAsB,GAAI,KAAK,MAAM,KAAG,OAAuC,CAAC;AAE7F,oFAAoF;AACpF,eAAO,MAAM,WAAW,gHAGvB,CAAC;AACF,MAAM,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAEpD,wCAAwC;AACxC,eAAO,MAAM,mBAAmB,mBAAmB,CAAC;AAEpD;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAChC,2BAA2B;IAC3B,aAAa,EAAE,MAAM,CAAC;IACtB,wFAAwF;IACxF,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,uCAAuC;IACvC,UAAU,EAAE,IAAI,CAAC;IACjB,iFAAiF;IACjF,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC;AAED;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,QAAO,MAExC,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,qBAAqB,GAAI,UAAU,MAAM,EAAE,OAAO,gBAAgB,KAAG,OAgBjF,CAAC"}
|
|
@@ -10,8 +10,20 @@
|
|
|
10
10
|
import { timingSafeEqual } from 'node:crypto';
|
|
11
11
|
import { message, pipe, regex, string } from '@fuzdev/fuz_schema/schema.ts';
|
|
12
12
|
import { generate_random_base64url } from '../crypto.js';
|
|
13
|
-
/**
|
|
14
|
-
export const
|
|
13
|
+
/** Regex for a daemon token: exactly 43 base64url characters (256 bits). */
|
|
14
|
+
export const DAEMON_TOKEN_REGEX = /^[A-Za-z0-9_-]{43}$/;
|
|
15
|
+
/**
|
|
16
|
+
* Whether `raw` has the shape of a daemon token — the daemon leg's precheck,
|
|
17
|
+
* ahead of the constant-time compare, so an off-form value is discarded
|
|
18
|
+
* without one. A `true` says nothing about whether the token is the current
|
|
19
|
+
* one. Twin of the Rust spine's `is_daemon_token_shaped`.
|
|
20
|
+
*
|
|
21
|
+
* @param raw - the value of an `X-Daemon-Token` line
|
|
22
|
+
* @returns `true` when `raw` matches `DAEMON_TOKEN_REGEX`
|
|
23
|
+
*/
|
|
24
|
+
export const is_daemon_token_shaped = (raw) => DAEMON_TOKEN_REGEX.test(raw);
|
|
25
|
+
/** Daemon token format, a `@fuzdev/fuz_schema` schema over `DAEMON_TOKEN_REGEX`. */
|
|
26
|
+
export const DaemonToken = pipe(string, message(regex(DAEMON_TOKEN_REGEX), 'Invalid daemon token format'));
|
|
15
27
|
/** The `X-Daemon-Token` header name. */
|
|
16
28
|
export const DAEMON_TOKEN_HEADER = 'X-Daemon-Token';
|
|
17
29
|
/**
|
|
@@ -41,19 +41,18 @@ export declare const resolve_keeper_account_id: (deps: QueryDeps) => Promise<str
|
|
|
41
41
|
* `RESOLVED_AUTH_KEY` on entry, so a layer mounted before the credential legs
|
|
42
42
|
* cannot pre-set an identity that every leg would then skip past.
|
|
43
43
|
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* -
|
|
44
|
+
* Reads the `X-Daemon-Token` header's lines through `read_daemon_token`.
|
|
45
|
+
* Behavior:
|
|
46
|
+
* - No header, a malformed value (fails `is_daemon_token_shaped`), or the
|
|
47
|
+
* header sent as more than one line: soft-fail discard (pass through, not
|
|
48
|
+
* 401) — mirrors the bearer guard and the Rust spine's `resolve.rs`
|
|
49
|
+
* (`None`). Downstream a daemon-gated action returns
|
|
50
|
+
* `credential_type_required`; a public action proceeds anonymous.
|
|
51
|
+
* - A shaped token + `Origin` / `Referer` present: discard the credential
|
|
47
52
|
* (browser context) and pass through — daemon tokens are loopback-only and
|
|
48
53
|
* never carry an `Origin` in production, so a header-bearing request is not
|
|
49
|
-
* a legitimate daemon caller.
|
|
50
|
-
*
|
|
51
|
-
* (not a hard fail). Silent on the wire (anti-enumeration); in `DEV` only,
|
|
52
|
-
* sets `X-Fuz-Auth-Debug: daemon_token_discarded_browser_context`.
|
|
53
|
-
* - Header present + malformed (fails `DaemonToken`): soft-fail discard (pass through,
|
|
54
|
-
* not 401) — mirrors the bearer guard and the Rust spine's `resolve.rs`
|
|
55
|
-
* (`None`). Downstream a daemon-gated action returns `credential_type_required`;
|
|
56
|
-
* a public action proceeds anonymous.
|
|
54
|
+
* a legitimate daemon caller. Silent on the wire (anti-enumeration); in
|
|
55
|
+
* `DEV` only, sets `X-Fuz-Auth-Debug: daemon_token_discarded_browser_context`.
|
|
57
56
|
* - Header present + invalid value (not the current/previous token): soft-fail
|
|
58
57
|
* discard (pass through, not 401) — same downstream behavior.
|
|
59
58
|
* - Header present + valid + `keeper_account_id` null (still pre-bootstrap
|