@fuzdev/fuz_app 0.180.0 → 0.182.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/CLAUDE.md +38 -20
- package/dist/actions/action_rpc.d.ts +25 -6
- package/dist/actions/action_rpc.d.ts.map +1 -1
- package/dist/actions/action_rpc.js +56 -48
- package/dist/actions/action_types.d.ts +31 -13
- package/dist/actions/action_types.d.ts.map +1 -1
- package/dist/actions/action_types.js +1 -1
- package/dist/actions/notification_sender.d.ts +83 -0
- package/dist/actions/notification_sender.d.ts.map +1 -0
- package/dist/actions/notification_sender.js +85 -0
- package/dist/actions/perform_action.d.ts +13 -4
- package/dist/actions/perform_action.d.ts.map +1 -1
- package/dist/actions/perform_action.js +27 -18
- package/dist/actions/register_action_ws.d.ts +20 -2
- package/dist/actions/register_action_ws.d.ts.map +1 -1
- package/dist/actions/register_action_ws.js +17 -5
- package/dist/actions/ws_socket_session.d.ts +3 -0
- package/dist/actions/ws_socket_session.d.ts.map +1 -1
- package/dist/actions/ws_socket_session.js +3 -2
- package/dist/auth/CLAUDE.md +84 -59
- package/dist/auth/account_actions.d.ts.map +1 -1
- package/dist/auth/account_actions.js +30 -3
- package/dist/auth/account_queries.d.ts +213 -2
- package/dist/auth/account_queries.d.ts.map +1 -1
- package/dist/auth/account_queries.js +255 -2
- package/dist/auth/account_route_schema.d.ts +26 -16
- package/dist/auth/account_route_schema.d.ts.map +1 -1
- package/dist/auth/account_route_schema.js +10 -24
- package/dist/auth/account_routes.d.ts +5 -7
- package/dist/auth/account_routes.d.ts.map +1 -1
- package/dist/auth/account_routes.js +110 -89
- package/dist/auth/admin_actions.d.ts.map +1 -1
- package/dist/auth/admin_actions.js +117 -25
- package/dist/auth/api_token_queries.d.ts +29 -12
- package/dist/auth/api_token_queries.d.ts.map +1 -1
- package/dist/auth/api_token_queries.js +42 -27
- package/dist/auth/audit_log_route_schema.d.ts +1 -1
- package/dist/auth/audit_log_route_schema.d.ts.map +1 -1
- package/dist/auth/audit_log_routes.d.ts +1 -1
- package/dist/auth/audit_log_routes.d.ts.map +1 -1
- package/dist/auth/audit_log_routes.js +10 -12
- package/dist/auth/audit_log_schema.js +4 -4
- package/dist/auth/bearer_auth.d.ts +4 -3
- package/dist/auth/bearer_auth.d.ts.map +1 -1
- package/dist/auth/bearer_auth.js +37 -32
- package/dist/auth/bootstrap_account.d.ts +65 -37
- package/dist/auth/bootstrap_account.d.ts.map +1 -1
- package/dist/auth/bootstrap_account.js +115 -66
- package/dist/auth/bootstrap_route_schema.d.ts +6 -2
- package/dist/auth/bootstrap_route_schema.d.ts.map +1 -1
- package/dist/auth/bootstrap_route_schema.js +7 -2
- package/dist/auth/bootstrap_routes.d.ts +50 -33
- package/dist/auth/bootstrap_routes.d.ts.map +1 -1
- package/dist/auth/bootstrap_routes.js +109 -87
- package/dist/auth/bootstrap_token_store.d.ts +60 -0
- package/dist/auth/bootstrap_token_store.d.ts.map +1 -0
- package/dist/auth/bootstrap_token_store.js +39 -0
- package/dist/auth/credential_headers.d.ts +71 -0
- package/dist/auth/credential_headers.d.ts.map +1 -0
- package/dist/auth/credential_headers.js +100 -0
- package/dist/auth/daemon_token.d.ts +13 -1
- package/dist/auth/daemon_token.d.ts.map +1 -1
- package/dist/auth/daemon_token.js +14 -2
- package/dist/auth/daemon_token_middleware.d.ts +10 -11
- package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
- package/dist/auth/daemon_token_middleware.js +39 -30
- package/dist/auth/deps.d.ts +10 -11
- package/dist/auth/deps.d.ts.map +1 -1
- package/dist/auth/invite_queries.d.ts +18 -0
- package/dist/auth/invite_queries.d.ts.map +1 -1
- package/dist/auth/invite_queries.js +24 -0
- package/dist/auth/request_context.d.ts +97 -76
- package/dist/auth/request_context.d.ts.map +1 -1
- package/dist/auth/request_context.js +93 -104
- package/dist/auth/resolved_auth.d.ts +10 -5
- package/dist/auth/resolved_auth.d.ts.map +1 -1
- package/dist/auth/resolved_auth.js +2 -2
- package/dist/auth/role_grant_offer_action_specs.d.ts +2 -2
- package/dist/auth/role_grant_offer_action_specs.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_action_specs.js +5 -3
- package/dist/auth/role_grant_offer_actions.d.ts +7 -11
- package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_actions.js +97 -106
- package/dist/auth/role_grant_offer_ddl.d.ts +7 -1
- package/dist/auth/role_grant_offer_ddl.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_ddl.js +9 -2
- package/dist/auth/role_grant_offer_notifications.d.ts +87 -38
- package/dist/auth/role_grant_offer_notifications.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_notifications.js +75 -22
- package/dist/auth/role_grant_offer_queries.d.ts +143 -9
- package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_queries.js +266 -66
- package/dist/auth/role_grant_offer_schema.js +1 -1
- package/dist/auth/role_grant_queries.d.ts +57 -10
- package/dist/auth/role_grant_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_queries.js +81 -22
- package/dist/auth/role_grant_sql.d.ts +21 -0
- package/dist/auth/role_grant_sql.d.ts.map +1 -1
- package/dist/auth/role_grant_sql.js +21 -0
- package/dist/auth/self_service_role_actions.d.ts.map +1 -1
- package/dist/auth/self_service_role_actions.js +9 -2
- package/dist/auth/session_cookie.d.ts +105 -25
- package/dist/auth/session_cookie.d.ts.map +1 -1
- package/dist/auth/session_cookie.js +124 -15
- package/dist/auth/session_middleware.d.ts +83 -54
- package/dist/auth/session_middleware.d.ts.map +1 -1
- package/dist/auth/session_middleware.js +92 -66
- package/dist/auth/session_queries.d.ts +95 -14
- package/dist/auth/session_queries.d.ts.map +1 -1
- package/dist/auth/session_queries.js +98 -19
- package/dist/auth/signup_route_schema.d.ts +5 -5
- package/dist/auth/signup_route_schema.d.ts.map +1 -1
- package/dist/auth/signup_route_schema.js +4 -4
- package/dist/auth/signup_routes.d.ts.map +1 -1
- package/dist/auth/signup_routes.js +17 -14
- package/dist/auth/standard_rpc_actions.d.ts +6 -19
- package/dist/auth/standard_rpc_actions.d.ts.map +1 -1
- package/dist/auth/standard_rpc_actions.js +5 -6
- package/dist/auth/token_scope.d.ts +6 -8
- package/dist/auth/token_scope.d.ts.map +1 -1
- package/dist/auth/token_scope.js +6 -9
- package/dist/dev/setup.d.ts +6 -1
- package/dist/dev/setup.d.ts.map +1 -1
- package/dist/dev/setup.js +42 -34
- package/dist/hono_context.d.ts +21 -0
- package/dist/hono_context.d.ts.map +1 -1
- package/dist/hono_context.js +17 -0
- package/dist/http/CLAUDE.md +156 -48
- package/dist/http/auth_shape.d.ts +4 -4
- package/dist/http/common_routes.js +1 -1
- package/dist/http/db_routes.d.ts +4 -3
- package/dist/http/db_routes.d.ts.map +1 -1
- package/dist/http/db_routes.js +14 -14
- package/dist/http/dev_route_error_check.d.ts +6 -3
- package/dist/http/dev_route_error_check.d.ts.map +1 -1
- package/dist/http/dev_route_error_check.js +6 -3
- package/dist/http/dev_set_cookie_check.d.ts +53 -0
- package/dist/http/dev_set_cookie_check.d.ts.map +1 -0
- package/dist/http/dev_set_cookie_check.js +80 -0
- package/dist/http/error_schemas.d.ts +45 -22
- package/dist/http/error_schemas.d.ts.map +1 -1
- package/dist/http/error_schemas.js +53 -26
- package/dist/http/header_lines.d.ts +42 -0
- package/dist/http/header_lines.d.ts.map +1 -0
- package/dist/http/header_lines.js +80 -0
- package/dist/http/host.d.ts +12 -9
- package/dist/http/host.d.ts.map +1 -1
- package/dist/http/host.js +25 -20
- package/dist/http/origin.d.ts +7 -22
- package/dist/http/origin.d.ts.map +1 -1
- package/dist/http/origin.js +11 -25
- package/dist/http/proxy.d.ts +1 -0
- package/dist/http/proxy.d.ts.map +1 -1
- package/dist/http/proxy.js +3 -0
- package/dist/http/request_headers.d.ts +95 -0
- package/dist/http/request_headers.d.ts.map +1 -0
- package/dist/http/request_headers.js +110 -0
- package/dist/http/request_target.d.ts +134 -0
- package/dist/http/request_target.d.ts.map +1 -0
- package/dist/http/request_target.js +193 -0
- package/dist/http/route_error_check.d.ts +4 -11
- package/dist/http/route_error_check.d.ts.map +1 -1
- package/dist/http/route_error_check.js +4 -21
- package/dist/http/route_result.d.ts +127 -23
- package/dist/http/route_result.d.ts.map +1 -1
- package/dist/http/route_result.js +97 -19
- package/dist/http/route_spec.d.ts +299 -83
- package/dist/http/route_spec.d.ts.map +1 -1
- package/dist/http/route_spec.js +548 -71
- package/dist/http/simple_request.d.ts +19 -14
- package/dist/http/simple_request.d.ts.map +1 -1
- package/dist/http/simple_request.js +17 -29
- package/dist/http/surface.d.ts +2 -0
- package/dist/http/surface.d.ts.map +1 -1
- package/dist/http/surface.js +4 -1
- package/dist/realtime/outbound_budget.d.ts +1 -2
- package/dist/realtime/outbound_budget.d.ts.map +1 -1
- package/dist/realtime/outbound_budget.js +1 -2
- package/dist/realtime/sse.d.ts +47 -17
- package/dist/realtime/sse.d.ts.map +1 -1
- package/dist/realtime/sse.js +115 -93
- package/dist/realtime/sse_constants.d.ts +7 -1
- package/dist/realtime/sse_constants.d.ts.map +1 -1
- package/dist/realtime/sse_constants.js +12 -1
- package/dist/realtime/sse_registry.d.ts +3 -3
- package/dist/realtime/sse_registry.js +3 -3
- package/dist/runtime/deps.d.ts +20 -4
- package/dist/runtime/deps.d.ts.map +1 -1
- package/dist/runtime/mock.d.ts +7 -1
- package/dist/runtime/mock.d.ts.map +1 -1
- package/dist/runtime/mock.js +33 -3
- package/dist/runtime/node.d.ts.map +1 -1
- package/dist/runtime/node.js +2 -1
- package/dist/runtime/secure_file.d.ts +71 -10
- package/dist/runtime/secure_file.d.ts.map +1 -1
- package/dist/runtime/secure_file.js +91 -11
- package/dist/server/app_backend.d.ts +0 -8
- package/dist/server/app_backend.d.ts.map +1 -1
- package/dist/server/app_backend.js +4 -4
- package/dist/server/app_server.d.ts +54 -33
- package/dist/server/app_server.d.ts.map +1 -1
- package/dist/server/app_server.js +69 -41
- package/dist/server/serve_fact_route.d.ts +3 -3
- package/dist/server/serve_fact_route.d.ts.map +1 -1
- package/dist/server/serve_fact_route.js +59 -55
- package/dist/server/static.d.ts +20 -0
- package/dist/server/static.d.ts.map +1 -1
- package/dist/server/static.js +56 -8
- package/dist/server/unmatched_route.d.ts +42 -0
- package/dist/server/unmatched_route.d.ts.map +1 -0
- package/dist/server/unmatched_route.js +64 -0
- package/dist/testing/CLAUDE.md +406 -1202
- package/dist/testing/app_server.d.ts +3 -1
- package/dist/testing/app_server.d.ts.map +1 -1
- package/dist/testing/app_server.js +5 -9
- package/dist/testing/auth_apps.d.ts.map +1 -1
- package/dist/testing/auth_apps.js +3 -2
- package/dist/testing/cross_backend/account_lifecycle.d.ts +11 -4
- package/dist/testing/cross_backend/account_lifecycle.d.ts.map +1 -1
- package/dist/testing/cross_backend/account_lifecycle.js +320 -6
- package/dist/testing/cross_backend/build_test_backend_paths.d.ts +4 -1
- package/dist/testing/cross_backend/build_test_backend_paths.d.ts.map +1 -1
- package/dist/testing/cross_backend/build_test_backend_paths.js +1 -1
- package/dist/testing/cross_backend/capabilities.d.ts +68 -5
- package/dist/testing/cross_backend/capabilities.d.ts.map +1 -1
- package/dist/testing/cross_backend/capabilities.js +20 -4
- package/dist/testing/cross_backend/cell_gated_create.js +1 -1
- package/dist/testing/cross_backend/conformance_case.d.ts +63 -21
- package/dist/testing/cross_backend/conformance_case.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_table.d.ts +54 -12
- package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_table.js +179 -23
- package/dist/testing/cross_backend/cookie_attributes.js +1 -1
- package/dist/testing/cross_backend/create_dual_spawn_global_setup.d.ts +7 -1
- package/dist/testing/cross_backend/create_dual_spawn_global_setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/create_dual_spawn_global_setup.js +3 -3
- package/dist/testing/cross_backend/credential_conformance.d.ts +196 -0
- package/dist/testing/cross_backend/credential_conformance.d.ts.map +1 -0
- package/dist/testing/cross_backend/credential_conformance.js +296 -0
- package/dist/testing/cross_backend/credential_conformance.json +1284 -0
- package/dist/testing/cross_backend/credential_conformance_wire.d.ts +40 -0
- package/dist/testing/cross_backend/credential_conformance_wire.d.ts.map +1 -0
- package/dist/testing/cross_backend/credential_conformance_wire.js +293 -0
- package/dist/testing/cross_backend/credential_header_robustness.d.ts +1 -3
- package/dist/testing/cross_backend/credential_header_robustness.d.ts.map +1 -1
- package/dist/testing/cross_backend/credential_header_robustness.js +24 -55
- package/dist/testing/cross_backend/credential_wire.d.ts +112 -0
- package/dist/testing/cross_backend/credential_wire.d.ts.map +1 -0
- package/dist/testing/cross_backend/credential_wire.js +188 -0
- package/dist/testing/cross_backend/default_backend_configs.d.ts.map +1 -1
- package/dist/testing/cross_backend/default_backend_configs.js +22 -2
- package/dist/testing/cross_backend/default_spine_surface.d.ts +1 -26
- package/dist/testing/cross_backend/default_spine_surface.d.ts.map +1 -1
- package/dist/testing/cross_backend/default_spine_surface.js +3 -7
- package/dist/testing/cross_backend/differential.d.ts +1 -1
- package/dist/testing/cross_backend/differential.d.ts.map +1 -1
- package/dist/testing/cross_backend/differential.js +3 -2
- package/dist/testing/cross_backend/differential_normalize.d.ts +23 -6
- package/dist/testing/cross_backend/differential_normalize.d.ts.map +1 -1
- package/dist/testing/cross_backend/differential_normalize.js +11 -5
- package/dist/testing/cross_backend/full_spine_mount.d.ts +4 -10
- package/dist/testing/cross_backend/full_spine_mount.d.ts.map +1 -1
- package/dist/testing/cross_backend/full_spine_mount.js +11 -4
- package/dist/testing/cross_backend/identity_parity.d.ts.map +1 -1
- package/dist/testing/cross_backend/identity_parity.js +4 -0
- package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/in_process_setup.js +78 -4
- package/dist/testing/cross_backend/login_security.d.ts.map +1 -1
- package/dist/testing/cross_backend/login_security.js +13 -10
- package/dist/testing/cross_backend/peer_ping_ws.d.ts +1 -1
- package/dist/testing/cross_backend/peer_ping_ws.js +2 -2
- package/dist/testing/cross_backend/request_header_conformance.d.ts +174 -0
- package/dist/testing/cross_backend/request_header_conformance.d.ts.map +1 -0
- package/dist/testing/cross_backend/request_header_conformance.js +196 -0
- package/dist/testing/cross_backend/request_header_conformance.json +1158 -0
- package/dist/testing/cross_backend/request_header_conformance_wire.d.ts +39 -0
- package/dist/testing/cross_backend/request_header_conformance_wire.d.ts.map +1 -0
- package/dist/testing/cross_backend/request_header_conformance_wire.js +284 -0
- package/dist/testing/cross_backend/request_target_conformance.d.ts +298 -0
- package/dist/testing/cross_backend/request_target_conformance.d.ts.map +1 -0
- package/dist/testing/cross_backend/request_target_conformance.js +186 -0
- package/dist/testing/cross_backend/request_target_conformance.json +3765 -0
- package/dist/testing/cross_backend/request_target_conformance_wire.d.ts +32 -0
- package/dist/testing/cross_backend/request_target_conformance_wire.d.ts.map +1 -0
- package/dist/testing/cross_backend/request_target_conformance_wire.js +278 -0
- package/dist/testing/cross_backend/role_grant_offer_lifecycle.d.ts.map +1 -1
- package/dist/testing/cross_backend/role_grant_offer_lifecycle.js +173 -1
- package/dist/testing/cross_backend/role_grant_offer_notification_ws.d.ts +5 -4
- package/dist/testing/cross_backend/role_grant_offer_notification_ws.d.ts.map +1 -1
- package/dist/testing/cross_backend/role_grant_offer_notification_ws.js +185 -31
- package/dist/testing/cross_backend/rpc_adversarial.d.ts +6 -4
- package/dist/testing/cross_backend/rpc_adversarial.d.ts.map +1 -1
- package/dist/testing/cross_backend/rpc_adversarial.js +5 -2
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts +6 -7
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
- package/dist/testing/cross_backend/rust_spine_consumer_surface.js +4 -5
- package/dist/testing/cross_backend/session_cap.d.ts.map +1 -1
- package/dist/testing/cross_backend/session_cap.js +82 -34
- package/dist/testing/cross_backend/session_cookie_effect.d.ts +43 -0
- package/dist/testing/cross_backend/session_cookie_effect.d.ts.map +1 -0
- package/dist/testing/cross_backend/session_cookie_effect.js +103 -0
- package/dist/testing/cross_backend/session_login.d.ts +24 -0
- package/dist/testing/cross_backend/session_login.d.ts.map +1 -0
- package/dist/testing/cross_backend/session_login.js +31 -0
- package/dist/testing/cross_backend/setup.d.ts +117 -0
- package/dist/testing/cross_backend/setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/setup.js +193 -9
- package/dist/testing/cross_backend/simple_request.d.ts.map +1 -1
- package/dist/testing/cross_backend/simple_request.js +5 -0
- package/dist/testing/cross_backend/spine_suites.d.ts +9 -1
- package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
- package/dist/testing/cross_backend/spine_suites.js +88 -5
- package/dist/testing/cross_backend/spine_surface_constants.d.ts +1 -1
- package/dist/testing/cross_backend/spine_surface_constants.d.ts.map +1 -1
- package/dist/testing/cross_backend/spine_surface_constants.js +1 -0
- package/dist/testing/cross_backend/sse_round_trip.d.ts +8 -5
- package/dist/testing/cross_backend/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/cross_backend/sse_round_trip.js +205 -64
- package/dist/testing/cross_backend/testing_backdoor.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_backdoor.js +5 -2
- package/dist/testing/cross_backend/testing_credential_read.d.ts +165 -0
- package/dist/testing/cross_backend/testing_credential_read.d.ts.map +1 -0
- package/dist/testing/cross_backend/testing_credential_read.js +175 -0
- package/dist/testing/cross_backend/testing_reset_actions.d.ts +19 -0
- package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_reset_actions.js +22 -6
- package/dist/testing/cross_backend/token_lifetime.d.ts.map +1 -1
- package/dist/testing/cross_backend/token_lifetime.js +58 -2
- package/dist/testing/cross_backend/transport_composition.d.ts +2 -4
- package/dist/testing/cross_backend/transport_composition.d.ts.map +1 -1
- package/dist/testing/cross_backend/transport_composition.js +13 -10
- package/dist/testing/cross_backend/ts_spine_backend_config.d.ts.map +1 -1
- package/dist/testing/cross_backend/ts_spine_backend_config.js +5 -3
- package/dist/testing/cross_backend/ws_endpoint.d.ts +11 -1
- package/dist/testing/cross_backend/ws_endpoint.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_endpoint.js +19 -2
- package/dist/testing/cross_backend/ws_role_gated.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_role_gated.js +2 -3
- package/dist/testing/cross_backend/ws_round_trip.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_round_trip.js +28 -12
- package/dist/testing/cross_backend/xfail.d.ts +44 -11
- package/dist/testing/cross_backend/xfail.d.ts.map +1 -1
- package/dist/testing/cross_backend/xfail.js +68 -23
- package/dist/testing/data_exposure.d.ts.map +1 -1
- package/dist/testing/data_exposure.js +4 -3
- package/dist/testing/integration.d.ts +1 -2
- package/dist/testing/integration.d.ts.map +1 -1
- package/dist/testing/integration.js +14 -8
- package/dist/testing/integration_helpers.d.ts +50 -3
- package/dist/testing/integration_helpers.d.ts.map +1 -1
- package/dist/testing/integration_helpers.js +87 -9
- package/dist/testing/middleware.d.ts +3 -1
- package/dist/testing/middleware.d.ts.map +1 -1
- package/dist/testing/middleware.js +14 -7
- package/dist/testing/resolved_auth.d.ts +3 -1
- package/dist/testing/resolved_auth.d.ts.map +1 -1
- package/dist/testing/resolved_auth.js +4 -4
- package/dist/testing/round_trip.d.ts +6 -2
- package/dist/testing/round_trip.d.ts.map +1 -1
- package/dist/testing/round_trip.js +17 -6
- package/dist/testing/rpc_envelope_cases.d.ts.map +1 -1
- package/dist/testing/rpc_envelope_cases.js +7 -0
- package/dist/testing/rpc_helpers.d.ts +4 -2
- package/dist/testing/rpc_helpers.d.ts.map +1 -1
- package/dist/testing/rpc_helpers.js +6 -1
- package/dist/testing/rpc_round_trip.d.ts +13 -2
- package/dist/testing/rpc_round_trip.d.ts.map +1 -1
- package/dist/testing/rpc_round_trip.js +25 -6
- package/dist/testing/schema_generators.d.ts +2 -2
- package/dist/testing/schema_generators.d.ts.map +1 -1
- package/dist/testing/schema_generators.js +4 -4
- package/dist/testing/stubs.d.ts +2 -2
- package/dist/testing/stubs.d.ts.map +1 -1
- package/dist/testing/stubs.js +13 -10
- package/dist/testing/transports/fetch_transport.d.ts +6 -3
- package/dist/testing/transports/fetch_transport.d.ts.map +1 -1
- package/dist/testing/transports/fetch_transport.js +31 -19
- package/dist/testing/transports/raw_http.d.ts +61 -1
- package/dist/testing/transports/raw_http.d.ts.map +1 -1
- package/dist/testing/transports/raw_http.js +61 -1
- package/dist/testing/transports/ws_raw_client.d.ts +20 -0
- package/dist/testing/transports/ws_raw_client.d.ts.map +1 -1
- package/dist/testing/transports/ws_raw_client.js +10 -4
- package/dist/testing/transports/ws_transport.d.ts +21 -1
- package/dist/testing/transports/ws_transport.d.ts.map +1 -1
- package/dist/testing/transports/ws_transport.js +58 -20
- package/dist/testing/ws_round_trip.d.ts.map +1 -1
- package/dist/testing/ws_round_trip.js +8 -4
- package/package.json +1 -1
|
@@ -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;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,mWAiBjC,CAAC;AACH,MAAM,MAAM,sBAAsB,GAAG,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAE1E;;;GAGG;AACH,eAAO,MAAM,uBAAuB,iXAAwD,CAAC;AAC7F,MAAM,MAAM,uBAAuB,GAAG,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAE5E,wDAAwD;AACxD,eAAO,MAAM,8BAA8B,EAAE,QAAQ,CAAC,MAAM,CAAC,uBAAuB,EAAE,MAAM,CAAC,CAwB5F,CAAC;AAEF,0DAA0D;AAC1D,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,IAAI,EAAE,uBAAuB,CAAC;IACvC,qEAAqE;IACrE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,oEAAoE;IACpE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACxB;AAKD;;;;;;;;GAQG;AACH,eAAO,MAAM,4BAA4B,GAAI,OAAO,mBAAmB,KAAG,MAOzE,CAAC;AAKF;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,KAAG,MAKxC,CAAC;AAUL;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,qBAAqB,GACjC,KAAK,MAAM,KACT,MAAM,CACR;IAAE,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAAC,QAAQ,EAAE,KAAK,CAAC,aAAa,CAAC,CAAA;CAAE,EAC1D;IAAE,MAAM,EAAE,KAAK,CAAC,mBAAmB,CAAC,CAAA;CAAE,CAqBtC,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC7B,sCAAsC;IACtC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,+CAA+C;IAC/C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,uFAAuF;IACvF,QAAQ,CAAC,WAAW,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;IACnD,4DAA4D;IAC5D,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,KAAK,GAAG,OAAO,CAAC;CAC1C;AAWD;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAAI,QAAQ,MAAM,KAAG,aAAa,GAAG,SAGlE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAC/B,QAAQ,MAAM,EACd,kBAAkB,aAAa,CAAC,MAAM,CAAC,KACrC,OAAqF,CAAC;AAEzF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,qBAAqB,GAEhC,kBAAkB,aAAa,CAAC,MAAM,CAAC,EACvC,aAAY,aAAa,CAAC,kBAAkB,CAAM,KAChD,OAcF,CAAC"}
|
package/dist/http/origin.js
CHANGED
|
@@ -21,24 +21,9 @@
|
|
|
21
21
|
import { escape_regexp } from '@fuzdev/fuz_util/regexp.ts';
|
|
22
22
|
import { one_of } from '@fuzdev/fuz_schema/schema.ts';
|
|
23
23
|
import { ERROR_FORBIDDEN_ORIGIN } from './error_schemas.js';
|
|
24
|
+
import { get_header_lines } from './header_lines.js';
|
|
25
|
+
import { read_origin } from './request_headers.js';
|
|
24
26
|
import { middleware_applies } from './schema_helpers.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 const is_browser_context = (c) => c.req.header('Origin') !== undefined || c.req.header('Referer') !== undefined;
|
|
42
27
|
/**
|
|
43
28
|
* Why one allowlist entry was refused, a `@fuzdev/fuz_schema` `one_of` whose
|
|
44
29
|
* `def` is the names. The wire names both spines emit — the Rust spine's
|
|
@@ -206,11 +191,13 @@ export const should_allow_origin = (origin, allowed_patterns) => VISIBLE_ASCII.t
|
|
|
206
191
|
*
|
|
207
192
|
* Origin allowlisting (not the CSRF layer — that's `SameSite: strict` cookies
|
|
208
193
|
* plus `http/simple_request.ts`):
|
|
209
|
-
* - Checks the `Origin`
|
|
194
|
+
* - Checks the one `Origin` line (if present) against the allowlist
|
|
210
195
|
* - Allows requests without an `Origin` header (direct access, curl, etc.)
|
|
211
|
-
* - Refuses
|
|
212
|
-
*
|
|
213
|
-
*
|
|
196
|
+
* - Refuses a malformed `Origin` (`read_origin` of `http/request_headers.ts`):
|
|
197
|
+
* an empty line, a second line, a byte that isn't visible ASCII — read from
|
|
198
|
+
* the lines the client sent (`get_header_lines`), so a runtime's own view of
|
|
199
|
+
* a repeated or empty line (`@hono/node-server` rebuilds a WebSocket
|
|
200
|
+
* upgrade's from Node's deduplicated one) decides nothing
|
|
214
201
|
*
|
|
215
202
|
* Origin-only by design — Fetch spec mandates `Origin` on every unsafe
|
|
216
203
|
* method (POST / PUT / DELETE / PATCH) regardless of `Referrer-Policy`,
|
|
@@ -233,10 +220,9 @@ export const verify_request_source = (allowed_patterns, carve_outs = []) => (c,
|
|
|
233
220
|
if (carve_outs.some((carve_out) => middleware_applies(carve_out.path, c.req.path))) {
|
|
234
221
|
return next();
|
|
235
222
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
if (origin !== undefined && !should_allow_origin(origin, allowed_patterns)) {
|
|
223
|
+
const origin = read_origin(get_header_lines(c, 'origin'));
|
|
224
|
+
if (origin.kind === 'refused' ||
|
|
225
|
+
(origin.kind === 'one' && !should_allow_origin(origin.value, allowed_patterns))) {
|
|
240
226
|
return c.json({ error: ERROR_FORBIDDEN_ORIGIN }, 403);
|
|
241
227
|
}
|
|
242
228
|
// no Origin — direct access (curl, CLI); token auth is the control
|
package/dist/http/proxy.d.ts
CHANGED
|
@@ -146,6 +146,7 @@ export declare const resolve_client_ip: (forwarded_for: string, proxies: Array<P
|
|
|
146
146
|
*
|
|
147
147
|
* @param options - trusted proxy configuration
|
|
148
148
|
* @mutates `c.var.client_ip` - set to the resolved (or `'unknown'`) client IP per request
|
|
149
|
+
* @mutates `c.var.connection_ip` - set to the connection's peer address, `null` when the runtime gave none (`CONNECTION_IP_KEY`)
|
|
149
150
|
* @throws Error if any entry in `options.trusted_proxies` is invalid (parsed eagerly via `parse_proxy_entry`)
|
|
150
151
|
*/
|
|
151
152
|
export declare const create_proxy_middleware: (options: ProxyOptions) => MiddlewareHandler;
|
package/dist/http/proxy.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../src/lib/http/proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAEvD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../src/lib/http/proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAEvD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAI3D;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,YAAY,GAAI,IAAI,MAAM,KAAG,MAA6B,CAAC;AAExE;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B,sFAAsF;IACtF,eAAe,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC/B,+DAA+D;IAC/D,iBAAiB,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,MAAM,GAAG,SAAS,CAAC;IACtD,wDAAwD;IACxD,GAAG,CAAC,EAAE,MAAM,CAAC;CACb;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GACpB;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAC/B;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAAC;AAEpF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,iBAAiB,GAAI,OAAO,MAAM,KAAG,WAgDjD,CAAC;AAiBF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,kBAAkB,GAAI,IAAI,MAAM,KAAG,MAAM,GAAG,MAAM,GAAG,SAWjE,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,GAAI,IAAI,MAAM,EAAE,SAAS,KAAK,CAAC,WAAW,CAAC,KAAG,OAqBvE,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,iBAAiB,GAC7B,eAAe,MAAM,EACrB,SAAS,KAAK,CAAC,WAAW,CAAC,KACzB,MAAM,GAAG,SAqBX,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,uBAAuB,GAAI,SAAS,YAAY,KAAG,iBA0C/D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,4BAA4B,GAAI,SAAS,YAAY,KAAG,cAInE,CAAC"}
|
package/dist/http/proxy.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { convertIPv4ToBinary, convertIPv6ToBinary, distinctRemoteAddr } from 'hono/utils/ipaddr';
|
|
11
11
|
import { canonicalize_ip, IP_LITERAL_CHARS } from './ip_canonical.js';
|
|
12
|
+
import { CONNECTION_IP_KEY } from '../hono_context.js';
|
|
12
13
|
/**
|
|
13
14
|
* Normalize an IP address for consistent matching and storage.
|
|
14
15
|
*
|
|
@@ -242,6 +243,7 @@ export const resolve_client_ip = (forwarded_for, proxies) => {
|
|
|
242
243
|
*
|
|
243
244
|
* @param options - trusted proxy configuration
|
|
244
245
|
* @mutates `c.var.client_ip` - set to the resolved (or `'unknown'`) client IP per request
|
|
246
|
+
* @mutates `c.var.connection_ip` - set to the connection's peer address, `null` when the runtime gave none (`CONNECTION_IP_KEY`)
|
|
245
247
|
* @throws Error if any entry in `options.trusted_proxies` is invalid (parsed eagerly via `parse_proxy_entry`)
|
|
246
248
|
*/
|
|
247
249
|
export const create_proxy_middleware = (options) => {
|
|
@@ -283,6 +285,7 @@ export const create_proxy_middleware = (options) => {
|
|
|
283
285
|
}
|
|
284
286
|
}
|
|
285
287
|
c.set('client_ip', client_ip);
|
|
288
|
+
c.set(CONNECTION_IP_KEY, connection_ip ?? null);
|
|
286
289
|
await next();
|
|
287
290
|
};
|
|
288
291
|
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The readers of the request headers the gates decide on — `Origin` (the
|
|
3
|
+
* origin check), `Origin` and `Referer` (browser context), `Host` (the host
|
|
4
|
+
* gate) and `Content-Type` (the CORS simple-request refusal) — as pure
|
|
5
|
+
* functions over header lines.
|
|
6
|
+
*
|
|
7
|
+
* One rule per reader, the Rust spine's `fuz_http::request_headers` reading
|
|
8
|
+
* the same one, and the shared table
|
|
9
|
+
* `testing/cross_backend/request_header_conformance.json` holding both to the
|
|
10
|
+
* same rows. Each reader takes the header's lines — one field value per
|
|
11
|
+
* header line, in the order sent, outer SP and HTAB already stripped
|
|
12
|
+
* (`get_header_lines` of `http/header_lines.ts` on a request) — so a header
|
|
13
|
+
* sent twice is something it can see.
|
|
14
|
+
*
|
|
15
|
+
* A malformed `Origin`, `Host` or `Content-Type` — an empty line, more than
|
|
16
|
+
* one line, a byte the grammar doesn't hold — reads `refused`, never
|
|
17
|
+
* `absent`: reading a malformed browser signal as no signal at all would fail
|
|
18
|
+
* open past the gate it feeds.
|
|
19
|
+
*
|
|
20
|
+
* **Join-invariance.** A runtime without a per-line view (Bun, an in-process
|
|
21
|
+
* `app.request`) hands the spine one line holding the repeated lines joined
|
|
22
|
+
* with `, `. No origin, host or media type holds a comma, so each reader
|
|
23
|
+
* refuses one anywhere in its value: the join of a repeat is then refused as
|
|
24
|
+
* the repeat itself is, and every reading is the same over the lines and over
|
|
25
|
+
* their join.
|
|
26
|
+
*
|
|
27
|
+
* Hono-free: lines in, a reading out.
|
|
28
|
+
*
|
|
29
|
+
* @module
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* One header's reading: none sent, exactly one well-formed line, or refused.
|
|
33
|
+
* Twin of the Rust `fuz_http::HeaderRead`.
|
|
34
|
+
*/
|
|
35
|
+
export type HeaderRead<T> = {
|
|
36
|
+
readonly kind: 'absent';
|
|
37
|
+
} | {
|
|
38
|
+
readonly kind: 'one';
|
|
39
|
+
readonly value: T;
|
|
40
|
+
} | {
|
|
41
|
+
readonly kind: 'refused';
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Read the `Origin` lines: `absent` when there are none, `one` for exactly one
|
|
45
|
+
* line of printable ASCII with no space or comma, `refused` otherwise — an
|
|
46
|
+
* empty line, a second line, a byte outside that set.
|
|
47
|
+
*
|
|
48
|
+
* The opaque origin `null` reads `one`: it is a value a browser sends, and the
|
|
49
|
+
* allowlist refuses it.
|
|
50
|
+
*
|
|
51
|
+
* @param origin_lines - the `Origin` header's lines
|
|
52
|
+
*/
|
|
53
|
+
export declare const read_origin: (origin_lines: ReadonlyArray<string>) => HeaderRead<string>;
|
|
54
|
+
/**
|
|
55
|
+
* Read the `Host` lines, by `read_origin`'s rule: `absent`, `one` well-formed
|
|
56
|
+
* line, or `refused` — an empty `Host` names nothing, and more than one is
|
|
57
|
+
* refused (RFC 9112 §3.2).
|
|
58
|
+
*
|
|
59
|
+
* @param host_lines - the `Host` header's lines
|
|
60
|
+
*/
|
|
61
|
+
export declare const read_host: (host_lines: ReadonlyArray<string>) => HeaderRead<string>;
|
|
62
|
+
/**
|
|
63
|
+
* Read the `Content-Type` lines to the MIME essence: `absent` when there are
|
|
64
|
+
* none, `one` with the essence (the part before any `;`, stripped of SP and
|
|
65
|
+
* HTAB, lowercased) when there is exactly one line of header text with no
|
|
66
|
+
* comma whose essence is `token "/" token`, `refused` otherwise.
|
|
67
|
+
*
|
|
68
|
+
* A comma is refused anywhere in the value, a quoted parameter's included: a
|
|
69
|
+
* joined repeat whose first line carries a parameter
|
|
70
|
+
* (`application/json; charset=utf-8, text/plain`) has a well-formed essence,
|
|
71
|
+
* and only refusing the comma reads it as the repeat it is.
|
|
72
|
+
*
|
|
73
|
+
* @param content_type_lines - the `Content-Type` header's lines
|
|
74
|
+
*/
|
|
75
|
+
export declare const read_content_type: (content_type_lines: ReadonlyArray<string>) => HeaderRead<string>;
|
|
76
|
+
/**
|
|
77
|
+
* True when the request carries a browser-context header — any `Origin` or
|
|
78
|
+
* `Referer` line, an empty or repeated one included. A presence test: a
|
|
79
|
+
* malformed browser signal is still a browser signal.
|
|
80
|
+
*
|
|
81
|
+
* The bearer (`auth/bearer_auth.ts`) and daemon-token
|
|
82
|
+
* (`auth/daemon_token_middleware.ts`) legs discard their credential when this
|
|
83
|
+
* is true, and the request continues without it: a stolen bearer token can't
|
|
84
|
+
* be replayed from a cross-origin page, and the loopback daemon token never
|
|
85
|
+
* legitimately carries an `Origin`. It is not a proof that the caller is no
|
|
86
|
+
* browser — a same-origin `GET` sends no `Origin`, and with
|
|
87
|
+
* `referrerPolicy: 'no-referrer'` no `Referer` either. Distinct from the
|
|
88
|
+
* origin check (`verify_request_source`), which gates a browser request
|
|
89
|
+
* against the allowlist.
|
|
90
|
+
*
|
|
91
|
+
* @param origin_lines - the `Origin` header's lines
|
|
92
|
+
* @param referer_lines - the `Referer` header's lines
|
|
93
|
+
*/
|
|
94
|
+
export declare const is_browser_context: (origin_lines: ReadonlyArray<string>, referer_lines: ReadonlyArray<string>) => boolean;
|
|
95
|
+
//# sourceMappingURL=request_headers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request_headers.d.ts","sourceRoot":"","sources":["../../src/lib/http/request_headers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAIH;;;GAGG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,IACrB;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,GAC3B;IAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GAC3C;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC;AAchC;;;;;;;;;GASG;AACH,eAAO,MAAM,WAAW,GAAI,cAAc,aAAa,CAAC,MAAM,CAAC,KAAG,UAAU,CAAC,MAAM,CACjD,CAAC;AAEnC;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GAAI,YAAY,aAAa,CAAC,MAAM,CAAC,KAAG,UAAU,CAAC,MAAM,CAC/C,CAAC;AASjC;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,iBAAiB,GAC7B,oBAAoB,aAAa,CAAC,MAAM,CAAC,KACvC,UAAU,CAAC,MAAM,CAQnB,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,kBAAkB,GAC9B,cAAc,aAAa,CAAC,MAAM,CAAC,EACnC,eAAe,aAAa,CAAC,MAAM,CAAC,KAClC,OAA8D,CAAC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The readers of the request headers the gates decide on — `Origin` (the
|
|
3
|
+
* origin check), `Origin` and `Referer` (browser context), `Host` (the host
|
|
4
|
+
* gate) and `Content-Type` (the CORS simple-request refusal) — as pure
|
|
5
|
+
* functions over header lines.
|
|
6
|
+
*
|
|
7
|
+
* One rule per reader, the Rust spine's `fuz_http::request_headers` reading
|
|
8
|
+
* the same one, and the shared table
|
|
9
|
+
* `testing/cross_backend/request_header_conformance.json` holding both to the
|
|
10
|
+
* same rows. Each reader takes the header's lines — one field value per
|
|
11
|
+
* header line, in the order sent, outer SP and HTAB already stripped
|
|
12
|
+
* (`get_header_lines` of `http/header_lines.ts` on a request) — so a header
|
|
13
|
+
* sent twice is something it can see.
|
|
14
|
+
*
|
|
15
|
+
* A malformed `Origin`, `Host` or `Content-Type` — an empty line, more than
|
|
16
|
+
* one line, a byte the grammar doesn't hold — reads `refused`, never
|
|
17
|
+
* `absent`: reading a malformed browser signal as no signal at all would fail
|
|
18
|
+
* open past the gate it feeds.
|
|
19
|
+
*
|
|
20
|
+
* **Join-invariance.** A runtime without a per-line view (Bun, an in-process
|
|
21
|
+
* `app.request`) hands the spine one line holding the repeated lines joined
|
|
22
|
+
* with `, `. No origin, host or media type holds a comma, so each reader
|
|
23
|
+
* refuses one anywhere in its value: the join of a repeat is then refused as
|
|
24
|
+
* the repeat itself is, and every reading is the same over the lines and over
|
|
25
|
+
* their join.
|
|
26
|
+
*
|
|
27
|
+
* Hono-free: lines in, a reading out.
|
|
28
|
+
*
|
|
29
|
+
* @module
|
|
30
|
+
*/
|
|
31
|
+
import { trim_optional_whitespace } from './header_lines.js';
|
|
32
|
+
const ABSENT = Object.freeze({ kind: 'absent' });
|
|
33
|
+
const REFUSED = Object.freeze({ kind: 'refused' });
|
|
34
|
+
/** Printable ASCII without the space or a comma — every byte of an origin or a host. */
|
|
35
|
+
const ORIGIN_OR_HOST_TEXT = /^[\x21-\x2b\x2d-\x7e]+$/;
|
|
36
|
+
/** Visible ASCII, the space and a tab, without a comma — what a `Content-Type` value may hold. */
|
|
37
|
+
const CONTENT_TYPE_TEXT = /^[\t\x20-\x2b\x2d-\x7e]*$/;
|
|
38
|
+
/** A MIME essence: `token "/" token` (RFC 9110 §8.3.1, §5.6.2). */
|
|
39
|
+
const MEDIA_TYPE_ESSENCE = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+\/[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
|
|
40
|
+
/**
|
|
41
|
+
* Read the `Origin` lines: `absent` when there are none, `one` for exactly one
|
|
42
|
+
* line of printable ASCII with no space or comma, `refused` otherwise — an
|
|
43
|
+
* empty line, a second line, a byte outside that set.
|
|
44
|
+
*
|
|
45
|
+
* The opaque origin `null` reads `one`: it is a value a browser sends, and the
|
|
46
|
+
* allowlist refuses it.
|
|
47
|
+
*
|
|
48
|
+
* @param origin_lines - the `Origin` header's lines
|
|
49
|
+
*/
|
|
50
|
+
export const read_origin = (origin_lines) => read_origin_or_host(origin_lines);
|
|
51
|
+
/**
|
|
52
|
+
* Read the `Host` lines, by `read_origin`'s rule: `absent`, `one` well-formed
|
|
53
|
+
* line, or `refused` — an empty `Host` names nothing, and more than one is
|
|
54
|
+
* refused (RFC 9112 §3.2).
|
|
55
|
+
*
|
|
56
|
+
* @param host_lines - the `Host` header's lines
|
|
57
|
+
*/
|
|
58
|
+
export const read_host = (host_lines) => read_origin_or_host(host_lines);
|
|
59
|
+
const read_origin_or_host = (lines) => {
|
|
60
|
+
if (lines.length === 0)
|
|
61
|
+
return ABSENT;
|
|
62
|
+
if (lines.length > 1)
|
|
63
|
+
return REFUSED;
|
|
64
|
+
const value = lines[0];
|
|
65
|
+
return ORIGIN_OR_HOST_TEXT.test(value) ? { kind: 'one', value } : REFUSED;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Read the `Content-Type` lines to the MIME essence: `absent` when there are
|
|
69
|
+
* none, `one` with the essence (the part before any `;`, stripped of SP and
|
|
70
|
+
* HTAB, lowercased) when there is exactly one line of header text with no
|
|
71
|
+
* comma whose essence is `token "/" token`, `refused` otherwise.
|
|
72
|
+
*
|
|
73
|
+
* A comma is refused anywhere in the value, a quoted parameter's included: a
|
|
74
|
+
* joined repeat whose first line carries a parameter
|
|
75
|
+
* (`application/json; charset=utf-8, text/plain`) has a well-formed essence,
|
|
76
|
+
* and only refusing the comma reads it as the repeat it is.
|
|
77
|
+
*
|
|
78
|
+
* @param content_type_lines - the `Content-Type` header's lines
|
|
79
|
+
*/
|
|
80
|
+
export const read_content_type = (content_type_lines) => {
|
|
81
|
+
if (content_type_lines.length === 0)
|
|
82
|
+
return ABSENT;
|
|
83
|
+
if (content_type_lines.length > 1)
|
|
84
|
+
return REFUSED;
|
|
85
|
+
const value = content_type_lines[0];
|
|
86
|
+
if (!CONTENT_TYPE_TEXT.test(value))
|
|
87
|
+
return REFUSED;
|
|
88
|
+
const semicolon = value.indexOf(';');
|
|
89
|
+
const essence = trim_optional_whitespace(semicolon === -1 ? value : value.slice(0, semicolon));
|
|
90
|
+
return MEDIA_TYPE_ESSENCE.test(essence) ? { kind: 'one', value: essence.toLowerCase() } : REFUSED;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* True when the request carries a browser-context header — any `Origin` or
|
|
94
|
+
* `Referer` line, an empty or repeated one included. A presence test: a
|
|
95
|
+
* malformed browser signal is still a browser signal.
|
|
96
|
+
*
|
|
97
|
+
* The bearer (`auth/bearer_auth.ts`) and daemon-token
|
|
98
|
+
* (`auth/daemon_token_middleware.ts`) legs discard their credential when this
|
|
99
|
+
* is true, and the request continues without it: a stolen bearer token can't
|
|
100
|
+
* be replayed from a cross-origin page, and the loopback daemon token never
|
|
101
|
+
* legitimately carries an `Origin`. It is not a proof that the caller is no
|
|
102
|
+
* browser — a same-origin `GET` sends no `Origin`, and with
|
|
103
|
+
* `referrerPolicy: 'no-referrer'` no `Referer` either. Distinct from the
|
|
104
|
+
* origin check (`verify_request_source`), which gates a browser request
|
|
105
|
+
* against the allowlist.
|
|
106
|
+
*
|
|
107
|
+
* @param origin_lines - the `Origin` header's lines
|
|
108
|
+
* @param referer_lines - the `Referer` header's lines
|
|
109
|
+
*/
|
|
110
|
+
export const is_browser_context = (origin_lines, referer_lines) => origin_lines.length > 0 || referer_lines.length > 0;
|