@fuzdev/fuz_app 0.180.0 → 0.181.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/CLAUDE.md +14 -14
- package/dist/actions/action_rpc.d.ts +14 -5
- package/dist/actions/action_rpc.d.ts.map +1 -1
- package/dist/actions/action_rpc.js +53 -46
- package/dist/actions/action_types.d.ts +15 -12
- package/dist/actions/action_types.d.ts.map +1 -1
- package/dist/actions/perform_action.d.ts +4 -4
- package/dist/actions/perform_action.d.ts.map +1 -1
- package/dist/actions/perform_action.js +6 -6
- package/dist/actions/register_action_ws.d.ts +6 -2
- package/dist/actions/register_action_ws.d.ts.map +1 -1
- package/dist/actions/register_action_ws.js +14 -3
- package/dist/actions/ws_socket_session.js +1 -1
- package/dist/auth/CLAUDE.md +36 -30
- package/dist/auth/account_actions.d.ts.map +1 -1
- package/dist/auth/account_actions.js +18 -1
- package/dist/auth/account_queries.d.ts +69 -0
- package/dist/auth/account_queries.d.ts.map +1 -1
- package/dist/auth/account_queries.js +82 -0
- package/dist/auth/account_route_schema.d.ts +26 -16
- package/dist/auth/account_route_schema.d.ts.map +1 -1
- package/dist/auth/account_route_schema.js +10 -24
- package/dist/auth/account_routes.d.ts +4 -6
- package/dist/auth/account_routes.d.ts.map +1 -1
- package/dist/auth/account_routes.js +86 -66
- package/dist/auth/admin_actions.d.ts.map +1 -1
- package/dist/auth/admin_actions.js +63 -14
- package/dist/auth/api_token_queries.d.ts +16 -7
- package/dist/auth/api_token_queries.d.ts.map +1 -1
- package/dist/auth/api_token_queries.js +18 -18
- package/dist/auth/audit_log_route_schema.d.ts +1 -1
- package/dist/auth/audit_log_route_schema.d.ts.map +1 -1
- package/dist/auth/audit_log_routes.d.ts +1 -1
- package/dist/auth/audit_log_routes.d.ts.map +1 -1
- package/dist/auth/audit_log_routes.js +10 -12
- package/dist/auth/audit_log_schema.js +4 -4
- package/dist/auth/bearer_auth.d.ts +4 -3
- package/dist/auth/bearer_auth.d.ts.map +1 -1
- package/dist/auth/bearer_auth.js +35 -31
- package/dist/auth/bootstrap_account.d.ts +65 -37
- package/dist/auth/bootstrap_account.d.ts.map +1 -1
- package/dist/auth/bootstrap_account.js +115 -66
- package/dist/auth/bootstrap_route_schema.d.ts +6 -2
- package/dist/auth/bootstrap_route_schema.d.ts.map +1 -1
- package/dist/auth/bootstrap_route_schema.js +7 -2
- package/dist/auth/bootstrap_routes.d.ts +50 -33
- package/dist/auth/bootstrap_routes.d.ts.map +1 -1
- package/dist/auth/bootstrap_routes.js +109 -87
- package/dist/auth/bootstrap_token_store.d.ts +60 -0
- package/dist/auth/bootstrap_token_store.d.ts.map +1 -0
- package/dist/auth/bootstrap_token_store.js +39 -0
- package/dist/auth/credential_headers.d.ts +71 -0
- package/dist/auth/credential_headers.d.ts.map +1 -0
- package/dist/auth/credential_headers.js +100 -0
- package/dist/auth/daemon_token.d.ts +13 -1
- package/dist/auth/daemon_token.d.ts.map +1 -1
- package/dist/auth/daemon_token.js +14 -2
- package/dist/auth/daemon_token_middleware.d.ts +10 -11
- package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
- package/dist/auth/daemon_token_middleware.js +27 -29
- package/dist/auth/deps.d.ts +0 -11
- package/dist/auth/deps.d.ts.map +1 -1
- package/dist/auth/invite_queries.d.ts +18 -0
- package/dist/auth/invite_queries.d.ts.map +1 -1
- package/dist/auth/invite_queries.js +24 -0
- package/dist/auth/request_context.d.ts +26 -5
- package/dist/auth/request_context.d.ts.map +1 -1
- package/dist/auth/request_context.js +17 -10
- package/dist/auth/role_grant_offer_action_specs.d.ts +1 -1
- package/dist/auth/role_grant_offer_action_specs.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_action_specs.js +3 -2
- package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_actions.js +37 -14
- package/dist/auth/role_grant_offer_ddl.d.ts +7 -1
- package/dist/auth/role_grant_offer_ddl.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_ddl.js +9 -2
- package/dist/auth/role_grant_offer_queries.d.ts +56 -3
- package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_queries.js +93 -8
- package/dist/auth/role_grant_queries.d.ts +7 -0
- package/dist/auth/role_grant_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_queries.js +8 -0
- package/dist/auth/session_cookie.d.ts +105 -25
- package/dist/auth/session_cookie.d.ts.map +1 -1
- package/dist/auth/session_cookie.js +124 -15
- package/dist/auth/session_middleware.d.ts +83 -54
- package/dist/auth/session_middleware.d.ts.map +1 -1
- package/dist/auth/session_middleware.js +92 -66
- package/dist/auth/session_queries.d.ts +64 -4
- package/dist/auth/session_queries.d.ts.map +1 -1
- package/dist/auth/session_queries.js +53 -4
- package/dist/auth/signup_route_schema.d.ts +5 -5
- package/dist/auth/signup_route_schema.d.ts.map +1 -1
- package/dist/auth/signup_route_schema.js +4 -4
- package/dist/auth/signup_routes.d.ts.map +1 -1
- package/dist/auth/signup_routes.js +17 -14
- package/dist/auth/token_scope.d.ts +5 -7
- package/dist/auth/token_scope.d.ts.map +1 -1
- package/dist/auth/token_scope.js +5 -8
- package/dist/dev/setup.d.ts +6 -1
- package/dist/dev/setup.d.ts.map +1 -1
- package/dist/dev/setup.js +42 -34
- package/dist/hono_context.d.ts +21 -0
- package/dist/hono_context.d.ts.map +1 -1
- package/dist/hono_context.js +17 -0
- package/dist/http/CLAUDE.md +150 -43
- package/dist/http/auth_shape.d.ts +3 -3
- package/dist/http/common_routes.js +1 -1
- package/dist/http/db_routes.d.ts +4 -3
- package/dist/http/db_routes.d.ts.map +1 -1
- package/dist/http/db_routes.js +14 -14
- package/dist/http/dev_route_error_check.d.ts +6 -3
- package/dist/http/dev_route_error_check.d.ts.map +1 -1
- package/dist/http/dev_route_error_check.js +6 -3
- package/dist/http/dev_set_cookie_check.d.ts +53 -0
- package/dist/http/dev_set_cookie_check.d.ts.map +1 -0
- package/dist/http/dev_set_cookie_check.js +80 -0
- package/dist/http/error_schemas.d.ts +36 -1
- package/dist/http/error_schemas.d.ts.map +1 -1
- package/dist/http/error_schemas.js +39 -2
- package/dist/http/header_lines.d.ts +42 -0
- package/dist/http/header_lines.d.ts.map +1 -0
- package/dist/http/header_lines.js +80 -0
- package/dist/http/host.d.ts +12 -9
- package/dist/http/host.d.ts.map +1 -1
- package/dist/http/host.js +25 -20
- package/dist/http/origin.d.ts +7 -22
- package/dist/http/origin.d.ts.map +1 -1
- package/dist/http/origin.js +11 -25
- package/dist/http/proxy.d.ts +1 -0
- package/dist/http/proxy.d.ts.map +1 -1
- package/dist/http/proxy.js +3 -0
- package/dist/http/request_headers.d.ts +95 -0
- package/dist/http/request_headers.d.ts.map +1 -0
- package/dist/http/request_headers.js +110 -0
- package/dist/http/request_target.d.ts +134 -0
- package/dist/http/request_target.d.ts.map +1 -0
- package/dist/http/request_target.js +193 -0
- package/dist/http/route_error_check.d.ts +4 -11
- package/dist/http/route_error_check.d.ts.map +1 -1
- package/dist/http/route_error_check.js +4 -21
- package/dist/http/route_result.d.ts +127 -23
- package/dist/http/route_result.d.ts.map +1 -1
- package/dist/http/route_result.js +97 -19
- package/dist/http/route_spec.d.ts +298 -82
- package/dist/http/route_spec.d.ts.map +1 -1
- package/dist/http/route_spec.js +548 -71
- package/dist/http/simple_request.d.ts +19 -14
- package/dist/http/simple_request.d.ts.map +1 -1
- package/dist/http/simple_request.js +17 -29
- package/dist/http/surface.d.ts +2 -0
- package/dist/http/surface.d.ts.map +1 -1
- package/dist/http/surface.js +4 -1
- package/dist/realtime/outbound_budget.d.ts +1 -2
- package/dist/realtime/outbound_budget.d.ts.map +1 -1
- package/dist/realtime/outbound_budget.js +1 -2
- package/dist/realtime/sse.d.ts +47 -17
- package/dist/realtime/sse.d.ts.map +1 -1
- package/dist/realtime/sse.js +115 -93
- package/dist/realtime/sse_constants.d.ts +7 -1
- package/dist/realtime/sse_constants.d.ts.map +1 -1
- package/dist/realtime/sse_constants.js +12 -1
- package/dist/realtime/sse_registry.d.ts +3 -3
- package/dist/realtime/sse_registry.js +3 -3
- package/dist/runtime/deps.d.ts +20 -4
- package/dist/runtime/deps.d.ts.map +1 -1
- package/dist/runtime/mock.d.ts +7 -1
- package/dist/runtime/mock.d.ts.map +1 -1
- package/dist/runtime/mock.js +33 -3
- package/dist/runtime/node.d.ts.map +1 -1
- package/dist/runtime/node.js +2 -1
- package/dist/runtime/secure_file.d.ts +71 -10
- package/dist/runtime/secure_file.d.ts.map +1 -1
- package/dist/runtime/secure_file.js +91 -11
- package/dist/server/app_backend.d.ts +0 -8
- package/dist/server/app_backend.d.ts.map +1 -1
- package/dist/server/app_backend.js +1 -3
- package/dist/server/app_server.d.ts +28 -17
- package/dist/server/app_server.d.ts.map +1 -1
- package/dist/server/app_server.js +52 -34
- package/dist/server/serve_fact_route.d.ts.map +1 -1
- package/dist/server/serve_fact_route.js +49 -45
- package/dist/server/static.d.ts +20 -0
- package/dist/server/static.d.ts.map +1 -1
- package/dist/server/static.js +56 -8
- package/dist/server/unmatched_route.d.ts +42 -0
- package/dist/server/unmatched_route.d.ts.map +1 -0
- package/dist/server/unmatched_route.js +64 -0
- package/dist/testing/CLAUDE.md +404 -1200
- package/dist/testing/app_server.d.ts +3 -1
- package/dist/testing/app_server.d.ts.map +1 -1
- package/dist/testing/app_server.js +4 -10
- package/dist/testing/auth_apps.d.ts.map +1 -1
- package/dist/testing/auth_apps.js +2 -1
- package/dist/testing/cross_backend/account_lifecycle.d.ts +11 -4
- package/dist/testing/cross_backend/account_lifecycle.d.ts.map +1 -1
- package/dist/testing/cross_backend/account_lifecycle.js +277 -6
- package/dist/testing/cross_backend/build_test_backend_paths.d.ts +4 -1
- package/dist/testing/cross_backend/build_test_backend_paths.d.ts.map +1 -1
- package/dist/testing/cross_backend/build_test_backend_paths.js +1 -1
- package/dist/testing/cross_backend/capabilities.d.ts +68 -5
- package/dist/testing/cross_backend/capabilities.d.ts.map +1 -1
- package/dist/testing/cross_backend/capabilities.js +20 -4
- package/dist/testing/cross_backend/cell_gated_create.js +1 -1
- package/dist/testing/cross_backend/conformance_case.d.ts +63 -21
- package/dist/testing/cross_backend/conformance_case.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_table.d.ts +54 -12
- package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_table.js +179 -23
- package/dist/testing/cross_backend/cookie_attributes.js +1 -1
- package/dist/testing/cross_backend/create_dual_spawn_global_setup.d.ts +7 -1
- package/dist/testing/cross_backend/create_dual_spawn_global_setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/create_dual_spawn_global_setup.js +3 -3
- package/dist/testing/cross_backend/credential_conformance.d.ts +196 -0
- package/dist/testing/cross_backend/credential_conformance.d.ts.map +1 -0
- package/dist/testing/cross_backend/credential_conformance.js +296 -0
- package/dist/testing/cross_backend/credential_conformance.json +1284 -0
- package/dist/testing/cross_backend/credential_conformance_wire.d.ts +40 -0
- package/dist/testing/cross_backend/credential_conformance_wire.d.ts.map +1 -0
- package/dist/testing/cross_backend/credential_conformance_wire.js +293 -0
- package/dist/testing/cross_backend/credential_header_robustness.d.ts +1 -3
- package/dist/testing/cross_backend/credential_header_robustness.d.ts.map +1 -1
- package/dist/testing/cross_backend/credential_header_robustness.js +24 -55
- package/dist/testing/cross_backend/credential_wire.d.ts +112 -0
- package/dist/testing/cross_backend/credential_wire.d.ts.map +1 -0
- package/dist/testing/cross_backend/credential_wire.js +188 -0
- package/dist/testing/cross_backend/default_backend_configs.d.ts.map +1 -1
- package/dist/testing/cross_backend/default_backend_configs.js +22 -2
- package/dist/testing/cross_backend/default_spine_surface.js +1 -1
- package/dist/testing/cross_backend/differential.d.ts +1 -1
- package/dist/testing/cross_backend/differential.d.ts.map +1 -1
- package/dist/testing/cross_backend/differential.js +3 -2
- package/dist/testing/cross_backend/differential_normalize.d.ts +23 -6
- package/dist/testing/cross_backend/differential_normalize.d.ts.map +1 -1
- package/dist/testing/cross_backend/differential_normalize.js +11 -5
- package/dist/testing/cross_backend/full_spine_mount.d.ts +1 -0
- package/dist/testing/cross_backend/full_spine_mount.d.ts.map +1 -1
- package/dist/testing/cross_backend/full_spine_mount.js +7 -0
- package/dist/testing/cross_backend/identity_parity.d.ts.map +1 -1
- package/dist/testing/cross_backend/identity_parity.js +4 -0
- package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/in_process_setup.js +78 -4
- package/dist/testing/cross_backend/login_security.d.ts.map +1 -1
- package/dist/testing/cross_backend/login_security.js +13 -10
- package/dist/testing/cross_backend/peer_ping_ws.d.ts +1 -1
- package/dist/testing/cross_backend/peer_ping_ws.js +2 -2
- package/dist/testing/cross_backend/request_header_conformance.d.ts +174 -0
- package/dist/testing/cross_backend/request_header_conformance.d.ts.map +1 -0
- package/dist/testing/cross_backend/request_header_conformance.js +196 -0
- package/dist/testing/cross_backend/request_header_conformance.json +1158 -0
- package/dist/testing/cross_backend/request_header_conformance_wire.d.ts +39 -0
- package/dist/testing/cross_backend/request_header_conformance_wire.d.ts.map +1 -0
- package/dist/testing/cross_backend/request_header_conformance_wire.js +284 -0
- package/dist/testing/cross_backend/request_target_conformance.d.ts +298 -0
- package/dist/testing/cross_backend/request_target_conformance.d.ts.map +1 -0
- package/dist/testing/cross_backend/request_target_conformance.js +186 -0
- package/dist/testing/cross_backend/request_target_conformance.json +3765 -0
- package/dist/testing/cross_backend/request_target_conformance_wire.d.ts +32 -0
- package/dist/testing/cross_backend/request_target_conformance_wire.d.ts.map +1 -0
- package/dist/testing/cross_backend/request_target_conformance_wire.js +278 -0
- package/dist/testing/cross_backend/role_grant_offer_lifecycle.d.ts.map +1 -1
- package/dist/testing/cross_backend/role_grant_offer_lifecycle.js +173 -1
- package/dist/testing/cross_backend/role_grant_offer_notification_ws.d.ts.map +1 -1
- package/dist/testing/cross_backend/role_grant_offer_notification_ws.js +2 -1
- package/dist/testing/cross_backend/rpc_adversarial.d.ts +6 -4
- package/dist/testing/cross_backend/rpc_adversarial.d.ts.map +1 -1
- package/dist/testing/cross_backend/rpc_adversarial.js +5 -2
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts +6 -7
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
- package/dist/testing/cross_backend/rust_spine_consumer_surface.js +4 -5
- package/dist/testing/cross_backend/session_cap.d.ts.map +1 -1
- package/dist/testing/cross_backend/session_cap.js +56 -29
- package/dist/testing/cross_backend/session_cookie_effect.d.ts +43 -0
- package/dist/testing/cross_backend/session_cookie_effect.d.ts.map +1 -0
- package/dist/testing/cross_backend/session_cookie_effect.js +103 -0
- package/dist/testing/cross_backend/session_login.d.ts +24 -0
- package/dist/testing/cross_backend/session_login.d.ts.map +1 -0
- package/dist/testing/cross_backend/session_login.js +31 -0
- package/dist/testing/cross_backend/setup.d.ts +117 -0
- package/dist/testing/cross_backend/setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/setup.js +193 -9
- package/dist/testing/cross_backend/simple_request.d.ts.map +1 -1
- package/dist/testing/cross_backend/simple_request.js +5 -0
- package/dist/testing/cross_backend/spine_suites.d.ts +9 -1
- package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
- package/dist/testing/cross_backend/spine_suites.js +88 -5
- package/dist/testing/cross_backend/spine_surface_constants.d.ts +1 -1
- package/dist/testing/cross_backend/spine_surface_constants.d.ts.map +1 -1
- package/dist/testing/cross_backend/spine_surface_constants.js +1 -0
- package/dist/testing/cross_backend/sse_round_trip.d.ts +8 -5
- package/dist/testing/cross_backend/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/cross_backend/sse_round_trip.js +205 -64
- package/dist/testing/cross_backend/testing_backdoor.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_backdoor.js +5 -2
- package/dist/testing/cross_backend/testing_credential_read.d.ts +165 -0
- package/dist/testing/cross_backend/testing_credential_read.d.ts.map +1 -0
- package/dist/testing/cross_backend/testing_credential_read.js +175 -0
- package/dist/testing/cross_backend/testing_reset_actions.d.ts +19 -0
- package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_reset_actions.js +22 -6
- package/dist/testing/cross_backend/token_lifetime.d.ts.map +1 -1
- package/dist/testing/cross_backend/token_lifetime.js +58 -2
- package/dist/testing/cross_backend/transport_composition.d.ts +2 -4
- package/dist/testing/cross_backend/transport_composition.d.ts.map +1 -1
- package/dist/testing/cross_backend/transport_composition.js +13 -10
- package/dist/testing/cross_backend/ts_spine_backend_config.d.ts.map +1 -1
- package/dist/testing/cross_backend/ts_spine_backend_config.js +5 -3
- package/dist/testing/cross_backend/ws_endpoint.d.ts +11 -1
- package/dist/testing/cross_backend/ws_endpoint.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_endpoint.js +19 -2
- package/dist/testing/cross_backend/ws_role_gated.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_role_gated.js +2 -3
- package/dist/testing/cross_backend/ws_round_trip.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_round_trip.js +28 -12
- package/dist/testing/cross_backend/xfail.d.ts +44 -11
- package/dist/testing/cross_backend/xfail.d.ts.map +1 -1
- package/dist/testing/cross_backend/xfail.js +68 -23
- package/dist/testing/data_exposure.d.ts.map +1 -1
- package/dist/testing/data_exposure.js +4 -3
- package/dist/testing/integration.d.ts +1 -2
- package/dist/testing/integration.d.ts.map +1 -1
- package/dist/testing/integration.js +14 -8
- package/dist/testing/integration_helpers.d.ts +50 -3
- package/dist/testing/integration_helpers.d.ts.map +1 -1
- package/dist/testing/integration_helpers.js +87 -9
- package/dist/testing/middleware.d.ts +2 -0
- package/dist/testing/middleware.d.ts.map +1 -1
- package/dist/testing/middleware.js +9 -2
- package/dist/testing/round_trip.d.ts +6 -2
- package/dist/testing/round_trip.d.ts.map +1 -1
- package/dist/testing/round_trip.js +17 -6
- package/dist/testing/rpc_envelope_cases.d.ts.map +1 -1
- package/dist/testing/rpc_envelope_cases.js +7 -0
- package/dist/testing/rpc_helpers.d.ts +4 -2
- package/dist/testing/rpc_helpers.d.ts.map +1 -1
- package/dist/testing/rpc_helpers.js +6 -1
- package/dist/testing/rpc_round_trip.d.ts +13 -2
- package/dist/testing/rpc_round_trip.d.ts.map +1 -1
- package/dist/testing/rpc_round_trip.js +25 -6
- package/dist/testing/schema_generators.d.ts +2 -2
- package/dist/testing/schema_generators.d.ts.map +1 -1
- package/dist/testing/schema_generators.js +4 -4
- package/dist/testing/stubs.d.ts +2 -2
- package/dist/testing/stubs.d.ts.map +1 -1
- package/dist/testing/stubs.js +8 -8
- package/dist/testing/transports/fetch_transport.d.ts +6 -3
- package/dist/testing/transports/fetch_transport.d.ts.map +1 -1
- package/dist/testing/transports/fetch_transport.js +31 -19
- package/dist/testing/transports/raw_http.d.ts +61 -1
- package/dist/testing/transports/raw_http.d.ts.map +1 -1
- package/dist/testing/transports/raw_http.js +61 -1
- package/dist/testing/transports/ws_raw_client.d.ts +20 -0
- package/dist/testing/transports/ws_raw_client.d.ts.map +1 -1
- package/dist/testing/transports/ws_raw_client.js +10 -4
- package/dist/testing/transports/ws_transport.d.ts +21 -1
- package/dist/testing/transports/ws_transport.d.ts.map +1 -1
- package/dist/testing/transports/ws_transport.js +58 -20
- package/package.json +1 -1
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The DEV-only `Set-Cookie` check: an outer middleware that logs a response
|
|
3
|
+
* which does not lead with the `Set-Cookie` line a middleware put on the
|
|
4
|
+
* context for every response.
|
|
5
|
+
*
|
|
6
|
+
* A middleware that writes a line on the context's prepared headers — the
|
|
7
|
+
* session middleware's clear of a stale cookie — records it under
|
|
8
|
+
* `EXPECTED_FIRST_SET_COOKIE_KEY`. Every response built through the context
|
|
9
|
+
* then carries it first: every route result, which the spine emits there,
|
|
10
|
+
* and every middleware and catch layer answering with `c.json` or `c.text`.
|
|
11
|
+
* A response built past the context does not — a consumer's
|
|
12
|
+
* `post_route_middleware`, a `transform_middleware` layer, or a raw Hono route
|
|
13
|
+
* answering with a `Response` it made — and only a check of the finished
|
|
14
|
+
* response can see that, so this one runs after the request: when a line was
|
|
15
|
+
* recorded, the response's first `Set-Cookie` must be that line, else it logs
|
|
16
|
+
* an error naming the method and path, and whether the response carries no
|
|
17
|
+
* `Set-Cookie` or another one first.
|
|
18
|
+
*
|
|
19
|
+
* One response is skipped: an accepted WebSocket upgrade's placeholder. No
|
|
20
|
+
* runtime adapter hands Hono a `101` — `@hono/node-server`'s and `@hono/bun`'s
|
|
21
|
+
* `upgradeWebSocket` return a bodiless `200` and the runtime writes the real
|
|
22
|
+
* `101` itself — so the check recognizes the placeholder by its shape: a
|
|
23
|
+
* request with `Upgrade: websocket` answered `200` with no body. That
|
|
24
|
+
* placeholder is no response a client reads, and no layer builds it through
|
|
25
|
+
* the context. The cost: a raw route answering a bodiless `200` to an upgrade
|
|
26
|
+
* request it did not accept goes unchecked too.
|
|
27
|
+
*
|
|
28
|
+
* Generic: it knows a line and an order, nothing of sessions. A sibling of
|
|
29
|
+
* the DEV error check (`http/dev_route_error_check.ts`) rather than part of
|
|
30
|
+
* it, as that one reads the route a request reached and only its error
|
|
31
|
+
* answers, where this one holds every answer of every path, routed or not.
|
|
32
|
+
* Mounted outermost beside it by `create_app_server`. Logs, never throws — a
|
|
33
|
+
* throw inside it, its logger's included, is swallowed — and leaves the
|
|
34
|
+
* response unchanged. Outside DEV `create_dev_set_cookie_check` returns `null`
|
|
35
|
+
* and nothing is mounted.
|
|
36
|
+
*
|
|
37
|
+
* @module
|
|
38
|
+
*/
|
|
39
|
+
import { DEV } from 'esm-env';
|
|
40
|
+
import { EXPECTED_FIRST_SET_COOKIE_KEY } from '../hono_context.js';
|
|
41
|
+
/**
|
|
42
|
+
* Build the DEV `Set-Cookie` check (module doc), or `null` outside DEV.
|
|
43
|
+
*
|
|
44
|
+
* @param options - the logger
|
|
45
|
+
* @returns the middleware to mount outermost, or `null` in production
|
|
46
|
+
*/
|
|
47
|
+
export const create_dev_set_cookie_check = (options) => {
|
|
48
|
+
if (!DEV)
|
|
49
|
+
return null;
|
|
50
|
+
const { log } = options;
|
|
51
|
+
// named, so an assembled app's route table shows it
|
|
52
|
+
const dev_set_cookie_check = async (c, next) => {
|
|
53
|
+
await next();
|
|
54
|
+
try {
|
|
55
|
+
const expected = c.get(EXPECTED_FIRST_SET_COOKIE_KEY);
|
|
56
|
+
if (expected === undefined)
|
|
57
|
+
return;
|
|
58
|
+
const response = c.res;
|
|
59
|
+
// an accepted upgrade's placeholder (module doc)
|
|
60
|
+
if (c.req.header('upgrade')?.toLowerCase() === 'websocket' &&
|
|
61
|
+
response.status === 200 &&
|
|
62
|
+
response.body === null) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const first = response.headers.getSetCookie()[0];
|
|
66
|
+
if (first === expected)
|
|
67
|
+
return;
|
|
68
|
+
log.error(`Response without the expected first Set-Cookie: ${c.req.method} ${c.req.path} — ${first === undefined ? 'it carries no Set-Cookie' : 'another Set-Cookie comes first'}`);
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
try {
|
|
72
|
+
log.error('dev_set_cookie_check failed:', err);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
// the logger itself threw; nothing left to tell
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
return dev_set_cookie_check;
|
|
80
|
+
};
|
|
@@ -80,6 +80,27 @@ export declare const ERROR_PAYLOAD_TOO_LARGE: "payload_too_large";
|
|
|
80
80
|
export declare const ERROR_SERVICE_UNAVAILABLE: "service_unavailable";
|
|
81
81
|
/** Request `Content-Length` header is not a plain run of ASCII digits. */
|
|
82
82
|
export declare const ERROR_INVALID_CONTENT_LENGTH: "invalid_content_length";
|
|
83
|
+
/**
|
|
84
|
+
* A request whose method its path doesn't serve (405, with `Allow` naming
|
|
85
|
+
* the methods it does) — `server/unmatched_route.ts`; the Rust spine's
|
|
86
|
+
* `fuz_http::METHOD_NOT_ALLOWED_REASON`.
|
|
87
|
+
*/
|
|
88
|
+
export declare const ERROR_METHOD_NOT_ALLOWED: "method_not_allowed";
|
|
89
|
+
/**
|
|
90
|
+
* A path under the auth scope that no route serves (404) —
|
|
91
|
+
* `server/unmatched_route.ts`; the Rust spine's
|
|
92
|
+
* `fuz_http::ROUTE_NOT_FOUND_REASON`. Distinct from a handler's own
|
|
93
|
+
* `not_found`, so a client — or a test asking whether a route is mounted —
|
|
94
|
+
* can tell a missing route from a missing row.
|
|
95
|
+
*/
|
|
96
|
+
export declare const ERROR_ROUTE_NOT_FOUND: "route_not_found";
|
|
97
|
+
/**
|
|
98
|
+
* The body of the `404` an unrouted path outside the auth scope answers, as
|
|
99
|
+
* `text/plain` — no code, since nothing outside the scope speaks the JSON
|
|
100
|
+
* error convention; the Rust spine's `fuz_actions::server::NOT_FOUND_TEXT`,
|
|
101
|
+
* byte for byte.
|
|
102
|
+
*/
|
|
103
|
+
export declare const NOT_FOUND_TEXT = "404 Not Found";
|
|
83
104
|
/** Request origin not in allowlist. */
|
|
84
105
|
export declare const ERROR_FORBIDDEN_ORIGIN: "forbidden_origin";
|
|
85
106
|
/**
|
|
@@ -137,6 +158,15 @@ export declare const ERROR_KEEPER_ACCOUNT_NOT_FOUND: "keeper_account_not_found";
|
|
|
137
158
|
export declare const ERROR_ALREADY_BOOTSTRAPPED: "already_bootstrapped";
|
|
138
159
|
/** Bootstrap token file not found on disk. */
|
|
139
160
|
export declare const ERROR_TOKEN_FILE_MISSING: "token_file_missing";
|
|
161
|
+
/**
|
|
162
|
+
* The bootstrap token matched, but its file couldn't be burned (deleted
|
|
163
|
+
* durably) inside the bootstrap transaction, so the bootstrap rolled back and
|
|
164
|
+
* nothing was created. A 500 with a code of its own because the operator can
|
|
165
|
+
* fix it — the server user needs write access to the token's directory — and
|
|
166
|
+
* then retry the same token: the window stays open. Twin of the Rust
|
|
167
|
+
* `BootstrapErrorKind::TokenFileUndeletable`.
|
|
168
|
+
*/
|
|
169
|
+
export declare const ERROR_TOKEN_FILE_UNDELETABLE: "token_file_undeletable";
|
|
140
170
|
/** No unclaimed invite matches the signup credentials. */
|
|
141
171
|
export declare const ERROR_NO_MATCHING_INVITE: "no_matching_invite";
|
|
142
172
|
/** Signup conflict — username or email already taken (intentionally vague for enumeration prevention). */
|
|
@@ -379,6 +409,8 @@ export declare const REST_NO_ACTORS_ON_ACCOUNT: RestErrorDef<500, "no_actors_on_
|
|
|
379
409
|
/** The account or actor row was deleted between credential validation and the actor read. */
|
|
380
410
|
export declare const REST_ACCOUNT_VANISHED: RestErrorDef<500, "account_vanished", Record<never, never>>;
|
|
381
411
|
export declare const REST_INTERNAL_ERROR: RestErrorDef<500, "internal_error", Record<never, never>>;
|
|
412
|
+
/** Bootstrap's token matched and its file couldn't be burned; the bootstrap rolled back. */
|
|
413
|
+
export declare const REST_TOKEN_FILE_UNDELETABLE: RestErrorDef<500, "token_file_undeletable", Record<never, never>>;
|
|
382
414
|
export declare const REST_SERVICE_UNAVAILABLE: RestErrorDef<503, "service_unavailable", Record<never, never>>;
|
|
383
415
|
/** `GET /health`'s failed check: the database is not connected, and its type. */
|
|
384
416
|
export declare const REST_DATABASE_CONNECTION_FAILED: RestErrorDef<503, "database_connection_failed", {
|
|
@@ -416,7 +448,10 @@ export interface DeriveRouteErrorsOptions {
|
|
|
416
448
|
*
|
|
417
449
|
* Derivation rules:
|
|
418
450
|
* - **A body**, an `input` other than `null` on a method other than `GET`:
|
|
419
|
-
* 400 `invalid_request_body` and `invalid_json_body`. A `GET` reads no body
|
|
451
|
+
* 400 `invalid_request_body` and `invalid_json_body`. A `GET` reads no body:
|
|
452
|
+
* `apply_route_specs` refuses one with an input, but a surface is built from
|
|
453
|
+
* the specs alone (`generate_app_surface`), so such a spec derives none of
|
|
454
|
+
* the body's errors there either.
|
|
420
455
|
* - **`params`**: 400 `invalid_route_params`. **`query`**: 400
|
|
421
456
|
* `invalid_query_params`.
|
|
422
457
|
* - **`auth.account === 'required'`** or **`auth.actor === 'required'`**: 401
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error_schemas.d.ts","sourceRoot":"","sources":["../../src/lib/http/error_schemas.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAYN,KAAK,SAAS,EACd,KAAK,KAAK,EACV,KAAK,MAAM,EACX,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EAAe,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAInD,4CAA4C;AAC5C,eAAO,MAAM,0BAA0B,EAAG,sBAA+B,CAAC;AAE1E,uDAAuD;AACvD,eAAO,MAAM,uBAAuB,EAAG,mBAA4B,CAAC;AAEpE,2CAA2C;AAC3C,eAAO,MAAM,0BAA0B,EAAG,sBAA+B,CAAC;AAE1E,4CAA4C;AAC5C,eAAO,MAAM,0BAA0B,EAAG,sBAA+B,CAAC;AAE1E;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,EAAG,kBAA2B,CAAC;AAElE;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,EAAG,YAAqB,CAAC;AAItD,wCAAwC;AACxC,eAAO,MAAM,6BAA6B,EAAG,yBAAkC,CAAC;AAEhF,+CAA+C;AAC/C,eAAO,MAAM,8BAA8B,EAAG,0BAAmC,CAAC;AAElF;;;;;;;;GAQG;AACH,eAAO,MAAM,8BAA8B,EAAG,0BAAmC,CAAC;AAElF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,0BAA0B,EAAG,sBAA+B,CAAC;AAE1E,yCAAyC;AACzC,eAAO,MAAM,yBAAyB,EAAG,qBAA8B,CAAC;AAExE,sFAAsF;AACtF,eAAO,MAAM,yBAAyB,EAA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O,MAAM,mBAAmB,GAAI,gEAOjC,wBAAwB,KAAG,KAAK,CAAC,YAAY,CAuC/C,CAAC"}
|
|
@@ -82,6 +82,28 @@ export const ERROR_PAYLOAD_TOO_LARGE = 'payload_too_large';
|
|
|
82
82
|
export const ERROR_SERVICE_UNAVAILABLE = 'service_unavailable';
|
|
83
83
|
/** Request `Content-Length` header is not a plain run of ASCII digits. */
|
|
84
84
|
export const ERROR_INVALID_CONTENT_LENGTH = 'invalid_content_length';
|
|
85
|
+
// --- Routing: what no route answers ---
|
|
86
|
+
/**
|
|
87
|
+
* A request whose method its path doesn't serve (405, with `Allow` naming
|
|
88
|
+
* the methods it does) — `server/unmatched_route.ts`; the Rust spine's
|
|
89
|
+
* `fuz_http::METHOD_NOT_ALLOWED_REASON`.
|
|
90
|
+
*/
|
|
91
|
+
export const ERROR_METHOD_NOT_ALLOWED = 'method_not_allowed';
|
|
92
|
+
/**
|
|
93
|
+
* A path under the auth scope that no route serves (404) —
|
|
94
|
+
* `server/unmatched_route.ts`; the Rust spine's
|
|
95
|
+
* `fuz_http::ROUTE_NOT_FOUND_REASON`. Distinct from a handler's own
|
|
96
|
+
* `not_found`, so a client — or a test asking whether a route is mounted —
|
|
97
|
+
* can tell a missing route from a missing row.
|
|
98
|
+
*/
|
|
99
|
+
export const ERROR_ROUTE_NOT_FOUND = 'route_not_found';
|
|
100
|
+
/**
|
|
101
|
+
* The body of the `404` an unrouted path outside the auth scope answers, as
|
|
102
|
+
* `text/plain` — no code, since nothing outside the scope speaks the JSON
|
|
103
|
+
* error convention; the Rust spine's `fuz_actions::server::NOT_FOUND_TEXT`,
|
|
104
|
+
* byte for byte.
|
|
105
|
+
*/
|
|
106
|
+
export const NOT_FOUND_TEXT = '404 Not Found';
|
|
85
107
|
// --- Origin & bearer token verification ---
|
|
86
108
|
/** Request origin not in allowlist. */
|
|
87
109
|
export const ERROR_FORBIDDEN_ORIGIN = 'forbidden_origin';
|
|
@@ -142,6 +164,15 @@ export const ERROR_KEEPER_ACCOUNT_NOT_FOUND = 'keeper_account_not_found';
|
|
|
142
164
|
export const ERROR_ALREADY_BOOTSTRAPPED = 'already_bootstrapped';
|
|
143
165
|
/** Bootstrap token file not found on disk. */
|
|
144
166
|
export const ERROR_TOKEN_FILE_MISSING = 'token_file_missing';
|
|
167
|
+
/**
|
|
168
|
+
* The bootstrap token matched, but its file couldn't be burned (deleted
|
|
169
|
+
* durably) inside the bootstrap transaction, so the bootstrap rolled back and
|
|
170
|
+
* nothing was created. A 500 with a code of its own because the operator can
|
|
171
|
+
* fix it — the server user needs write access to the token's directory — and
|
|
172
|
+
* then retry the same token: the window stays open. Twin of the Rust
|
|
173
|
+
* `BootstrapErrorKind::TokenFileUndeletable`.
|
|
174
|
+
*/
|
|
175
|
+
export const ERROR_TOKEN_FILE_UNDELETABLE = 'token_file_undeletable';
|
|
145
176
|
// --- Signup / Invites ---
|
|
146
177
|
/** No unclaimed invite matches the signup credentials. */
|
|
147
178
|
export const ERROR_NO_MATCHING_INVITE = 'no_matching_invite';
|
|
@@ -394,6 +425,8 @@ export const REST_NO_ACTORS_ON_ACCOUNT = rest_error(500, ERROR_NO_ACTORS_ON_ACCO
|
|
|
394
425
|
/** The account or actor row was deleted between credential validation and the actor read. */
|
|
395
426
|
export const REST_ACCOUNT_VANISHED = rest_error(500, ERROR_ACCOUNT_VANISHED);
|
|
396
427
|
export const REST_INTERNAL_ERROR = rest_error(500, ERROR_INTERNAL_ERROR);
|
|
428
|
+
/** Bootstrap's token matched and its file couldn't be burned; the bootstrap rolled back. */
|
|
429
|
+
export const REST_TOKEN_FILE_UNDELETABLE = rest_error(500, ERROR_TOKEN_FILE_UNDELETABLE);
|
|
397
430
|
// 503: a failed pool checkout any route can answer with, and the health and readiness checks
|
|
398
431
|
export const REST_SERVICE_UNAVAILABLE = rest_error(503, ERROR_SERVICE_UNAVAILABLE);
|
|
399
432
|
/** `GET /health`'s failed check: the database is not connected, and its type. */
|
|
@@ -414,7 +447,10 @@ export const REST_DB_UNREACHABLE = rest_error(503, ERROR_DB_UNREACHABLE);
|
|
|
414
447
|
*
|
|
415
448
|
* Derivation rules:
|
|
416
449
|
* - **A body**, an `input` other than `null` on a method other than `GET`:
|
|
417
|
-
* 400 `invalid_request_body` and `invalid_json_body`. A `GET` reads no body
|
|
450
|
+
* 400 `invalid_request_body` and `invalid_json_body`. A `GET` reads no body:
|
|
451
|
+
* `apply_route_specs` refuses one with an input, but a surface is built from
|
|
452
|
+
* the specs alone (`generate_app_surface`), so such a spec derives none of
|
|
453
|
+
* the body's errors there either.
|
|
418
454
|
* - **`params`**: 400 `invalid_route_params`. **`query`**: 400
|
|
419
455
|
* `invalid_query_params`.
|
|
420
456
|
* - **`auth.account === 'required'`** or **`auth.actor === 'required'`**: 401
|
|
@@ -439,7 +475,8 @@ export const REST_DB_UNREACHABLE = rest_error(503, ERROR_DB_UNREACHABLE);
|
|
|
439
475
|
*/
|
|
440
476
|
export const derive_route_errors = ({ method, auth, has_input = false, has_params = false, has_query = false, rate_limit }) => {
|
|
441
477
|
const defs = [];
|
|
442
|
-
//
|
|
478
|
+
// a GET reads no body — registration refuses one with an input, and a
|
|
479
|
+
// surface built without registering derives what the runtime would answer
|
|
443
480
|
if (has_input && method !== 'GET') {
|
|
444
481
|
defs.push(REST_INVALID_REQUEST_BODY, REST_INVALID_JSON_BODY);
|
|
445
482
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A request header as the lines the client sent — one field value per header
|
|
3
|
+
* line, in order — where the Fetch `Headers` a handler normally reads has
|
|
4
|
+
* already folded them into one string.
|
|
5
|
+
*
|
|
6
|
+
* The credential readers (`auth/credential_headers.ts`) and the gate readers
|
|
7
|
+
* (`http/request_headers.ts`) decide on the lines: a credential header sent
|
|
8
|
+
* twice is discarded, an `Origin` or `Host` sent twice is refused, and that
|
|
9
|
+
* takes knowing it was sent twice. `Headers.get` joins repeated lines with
|
|
10
|
+
* `, `, and `@hono/node-server` builds a WebSocket upgrade's `Headers` from
|
|
11
|
+
* Node's deduplicated view, which keeps only the first `Authorization`,
|
|
12
|
+
* `Host`, `Referer` or `Content-Type` line and drops every empty one — so on
|
|
13
|
+
* that path neither the join nor an empty line shows.
|
|
14
|
+
*
|
|
15
|
+
* @module
|
|
16
|
+
*/
|
|
17
|
+
import type { Context } from 'hono';
|
|
18
|
+
/**
|
|
19
|
+
* Strip HTTP optional whitespace — SP and HTAB, nothing else — from both ends
|
|
20
|
+
* of a field value or a part of one. `String.prototype.trim` strips more: a
|
|
21
|
+
* header byte 0xA0 reaches a handler as U+00A0, which it counts as whitespace.
|
|
22
|
+
*
|
|
23
|
+
* @param text - a field value, or a part of one
|
|
24
|
+
* @returns `text` without its leading and trailing SP and HTAB
|
|
25
|
+
*/
|
|
26
|
+
export declare const trim_optional_whitespace: (text: string) => string;
|
|
27
|
+
/**
|
|
28
|
+
* Read one request header as the lines it was sent in.
|
|
29
|
+
*
|
|
30
|
+
* On `@hono/node-server` the lines come from the request's raw header list
|
|
31
|
+
* (`c.env.incoming.rawHeaders`), so a header sent twice is two entries. A
|
|
32
|
+
* runtime with no per-line view — Bun, and an in-process `app.request` — gives
|
|
33
|
+
* the Fetch `Headers` value as the single line: repeated lines arrive already
|
|
34
|
+
* joined (`; ` for `Cookie`, `, ` otherwise), and a caller that must tell a
|
|
35
|
+
* repeat from one line reads a grammar that refuses the join.
|
|
36
|
+
*
|
|
37
|
+
* @param c - the request context
|
|
38
|
+
* @param name - the header name, in any case
|
|
39
|
+
* @returns the header's field values, outer SP and HTAB stripped, in the order sent — `[]` when the request carries no such header
|
|
40
|
+
*/
|
|
41
|
+
export declare const get_header_lines: (c: Context, name: string) => Array<string>;
|
|
42
|
+
//# sourceMappingURL=header_lines.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"header_lines.d.ts","sourceRoot":"","sources":["../../src/lib/http/header_lines.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAiBpC;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,GAAI,MAAM,MAAM,KAAG,MAMvD,CAAC;AAIF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gBAAgB,GAAI,GAAG,OAAO,EAAE,MAAM,MAAM,KAAG,KAAK,CAAC,MAAM,CAcvE,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A request header as the lines the client sent — one field value per header
|
|
3
|
+
* line, in order — where the Fetch `Headers` a handler normally reads has
|
|
4
|
+
* already folded them into one string.
|
|
5
|
+
*
|
|
6
|
+
* The credential readers (`auth/credential_headers.ts`) and the gate readers
|
|
7
|
+
* (`http/request_headers.ts`) decide on the lines: a credential header sent
|
|
8
|
+
* twice is discarded, an `Origin` or `Host` sent twice is refused, and that
|
|
9
|
+
* takes knowing it was sent twice. `Headers.get` joins repeated lines with
|
|
10
|
+
* `, `, and `@hono/node-server` builds a WebSocket upgrade's `Headers` from
|
|
11
|
+
* Node's deduplicated view, which keeps only the first `Authorization`,
|
|
12
|
+
* `Host`, `Referer` or `Content-Type` line and drops every empty one — so on
|
|
13
|
+
* that path neither the join nor an empty line shows.
|
|
14
|
+
*
|
|
15
|
+
* @module
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* The names and values of the request's header lines, alternating, as Node's
|
|
19
|
+
* `IncomingMessage.rawHeaders` holds them — from the `c.env.incoming` that
|
|
20
|
+
* `@hono/node-server` passes a handler, on plain requests and on WebSocket
|
|
21
|
+
* upgrades alike.
|
|
22
|
+
*/
|
|
23
|
+
const to_node_raw_headers = (env) => {
|
|
24
|
+
if (typeof env !== 'object' || env === null)
|
|
25
|
+
return null;
|
|
26
|
+
const incoming = env.incoming;
|
|
27
|
+
if (typeof incoming !== 'object' || incoming === null)
|
|
28
|
+
return null;
|
|
29
|
+
const raw_headers = incoming.rawHeaders;
|
|
30
|
+
if (!Array.isArray(raw_headers) || raw_headers.length % 2 !== 0)
|
|
31
|
+
return null;
|
|
32
|
+
return raw_headers.every((entry) => typeof entry === 'string') ? raw_headers : null;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Strip HTTP optional whitespace — SP and HTAB, nothing else — from both ends
|
|
36
|
+
* of a field value or a part of one. `String.prototype.trim` strips more: a
|
|
37
|
+
* header byte 0xA0 reaches a handler as U+00A0, which it counts as whitespace.
|
|
38
|
+
*
|
|
39
|
+
* @param text - a field value, or a part of one
|
|
40
|
+
* @returns `text` without its leading and trailing SP and HTAB
|
|
41
|
+
*/
|
|
42
|
+
export const trim_optional_whitespace = (text) => {
|
|
43
|
+
let start = 0;
|
|
44
|
+
let end = text.length;
|
|
45
|
+
while (start < end && is_optional_whitespace(text.charCodeAt(start)))
|
|
46
|
+
start++;
|
|
47
|
+
while (end > start && is_optional_whitespace(text.charCodeAt(end - 1)))
|
|
48
|
+
end--;
|
|
49
|
+
return text.slice(start, end);
|
|
50
|
+
};
|
|
51
|
+
const is_optional_whitespace = (code) => code === 0x20 || code === 0x09;
|
|
52
|
+
/**
|
|
53
|
+
* Read one request header as the lines it was sent in.
|
|
54
|
+
*
|
|
55
|
+
* On `@hono/node-server` the lines come from the request's raw header list
|
|
56
|
+
* (`c.env.incoming.rawHeaders`), so a header sent twice is two entries. A
|
|
57
|
+
* runtime with no per-line view — Bun, and an in-process `app.request` — gives
|
|
58
|
+
* the Fetch `Headers` value as the single line: repeated lines arrive already
|
|
59
|
+
* joined (`; ` for `Cookie`, `, ` otherwise), and a caller that must tell a
|
|
60
|
+
* repeat from one line reads a grammar that refuses the join.
|
|
61
|
+
*
|
|
62
|
+
* @param c - the request context
|
|
63
|
+
* @param name - the header name, in any case
|
|
64
|
+
* @returns the header's field values, outer SP and HTAB stripped, in the order sent — `[]` when the request carries no such header
|
|
65
|
+
*/
|
|
66
|
+
export const get_header_lines = (c, name) => {
|
|
67
|
+
const raw_headers = to_node_raw_headers(c.env);
|
|
68
|
+
if (raw_headers === null) {
|
|
69
|
+
const value = c.req.raw.headers.get(name);
|
|
70
|
+
return value === null ? [] : [trim_optional_whitespace(value)];
|
|
71
|
+
}
|
|
72
|
+
const lower_name = name.toLowerCase();
|
|
73
|
+
const lines = [];
|
|
74
|
+
for (let i = 0; i < raw_headers.length; i += 2) {
|
|
75
|
+
if (raw_headers[i].toLowerCase() === lower_name) {
|
|
76
|
+
lines.push(trim_optional_whitespace(raw_headers[i + 1]));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return lines;
|
|
80
|
+
};
|
package/dist/http/host.d.ts
CHANGED
|
@@ -16,9 +16,11 @@
|
|
|
16
16
|
* admit the hosts they'd admit as origins.
|
|
17
17
|
*
|
|
18
18
|
* A request without a `Host` header passes: browsers always send one, so its
|
|
19
|
-
* absence means a non-browser client, which the auth stack governs.
|
|
20
|
-
*
|
|
21
|
-
*
|
|
19
|
+
* absence means a non-browser client, which the auth stack governs. An empty
|
|
20
|
+
* `Host` and more than one `Host` are refused (RFC 9112 §3.2), read from the
|
|
21
|
+
* lines the client sent (`get_header_lines`) — on `@hono/node-server` a
|
|
22
|
+
* WebSocket upgrade's own `Headers` keep only the first `Host` line, and on a
|
|
23
|
+
* runtime that joins repeated lines (`a, b`) the comma names no host.
|
|
22
24
|
*
|
|
23
25
|
* The gate is on by default (`AppServerOptions.host_gate`). A refusal is said
|
|
24
26
|
* in the log as well as answered: the first in each
|
|
@@ -64,13 +66,13 @@ export declare const is_loopback_host: (host: string) => boolean;
|
|
|
64
66
|
*/
|
|
65
67
|
export declare const allows_host: (host: string, allowed_patterns: ReadonlyArray<RegExp>) => boolean;
|
|
66
68
|
/**
|
|
67
|
-
* Host check for a request's `Host`
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
69
|
+
* Host check for a request's `Host` lines — true when there are none, or one
|
|
70
|
+
* (`read_host` of `http/request_headers.ts`: printable ASCII, no space or
|
|
71
|
+
* comma) that passes `allows_host`. An empty line, more than one line (RFC
|
|
72
|
+
* 9112 §3.2), and a byte outside that set are refused. Twin of the Rust
|
|
71
73
|
* `AllowedOrigins::allows_request_hosts`.
|
|
72
74
|
*
|
|
73
|
-
* @param hosts - the request's `Host`
|
|
75
|
+
* @param hosts - the request's `Host` lines, `[]` for none
|
|
74
76
|
* @param allowed_patterns - the matchers `parse_allowed_origins` built
|
|
75
77
|
* @returns whether the request passes the host gate
|
|
76
78
|
*/
|
|
@@ -78,7 +80,8 @@ export declare const allows_request_hosts: (hosts: ReadonlyArray<string>, allowe
|
|
|
78
80
|
/**
|
|
79
81
|
* The refusal warning's text. Twin of the Rust `format_host_refusal_warning`.
|
|
80
82
|
*
|
|
81
|
-
* @param host - the refused `Host` as the request carried it
|
|
83
|
+
* @param host - the refused `Host` as the request carried it — several lines
|
|
84
|
+
* joined with `, `
|
|
82
85
|
* @param allowed_origins_var - the env var the allowlist was read from
|
|
83
86
|
* @param held_back - the refusals held back since the last warning
|
|
84
87
|
* @returns one log line
|
package/dist/http/host.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../../src/lib/http/host.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../../src/lib/http/host.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAK9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAK3D,2FAA2F;AAC3F,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAExC;;;GAGG;AACH,eAAO,MAAM,6BAA6B,QAAS,CAAC;AAQpD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,MAAM,KAAG,OAsB/C,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,GAAI,MAAM,MAAM,EAAE,kBAAkB,aAAa,CAAC,MAAM,CAAC,KAAG,OAQnF,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,oBAAoB,GAChC,OAAO,aAAa,CAAC,MAAM,CAAC,EAC5B,kBAAkB,aAAa,CAAC,MAAM,CAAC,KACrC,OAUF,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,2BAA2B,GACvC,MAAM,MAAM,EACZ,qBAAqB,MAAM,EAC3B,WAAW,MAAM,KACf,MAQF,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IACnC;;;OAGG;IACH,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;CACxC;AAED,+CAA+C;AAC/C,eAAO,MAAM,4BAA4B,QAAO,mBAe/C,CAAC;AAEF,iDAAiD;AACjD,MAAM,WAAW,eAAe;IAC/B,2EAA2E;IAC3E,eAAe,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACvC,sCAAsC;IACtC,GAAG,EAAE,MAAM,CAAC;IACZ,wGAAwG;IACxG,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,yFAAyF;IACzF,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACnB;AAED;;;;;;GAMG;AACH,eAAO,MAAM,2BAA2B,GAAI,SAAS,eAAe,KAAG,iBAetE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,0BAA0B;;;;CAIa,CAAC;AAErD;;;;;;GAMG;AACH,eAAO,MAAM,gCAAgC,GAAI,SAAS,eAAe,KAAG,cAG1E,CAAC"}
|
package/dist/http/host.js
CHANGED
|
@@ -16,9 +16,11 @@
|
|
|
16
16
|
* admit the hosts they'd admit as origins.
|
|
17
17
|
*
|
|
18
18
|
* A request without a `Host` header passes: browsers always send one, so its
|
|
19
|
-
* absence means a non-browser client, which the auth stack governs.
|
|
20
|
-
*
|
|
21
|
-
*
|
|
19
|
+
* absence means a non-browser client, which the auth stack governs. An empty
|
|
20
|
+
* `Host` and more than one `Host` are refused (RFC 9112 §3.2), read from the
|
|
21
|
+
* lines the client sent (`get_header_lines`) — on `@hono/node-server` a
|
|
22
|
+
* WebSocket upgrade's own `Headers` keep only the first `Host` line, and on a
|
|
23
|
+
* runtime that joins repeated lines (`a, b`) the comma names no host.
|
|
22
24
|
*
|
|
23
25
|
* The gate is on by default (`AppServerOptions.host_gate`). A refusal is said
|
|
24
26
|
* in the log as well as answered: the first in each
|
|
@@ -33,9 +35,11 @@
|
|
|
33
35
|
* @module
|
|
34
36
|
*/
|
|
35
37
|
import { ERROR_FORBIDDEN_HOST, REST_FORBIDDEN_HOST } from './error_schemas.js';
|
|
38
|
+
import { get_header_lines } from './header_lines.js';
|
|
36
39
|
import { parse_ipv4_bits, parse_ipv6_bits } from './ip_canonical.js';
|
|
37
40
|
import { quote_ascii, should_allow_origin } from './origin.js';
|
|
38
41
|
import { ALLOWED_ORIGINS_VAR } from './origin_wildcard.js';
|
|
42
|
+
import { read_host } from './request_headers.js';
|
|
39
43
|
/** Where the host gate mounts — every path, as the Rust stack mounts it in every group. */
|
|
40
44
|
export const HOST_MIDDLEWARE_PATH = '*';
|
|
41
45
|
/**
|
|
@@ -103,31 +107,33 @@ export const allows_host = (host, allowed_patterns) => {
|
|
|
103
107
|
return (should_allow_origin(`http://${host}`, allowed_patterns) ||
|
|
104
108
|
should_allow_origin(`https://${host}`, allowed_patterns));
|
|
105
109
|
};
|
|
106
|
-
/** Visible ASCII, the space, and a tab — what a header value holds. */
|
|
107
|
-
const HEADER_TEXT = /^[\t\x20-\x7e]*$/;
|
|
108
110
|
/**
|
|
109
|
-
* Host check for a request's `Host`
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
111
|
+
* Host check for a request's `Host` lines — true when there are none, or one
|
|
112
|
+
* (`read_host` of `http/request_headers.ts`: printable ASCII, no space or
|
|
113
|
+
* comma) that passes `allows_host`. An empty line, more than one line (RFC
|
|
114
|
+
* 9112 §3.2), and a byte outside that set are refused. Twin of the Rust
|
|
113
115
|
* `AllowedOrigins::allows_request_hosts`.
|
|
114
116
|
*
|
|
115
|
-
* @param hosts - the request's `Host`
|
|
117
|
+
* @param hosts - the request's `Host` lines, `[]` for none
|
|
116
118
|
* @param allowed_patterns - the matchers `parse_allowed_origins` built
|
|
117
119
|
* @returns whether the request passes the host gate
|
|
118
120
|
*/
|
|
119
121
|
export const allows_request_hosts = (hosts, allowed_patterns) => {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
122
|
+
const host = read_host(hosts);
|
|
123
|
+
switch (host.kind) {
|
|
124
|
+
case 'absent':
|
|
125
|
+
return true;
|
|
126
|
+
case 'refused':
|
|
127
|
+
return false;
|
|
128
|
+
case 'one':
|
|
129
|
+
return allows_host(host.value, allowed_patterns);
|
|
130
|
+
}
|
|
126
131
|
};
|
|
127
132
|
/**
|
|
128
133
|
* The refusal warning's text. Twin of the Rust `format_host_refusal_warning`.
|
|
129
134
|
*
|
|
130
|
-
* @param host - the refused `Host` as the request carried it
|
|
135
|
+
* @param host - the refused `Host` as the request carried it — several lines
|
|
136
|
+
* joined with `, `
|
|
131
137
|
* @param allowed_origins_var - the env var the allowlist was read from
|
|
132
138
|
* @param held_back - the refusals held back since the last warning
|
|
133
139
|
* @returns one log line
|
|
@@ -168,12 +174,11 @@ export const create_host_gate_middleware = (options) => {
|
|
|
168
174
|
const now = options.now ?? Date.now;
|
|
169
175
|
const warnings = create_host_refusal_warnings();
|
|
170
176
|
return async (c, next) => {
|
|
171
|
-
const
|
|
172
|
-
const hosts = host === undefined ? [] : [host];
|
|
177
|
+
const hosts = get_header_lines(c, 'host');
|
|
173
178
|
if (!allows_request_hosts(hosts, allowed_origins)) {
|
|
174
179
|
const held_back = warnings.note(now());
|
|
175
180
|
if (held_back !== null) {
|
|
176
|
-
log.warn(format_host_refusal_warning(
|
|
181
|
+
log.warn(format_host_refusal_warning(hosts.join(', '), allowed_origins_var, held_back));
|
|
177
182
|
}
|
|
178
183
|
return c.json({ error: ERROR_FORBIDDEN_HOST }, 403);
|
|
179
184
|
}
|
package/dist/http/origin.d.ts
CHANGED
|
@@ -19,26 +19,9 @@
|
|
|
19
19
|
* @module
|
|
20
20
|
*/
|
|
21
21
|
import type { Result } from '@fuzdev/fuz_util/result.ts';
|
|
22
|
-
import type {
|
|
22
|
+
import type { Handler } from 'hono';
|
|
23
23
|
import { type Infer } from '@fuzdev/fuz_schema/schema.ts';
|
|
24
24
|
import type { MiddlewareCarveOut } from './middleware_spec.js';
|
|
25
|
-
/**
|
|
26
|
-
* True when the request looks like it originated from a browser context — it
|
|
27
|
-
* carries an `Origin` or `Referer` header. Browsers attach these
|
|
28
|
-
* automatically on the state-changing surface; loopback / CLI clients don't.
|
|
29
|
-
* Uses `!== undefined` so an empty-string header still counts as browser
|
|
30
|
-
* context. Checks `Referer` too (not just `Origin`) because some browser
|
|
31
|
-
* requests send only `Referer`. Twin of the Rust spine's
|
|
32
|
-
* `bearer_auth::is_browser_context`.
|
|
33
|
-
*
|
|
34
|
-
* The bearer (`auth/bearer_auth.ts`) and daemon-token
|
|
35
|
-
* (`auth/daemon_token_middleware.ts`) middleware both silently discard their
|
|
36
|
-
* credential when this is true: a stolen bearer token can't be replayed from a
|
|
37
|
-
* browser, and the loopback daemon token never legitimately carries an
|
|
38
|
-
* `Origin`. Distinct from `verify_request_source` — that gates browser
|
|
39
|
-
* requests against an allowlist; this only detects browser context.
|
|
40
|
-
*/
|
|
41
|
-
export declare const is_browser_context: (c: Context) => boolean;
|
|
42
25
|
/**
|
|
43
26
|
* Why one allowlist entry was refused, a `@fuzdev/fuz_schema` `one_of` whose
|
|
44
27
|
* `def` is the names. The wire names both spines emit — the Rust spine's
|
|
@@ -154,11 +137,13 @@ export declare const should_allow_origin: (origin: string, allowed_patterns: Rea
|
|
|
154
137
|
*
|
|
155
138
|
* Origin allowlisting (not the CSRF layer — that's `SameSite: strict` cookies
|
|
156
139
|
* plus `http/simple_request.ts`):
|
|
157
|
-
* - Checks the `Origin`
|
|
140
|
+
* - Checks the one `Origin` line (if present) against the allowlist
|
|
158
141
|
* - Allows requests without an `Origin` header (direct access, curl, etc.)
|
|
159
|
-
* - Refuses
|
|
160
|
-
*
|
|
161
|
-
*
|
|
142
|
+
* - Refuses a malformed `Origin` (`read_origin` of `http/request_headers.ts`):
|
|
143
|
+
* an empty line, a second line, a byte that isn't visible ASCII — read from
|
|
144
|
+
* the lines the client sent (`get_header_lines`), so a runtime's own view of
|
|
145
|
+
* a repeated or empty line (`@hono/node-server` rebuilds a WebSocket
|
|
146
|
+
* upgrade's from Node's deduplicated one) decides nothing
|
|
162
147
|
*
|
|
163
148
|
* Origin-only by design — Fetch spec mandates `Origin` on every unsafe
|
|
164
149
|
* method (POST / PUT / DELETE / PATCH) regardless of `Referrer-Policy`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"origin.d.ts","sourceRoot":"","sources":["../../src/lib/http/origin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,KAAK,EAAE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"origin.d.ts","sourceRoot":"","sources":["../../src/lib/http/origin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,EAAU,KAAK,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAIlE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAI/D;;;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