xtr-security-http 6.2.0__tar.gz → 6.3.0__tar.gz

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.
Files changed (265) hide show
  1. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/PKG-INFO +99 -26
  2. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/README.md +98 -25
  3. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/pyproject.toml +1 -1
  4. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/pyproject.toml.orig +1 -1
  5. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/__init__.py +8 -0
  6. xtr_security_http-6.3.0/src/xtr_security_http/_form_content_type.py +40 -0
  7. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/_request_parameters.py +35 -4
  8. xtr_security_http-6.3.0/src/xtr_security_http/_same_origin.py +76 -0
  9. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/access_token/form_encoded_body_extractor.py +19 -23
  10. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authentication/authentication_utils.py +12 -5
  11. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authentication/default_authentication_failure_handler.py +32 -22
  12. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authentication/default_authentication_success_handler.py +23 -16
  13. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/_form_login_credentials.py +11 -9
  14. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/_oidc_login_authorization.py +30 -2
  15. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/_oidc_login_callback.py +13 -7
  16. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/_oidc_login_options.py +14 -2
  17. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/abstract_login_form_authenticator.py +11 -3
  18. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/form_login_authenticator.py +4 -9
  19. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/json_login_authenticator.py +19 -10
  20. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/login_link_authenticator.py +1 -1
  21. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/oidc_login_authenticator.py +2 -2
  22. xtr_security_http-6.3.0/src/xtr_security_http/authenticator/token/post_authentication_token.py +88 -0
  23. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/event_listener/check_remember_me_conditions_listener.py +3 -3
  24. xtr_security_http-6.3.0/src/xtr_security_http/firewall/_switch_request.py +69 -0
  25. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/firewall/_user_refresh.py +50 -8
  26. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/firewall/authenticator_manager_listener.py +23 -3
  27. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/firewall/context_listener.py +53 -26
  28. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/firewall/exception_listener.py +9 -2
  29. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/firewall/logout_listener.py +10 -2
  30. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/firewall/switch_user_listener.py +13 -9
  31. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/firewall/user_changed.py +8 -31
  32. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/login_link/_presented_link.py +10 -10
  33. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/login_link/login_link_handler.py +4 -4
  34. xtr_security_http-6.3.0/src/xtr_security_http/session/__init__.py +24 -0
  35. xtr_security_http-6.3.0/src/xtr_security_http/session/_session_kinds.py +48 -0
  36. xtr_security_http-6.3.0/src/xtr_security_http/session/authentication_error_serializer.py +62 -0
  37. xtr_security_http-6.3.0/src/xtr_security_http/session/password_session_user.py +52 -0
  38. xtr_security_http-6.3.0/src/xtr_security_http/session/session_token_serializer.py +251 -0
  39. xtr_security_http-6.3.0/src/xtr_security_http/session/session_user.py +56 -0
  40. xtr_security_http-6.2.0/src/xtr_security_http/authenticator/token/post_authentication_token.py +0 -51
  41. xtr_security_http-6.2.0/src/xtr_security_http/firewall/_switch_request.py +0 -48
  42. xtr_security_http-6.2.0/src/xtr_security_http/session/__init__.py +0 -11
  43. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/LICENSE +0 -0
  44. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/_challenge.py +0 -0
  45. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/_security_state.py +0 -0
  46. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/access_map.py +0 -0
  47. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/access_map_interface.py +0 -0
  48. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/access_token/__init__.py +0 -0
  49. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/access_token/access_token_extractor_interface.py +0 -0
  50. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/access_token/access_token_handler_interface.py +0 -0
  51. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/access_token/chain_access_token_extractor.py +0 -0
  52. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/access_token/header_access_token_extractor.py +0 -0
  53. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/access_token/oauth2/__init__.py +0 -0
  54. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/access_token/oauth2/_introspected_user.py +0 -0
  55. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/access_token/oauth2/_introspection_claims.py +0 -0
  56. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/access_token/oauth2/_signed_response.py +0 -0
  57. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/access_token/oauth2/_signed_response_discovery.py +0 -0
  58. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/access_token/oauth2/oauth2_token_handler.py +0 -0
  59. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/access_token/oidc/__init__.py +0 -0
  60. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/access_token/oidc/exception/__init__.py +0 -0
  61. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/access_token/oidc/exception/invalid_signature_error.py +0 -0
  62. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/access_token/oidc/exception/missing_claim_error.py +0 -0
  63. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/access_token/oidc/exception/oidc_key_set_error.py +0 -0
  64. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/access_token/oidc/oidc_token_generator.py +0 -0
  65. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/access_token/oidc/oidc_token_handler.py +0 -0
  66. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/access_token/oidc/oidc_trait.py +0 -0
  67. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/access_token/oidc/oidc_user_info_token_handler.py +0 -0
  68. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/access_token/query_access_token_extractor.py +0 -0
  69. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/access_token/sender_constraint_interface.py +0 -0
  70. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authentication/__init__.py +0 -0
  71. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authentication/_authentication_outcome.py +0 -0
  72. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authentication/_manager_reporting.py +0 -0
  73. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authentication/_referer.py +0 -0
  74. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authentication/_sensitive.py +0 -0
  75. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authentication/_supports_pass.py +0 -0
  76. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authentication/authentication_failure_handler_interface.py +0 -0
  77. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authentication/authentication_success_handler_interface.py +0 -0
  78. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authentication/authenticator_manager.py +0 -0
  79. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authentication/authenticator_manager_interface.py +0 -0
  80. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authentication/custom_authentication_failure_handler.py +0 -0
  81. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authentication/custom_authentication_success_handler.py +0 -0
  82. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authentication/expose_security_level.py +0 -0
  83. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authentication/user_authenticator_interface.py +0 -0
  84. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/__init__.py +0 -0
  85. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/_access_token_challenge.py +0 -0
  86. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/_access_token_scopes.py +0 -0
  87. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/_oidc_login_attempts.py +0 -0
  88. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/_oidc_login_claims.py +0 -0
  89. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/_oidc_login_public_client.py +0 -0
  90. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/_oidc_login_token.py +0 -0
  91. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/abstract_authenticator.py +0 -0
  92. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/abstract_pre_authenticated_authenticator.py +0 -0
  93. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/access_token_authenticator.py +0 -0
  94. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/authenticator_interface.py +0 -0
  95. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/debug/__init__.py +0 -0
  96. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/debug/traceable_authenticator.py +0 -0
  97. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/debug/traceable_authenticator_manager_listener.py +0 -0
  98. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/debug/unsupported_reasons.py +0 -0
  99. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/fallback_user_loader.py +0 -0
  100. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/http_basic_authenticator.py +0 -0
  101. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/interactive_authenticator_interface.py +0 -0
  102. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/oidc/__init__.py +0 -0
  103. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/oidc/oidc_jwks.py +0 -0
  104. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/passport/__init__.py +0 -0
  105. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/passport/badge/__init__.py +0 -0
  106. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/passport/badge/authentication_method_badge.py +0 -0
  107. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/passport/badge/badge_interface.py +0 -0
  108. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/passport/badge/csrf_token_badge.py +0 -0
  109. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/passport/badge/password_upgrade_badge.py +0 -0
  110. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/passport/badge/pre_authenticated_user_badge.py +0 -0
  111. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/passport/badge/remember_me_badge.py +0 -0
  112. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/passport/badge/user_badge.py +0 -0
  113. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/passport/credentials/__init__.py +0 -0
  114. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/passport/credentials/credentials_interface.py +0 -0
  115. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/passport/credentials/custom_credentials.py +0 -0
  116. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/passport/credentials/password_credentials.py +0 -0
  117. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/passport/passport.py +0 -0
  118. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/passport/self_validating_passport.py +0 -0
  119. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/remember_me_authenticator.py +0 -0
  120. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/remote_user_authenticator.py +0 -0
  121. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/token/__init__.py +0 -0
  122. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authenticator/x509_authenticator.py +0 -0
  123. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authorization/__init__.py +0 -0
  124. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authorization/access_denied_handler_interface.py +0 -0
  125. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authorization/insufficient_scope_access_denied_handler.py +0 -0
  126. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/authorization/oauth2_scope_voter.py +0 -0
  127. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/command/__init__.py +0 -0
  128. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/command/_registry.py +0 -0
  129. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/command/oidc_token_generate_command.py +0 -0
  130. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/decorator/__init__.py +0 -0
  131. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/decorator/_methods.py +0 -0
  132. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/decorator/current_token.py +0 -0
  133. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/decorator/current_user.py +0 -0
  134. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/decorator/firewall_listener_order.py +0 -0
  135. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/decorator/is_csrf_token_valid.py +0 -0
  136. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/decorator/is_granted.py +0 -0
  137. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/decorator/is_granted_context.py +0 -0
  138. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/entry_point/__init__.py +0 -0
  139. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/entry_point/authentication_entry_point_interface.py +0 -0
  140. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/entry_point/fallback_authentication_entry_point_interface.py +0 -0
  141. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/entry_point/re_authentication_entry_point_interface.py +0 -0
  142. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/event/__init__.py +0 -0
  143. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/event/authentication_token_created_event.py +0 -0
  144. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/event/check_passport_event.py +0 -0
  145. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/event/check_refreshed_user_event.py +0 -0
  146. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/event/interactive_login_event.py +0 -0
  147. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/event/login_failure_event.py +0 -0
  148. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/event/login_success_event.py +0 -0
  149. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/event/logout_event.py +0 -0
  150. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/event/oidc_authorization_request_event.py +0 -0
  151. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/event/switch_user_event.py +0 -0
  152. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/event/token_deauthenticated_event.py +0 -0
  153. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/event_listener/__init__.py +0 -0
  154. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/event_listener/authentication_proofs_listener.py +0 -0
  155. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/event_listener/check_credentials_listener.py +0 -0
  156. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/event_listener/clear_site_data_listener.py +0 -0
  157. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/event_listener/cleared_cookie.py +0 -0
  158. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/event_listener/cookie_clearing_listener.py +0 -0
  159. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/event_listener/csrf_protection_listener.py +0 -0
  160. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/event_listener/csrf_token_clearing_listener.py +0 -0
  161. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/event_listener/default_logout_listener.py +0 -0
  162. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/event_listener/login_throttling_listener.py +0 -0
  163. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/event_listener/oidc_back_channel_logout_listener.py +0 -0
  164. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/event_listener/oidc_end_session_listener.py +0 -0
  165. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/event_listener/password_migrating_listener.py +0 -0
  166. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/event_listener/remember_me_listener.py +0 -0
  167. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/event_listener/save_session_listener.py +0 -0
  168. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/event_listener/session_logout_listener.py +0 -0
  169. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/event_listener/session_strategy_listener.py +0 -0
  170. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/event_listener/user_checker_listener.py +0 -0
  171. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/event_listener/user_provider_listener.py +0 -0
  172. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/exception/__init__.py +0 -0
  173. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/exception/expired_login_link_error.py +0 -0
  174. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/exception/impersonation_error.py +0 -0
  175. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/exception/invalid_access_token_error.py +0 -0
  176. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/exception/invalid_csrf_token_error.py +0 -0
  177. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/exception/invalid_login_link_authentication_error.py +0 -0
  178. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/exception/invalid_login_link_error.py +0 -0
  179. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/exception/invalid_login_link_error_interface.py +0 -0
  180. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/exception/invalid_session_strategy_error.py +0 -0
  181. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/exception/logout_error.py +0 -0
  182. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/exception/missing_session_error.py +0 -0
  183. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/exception/missing_state_bag_error.py +0 -0
  184. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/exception/oidc_invalid_grant_error.py +0 -0
  185. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/exception/oidc_session_ended_error.py +0 -0
  186. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/exception/unknown_firewall_error.py +0 -0
  187. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/firewall/__init__.py +0 -0
  188. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/firewall/_exception_answers.py +0 -0
  189. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/firewall/_re_authentication.py +0 -0
  190. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/firewall/_switch_load.py +0 -0
  191. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/firewall/_switch_uri.py +0 -0
  192. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/firewall/abstract_listener.py +0 -0
  193. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/firewall/access_listener.py +0 -0
  194. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/firewall/channel_listener.py +0 -0
  195. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/firewall/firewall.py +0 -0
  196. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/firewall/firewall_listener_interface.py +0 -0
  197. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/firewall/oidc_token_refresh_listener.py +0 -0
  198. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/firewall/refresh_user_result.py +0 -0
  199. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/firewall_context_interface.py +0 -0
  200. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/firewall_map.py +0 -0
  201. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/firewall_map_interface.py +0 -0
  202. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/http_utils.py +0 -0
  203. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/impersonate/__init__.py +0 -0
  204. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/impersonate/impersonate_url_generator.py +0 -0
  205. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/impersonate/impersonation_form.py +0 -0
  206. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/impersonate/switch_user_config.py +0 -0
  207. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/impersonate/switch_user_config_lookup_interface.py +0 -0
  208. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/login_link/__init__.py +0 -0
  209. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/login_link/login_link_details.py +0 -0
  210. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/login_link/login_link_handler_interface.py +0 -0
  211. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/logout/__init__.py +0 -0
  212. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/logout/logout_form.py +0 -0
  213. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/logout/logout_url_generator.py +0 -0
  214. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/oauth2/__init__.py +0 -0
  215. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/oauth2/access_token_type/__init__.py +0 -0
  216. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/oauth2/access_token_type/access_token_type_interface.py +0 -0
  217. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/oauth2/access_token_type/bearer_token_type.py +0 -0
  218. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/oauth2/client_authentication/__init__.py +0 -0
  219. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/oauth2/client_authentication/abstract_client_assertion.py +0 -0
  220. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/oauth2/client_authentication/abstract_tls_client_auth.py +0 -0
  221. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/oauth2/client_authentication/client_authentication_interface.py +0 -0
  222. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/oauth2/client_authentication/client_secret_basic.py +0 -0
  223. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/oauth2/client_authentication/client_secret_jwt.py +0 -0
  224. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/oauth2/client_authentication/client_secret_post.py +0 -0
  225. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/oauth2/client_authentication/no_client_authentication.py +0 -0
  226. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/oauth2/client_authentication/private_key_jwt.py +0 -0
  227. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/oauth2/client_authentication/self_signed_tls_client_auth.py +0 -0
  228. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/oauth2/client_authentication/tls_client_auth.py +0 -0
  229. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/oauth2/jws_algorithms.py +0 -0
  230. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/oidc/__init__.py +0 -0
  231. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/oidc/discovery_oidc_key_set_provider.py +0 -0
  232. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/oidc/oidc_back_channel_logout.py +0 -0
  233. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/oidc/oidc_client.py +0 -0
  234. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/oidc/oidc_client_interface.py +0 -0
  235. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/oidc/oidc_discovery.py +0 -0
  236. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/oidc/oidc_ended_sessions.py +0 -0
  237. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/oidc/oidc_id_token.py +0 -0
  238. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/oidc/oidc_jwks.py +0 -0
  239. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/oidc/oidc_logout_token.py +0 -0
  240. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/oidc/oidc_signature_verifier.py +0 -0
  241. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/oidc/oidc_token_refresher.py +0 -0
  242. /xtr_security_http-6.2.0/src/xtr_security_http/_parked_session.py → /xtr_security_http-6.3.0/src/xtr_security_http/parked_session.py +0 -0
  243. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/py.typed +0 -0
  244. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/rate_limiter/__init__.py +0 -0
  245. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/rate_limiter/default_login_rate_limiter.py +0 -0
  246. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/remember_me/__init__.py +0 -0
  247. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/remember_me/_signature_digest.py +0 -0
  248. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/remember_me/abstract_remember_me_handler.py +0 -0
  249. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/remember_me/persistent_remember_me_handler.py +0 -0
  250. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/remember_me/remember_me_cookie.py +0 -0
  251. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/remember_me/remember_me_details.py +0 -0
  252. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/remember_me/remember_me_handler_interface.py +0 -0
  253. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/remember_me/response_listener.py +0 -0
  254. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/remember_me/signature_remember_me_handler.py +0 -0
  255. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/resolver/__init__.py +0 -0
  256. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/resolver/csrf_token_checker.py +0 -0
  257. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/resolver/is_granted_checker.py +0 -0
  258. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/resolver/security_token_resolver.py +0 -0
  259. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/resolver/user_value_resolver.py +0 -0
  260. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/security_events.py +0 -0
  261. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/security_request_attributes.py +0 -0
  262. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/session/session_authentication_strategy.py +0 -0
  263. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/session/session_authentication_strategy_interface.py +0 -0
  264. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/util/__init__.py +0 -0
  265. {xtr_security_http-6.2.0 → xtr_security_http-6.3.0}/src/xtr_security_http/util/target_path.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xtr-security-http
3
- Version: 6.2.0
3
+ Version: 6.3.0
4
4
  Summary: The HTTP edge of xtr security: firewalls, authenticators, bearer access tokens and the request surface.
5
5
  Keywords: security,authentication,firewall,fastapi,oauth2
6
6
  Author: Xterr
@@ -281,9 +281,11 @@ user exists), checked after authentication, and settled on a `SwitchUserToken` t
281
281
  token the switch started from. The switch is announced as `SwitchUserEvent` under
282
282
  `SecurityEvents.SWITCH_USER` before the token is stored — a listener may replace it — and the
283
283
  request is answered with a redirect to the page it was asked at, the switch's own parameters
284
- stripped from the address. The exit is the same parameter carrying `SwitchUserListener.EXIT_VALUE`
285
- (`_exit`): the original token is restored, its user reloaded first, and the exit announced the
286
- same way. A `stateless` step switches without answering the request.
284
+ stripped from the address — on a dedicated path, to the submitted `_target_path` when it leads back
285
+ to the request's own origin, the same rule a login's target is held to, and to `/` otherwise. The
286
+ exit is the same parameter carrying `SwitchUserListener.EXIT_VALUE` (`_exit`): the original token
287
+ is restored, its user reloaded first, and the exit announced the same way. A `stateless` step
288
+ switches without answering the request.
287
289
 
288
290
  ### Logout
289
291
 
@@ -407,8 +409,10 @@ identifier and the denied attribute on the session for the page.
407
409
  **`JsonLoginAuthenticator(http_utils, user_provider, responses, success_handler=None,
408
410
  failure_handler=None, options=None)`** is the stateless sibling: a JSON body read by its configured
409
411
  paths (`username_path`, `password_path` — a dotted path walks a nested document), answered — when
410
- no failure handler is given — with a `401` carrying the error's message as JSON. The password is
411
- erased from the document before its fields ride along as remember-me parameters.
412
+ no failure handler is given — with a `401` carrying the error's message as JSON. A served request's
413
+ JSON body is read before the document is asked for, and the password is erased from a copy of the
414
+ document before its fields ride along as remember-me parameters — the request's own parsed body,
415
+ the one the route behind the firewall reads, is left as it arrived.
412
416
 
413
417
  **`HttpBasicAuthenticator(realm_name, user_provider, responses, logger=None)`** authenticates the
414
418
  `Authorization: Basic` header's credentials and is its own entry point: a `401` carrying
@@ -422,6 +426,14 @@ and **`DefaultAuthenticationFailureHandler(http_utils, options=None, logger=None
422
426
  firewall_name=None)`** keeps the error on the session for the form that renders again and redirects
423
427
  by its own ladder (`failure_path_parameter`, `failure_path`, then `login_path`), keeping the
424
428
  `Referer` as the return trip's target when `use_referer` is set and the handler knows its firewall.
429
+ A target the client names — the `target_path_parameter` (`_target_path`) or the
430
+ `failure_path_parameter` (`_failure_path`) a form or a query string carries, and the `Referer` the
431
+ success handler weighs — is honoured only when it leads back to the request's own origin: a path
432
+ opening with a single `/`, or an absolute `http(s)` URL with the request's scheme, host and port (a
433
+ port left out read as the scheme's). A protocol-relative `//host`, a target carrying a backslash or
434
+ a control character, a relative path and an address on any other origin all fall to the next rung,
435
+ so a link written elsewhere cannot send a caller who has just signed in off the site; the domain
436
+ regexps of `HttpUtils`, when configured, still weigh whichever target wins.
425
437
  **`CustomAuthenticationSuccessHandler(handler, options, firewall_name)`** and
426
438
  **`CustomAuthenticationFailureHandler(handler, options)`** are the seams for an application's own
427
439
  handlers, handing them the wiring's options — and the firewall's name, for a success handler that
@@ -645,7 +657,8 @@ callable `(message) -> bool`, for a rule none of the matchers above express.
645
657
  ### The context listener: a session's token, restored and written back
646
658
 
647
659
  **`ContextListener(token_storage, user_providers, context_key, session_storage, *, logger=None,
648
- dispatcher=None, trust_resolver=None)`** is the chain step a *stateful* firewall runs: it reads
660
+ dispatcher=None, trust_resolver=None, cookie=SessionCookieConfig())`** is the chain step a
661
+ *stateful* firewall runs: it reads
649
662
  the token the request's session carries — under the key `_security.<context>`, the firewall's
650
663
  own name composed onto the prefix every user-facing key of the flow carries — and restores it
651
664
  into the token storage, after refreshing the user it carries through the firewall's user
@@ -669,14 +682,65 @@ the switch with it, because a switch whose origin is gone has nothing to return
669
682
  holding no token, or something that is not one — a corrupt
670
683
  payload, a foreign class — leaves the storage empty the same way, without failing the request.
671
684
 
685
+ The session is built from the request here and nowhere else, reading its ID from the cookie
686
+ `cookie` describes — its name, path, domain, `Secure`, `HttpOnly`, `SameSite` and lifetime.
687
+ Every later step of the request reaches that same session, so the cookie a login's rotation, a
688
+ logout's invalidation and the save stage is always this one.
689
+ Any step reads it with **`parked_session_of(request)`** — `None` for a request no stateful chain ran.
690
+
672
691
  The response half, **`on_response(response_event)`** — registered beside the chain on the
673
692
  kernel's response event — writes the token back: what the request authenticated is stored under
674
693
  the same session key, and an anonymous request's key is removed, so a logout does not linger in
675
694
  the session. It runs only for the requests the request half marked with its own session key —
676
695
  the firewall-run mark — so a response of a request another firewall ran is left to that
677
- firewall's listener. The token is stored as the object it is: the session storage's own contract
678
- owns the wire format, and the lazy-object initialisation guard the upstream listener opens with
679
- has no lazy user to guard on this stack.
696
+ firewall's listener.
697
+
698
+ A session holds JSON and nothing else, whatever storage keeps it, so the token is stored as the
699
+ envelope a **`SessionTokenSerializer`** (`xtr_security_http.session`) writes —
700
+ `{"v": 1, "kind": …, "state": …, "user": …}` — and rebuilt from it on the next request. The kind
701
+ names the token's class as `module:QualifiedName`; the state is what the token's own
702
+ `to_session(encode_token)` answers — the roles, the attributes, the firewall, a switch's original
703
+ nested through the same serializer — and a token class is kept only when it defines
704
+ `from_session(state, user, decode_token)` in its own class body. The user part is the user's own
705
+ state when it implements `SessionSerializableUserInterface` (from `xtr_security_core`), named by
706
+ its kind, and otherwise a snapshot: its identifier, its roles and the `password_digest` of its
707
+ password, never the hash. `encode(token)` refuses, with `InvalidArgumentError` naming the
708
+ culprit, a token class without its own `from_session`, an attribute that does not come back from
709
+ JSON exactly as it went in — a tuple, a set, an object — and a user state that does not; the
710
+ response half raises it, so a token that cannot be kept fails the response rather than vanishing.
711
+
712
+ Reading never trusts the session. `decode(value)` looks a kind up only among the classes already
713
+ loaded — the subclasses of the token, user and error contracts, walked as they are — and never
714
+ imports anything a session names. What it cannot rebuild reads as no token, and the request half
715
+ answers that the way it answers a corrupt payload: a warning naming the value's type, and the
716
+ request goes on anonymous. That is anything that is no envelope — an object a session held
717
+ before, another version — a kind no loaded class answers to, and a state its class's
718
+ `from_session` refuses as malformed. An envelope keeping no user rebuilds a token carrying none,
719
+ which the request half refuses with `InvalidArgumentError`; a user no provider supports is
720
+ `UnsupportedUserError`, raised by the refresh as ever.
721
+
722
+ What the providers are handed follows from what the session kept. A user kept whole is rebuilt
723
+ as its own class and refreshed through `refresh_user(user)`, the providers' contract unchanged. A
724
+ snapshot is rebuilt as a **`SessionUser`** stand-in — a **`PasswordSessionUser`** carrying the
725
+ digest as its password when the user carried one, so the comparison still sees which side
726
+ stopped carrying a password — and the refresh asks each provider for
727
+ `load_user_by_identifier(identifier)` instead, skipping one whose answer is of a class it does
728
+ not support: the stand-in never reaches `refresh_user`, where a provider might merge it into what
729
+ it stores. The answer is weighed against the stand-in exactly as a reload is weighed against the
730
+ user it reloads — the digest of an unchanged password reads as the same password — so a changed
731
+ password, a role granted or withdrawn, or another identifier still logs the user out.
732
+
733
+ The last authentication error a failed login redirects with is kept the same way:
734
+ `authentication_error_to_session(error)` (`xtr_security_http.session.authentication_error_serializer`)
735
+ stores its class, its message key and the entries of its message data that survive JSON — never
736
+ the internal message — and `AuthenticationUtils.get_last_authentication_error()` rebuilds it
737
+ through `authentication_error_from_session(value)`, as the class it was when that class is
738
+ loaded and as a plain `AuthenticationError` otherwise, its `str()` the key. The error a request
739
+ parks on its own security state stays the live error.
740
+
741
+ The session store is the trust boundary: nothing in an envelope is signed or encrypted, so token
742
+ attributes — the OIDC login's ID, access and refresh tokens among them — and the user's state sit
743
+ in it as plaintext JSON.
680
744
 
681
745
  The session itself reaches the storage through **`SaveSessionListener`** — the last word on
682
746
  the kernel's response event, at priority `-1000`, below every other listener, so the token
@@ -944,18 +1008,26 @@ ever makes it: documentation.
944
1008
  back to the token the storage holds. Without the fallback a switch's
945
1009
  denial on a restored session would be read as an anonymous caller and
946
1010
  answered with the entry point's redirect instead of the `403` it earned.
947
- - **The chain's request carries its body unparsed.** The firewall runs at
948
- the request event, where the served message is born with its body lazy:
949
- `get_parsed_body()` answers what has been materialised so far, and nothing
950
- in the chain materialises it — that happens where the route's own request
951
- service is built. A reader that awaits the body (the form-encoded
952
- access-token extractor) materialises it itself; the plain parameter
953
- readers see nothing of the body at chain time, so a submission's fields
954
- ride the query string, the fallback the landed readers document — a form
955
- login with `post_only` off reads the query first, and the logout's, the
956
- switch's and the login link's proofs all read the query string beside the
957
- body. A login page's own route, running after the materialisation, reads
958
- the body as ever.
1011
+ - **The chain reads a posted form before asking for its fields.** The
1012
+ firewall runs at the request event, where the served message is born with
1013
+ its body lazy: `get_parsed_body()` answers what a read of the body has
1014
+ materialised so far — on the message and on every copy of it a step is
1015
+ handed. So every reader of a posted parameter reads the body first, and
1016
+ only a form's: a body encoded `application/x-www-form-urlencoded` or
1017
+ `multipart/form-data` is read before its fields are asked for, and a body
1018
+ of any other media type is left unread — no step buffers an upload for a
1019
+ parameter it cannot carry. A form login reads its username and password
1020
+ from the posted body (the body alone while `post_only` stands, the query
1021
+ first when it is off) and its forgery token from the query first, then the
1022
+ body; `_target_path`, `_failure_path` and `_remember_me` are read from it
1023
+ too, and so are the logout's forgery token, the switch's username and its
1024
+ proof, a followed login link's parameters and an OIDC `form_post`
1025
+ callback. The JSON login reads a JSON body before its document. The
1026
+ authentication step reads a submitted form — a `POST` encoded as one —
1027
+ before it hands the request to the manager, too, so an authenticator of
1028
+ the application's own that asks for the parsed body directly finds the
1029
+ form's fields. The body stays readable for the route behind the firewall,
1030
+ which reads it as ever.
959
1031
  - **A route cannot read the chain's parked state through its own request
960
1032
  message.** What the chain parks — the session the context listener
961
1033
  reattached, the error a failed login left, the last username — lives on
@@ -1050,9 +1122,9 @@ ever makes it: documentation.
1050
1122
  kernel's event accepts, so both are constructor parameters.
1051
1123
  - **The switch's target route is not ported.** Upstream can redirect a completed switch to
1052
1124
  a configured `target_route` through a routing component; no routing component exists here,
1053
- so the redirect falls to the request's own stripped URI — or the submitted `_target_path`
1054
- and then `/` on a dedicated path — and the generator refuses a dedicated path configured
1055
- as a route name.
1125
+ so the redirect falls to the request's own stripped URI — or, on a dedicated path, the
1126
+ submitted `_target_path` when it is on the request's own origin, and then `/` — and the
1127
+ generator refuses a dedicated path configured as a route name.
1056
1128
  - **The query strip is written on the URI's text.** Upstream removes the switch's parameters
1057
1129
  from the request's query bag and rebuilds the query string; a request message is immutable
1058
1130
  here, so the strip removes each parameter's pattern from the URI text and mends the join,
@@ -1717,7 +1789,8 @@ xtr_security_http/
1717
1789
  ├── logout/ LogoutUrlGenerator, LogoutForm — the logout addresses
1718
1790
  ├── remember_me/ the handlers, details, staged cookie and response pass of a
1719
1791
  │ login the user asked to outlive its session
1720
- ├── session/ what a login does to the session it reattached
1792
+ ├── session/ the JSON a session keeps of the token and the last error,
1793
+ │ and what a login does to the session it reattached
1721
1794
  ├── command/ the console command: security:oidc:generate-token
1722
1795
  └── exception/ the errors this package adds
1723
1796
  ```
@@ -242,9 +242,11 @@ user exists), checked after authentication, and settled on a `SwitchUserToken` t
242
242
  token the switch started from. The switch is announced as `SwitchUserEvent` under
243
243
  `SecurityEvents.SWITCH_USER` before the token is stored — a listener may replace it — and the
244
244
  request is answered with a redirect to the page it was asked at, the switch's own parameters
245
- stripped from the address. The exit is the same parameter carrying `SwitchUserListener.EXIT_VALUE`
246
- (`_exit`): the original token is restored, its user reloaded first, and the exit announced the
247
- same way. A `stateless` step switches without answering the request.
245
+ stripped from the address — on a dedicated path, to the submitted `_target_path` when it leads back
246
+ to the request's own origin, the same rule a login's target is held to, and to `/` otherwise. The
247
+ exit is the same parameter carrying `SwitchUserListener.EXIT_VALUE` (`_exit`): the original token
248
+ is restored, its user reloaded first, and the exit announced the same way. A `stateless` step
249
+ switches without answering the request.
248
250
 
249
251
  ### Logout
250
252
 
@@ -368,8 +370,10 @@ identifier and the denied attribute on the session for the page.
368
370
  **`JsonLoginAuthenticator(http_utils, user_provider, responses, success_handler=None,
369
371
  failure_handler=None, options=None)`** is the stateless sibling: a JSON body read by its configured
370
372
  paths (`username_path`, `password_path` — a dotted path walks a nested document), answered — when
371
- no failure handler is given — with a `401` carrying the error's message as JSON. The password is
372
- erased from the document before its fields ride along as remember-me parameters.
373
+ no failure handler is given — with a `401` carrying the error's message as JSON. A served request's
374
+ JSON body is read before the document is asked for, and the password is erased from a copy of the
375
+ document before its fields ride along as remember-me parameters — the request's own parsed body,
376
+ the one the route behind the firewall reads, is left as it arrived.
373
377
 
374
378
  **`HttpBasicAuthenticator(realm_name, user_provider, responses, logger=None)`** authenticates the
375
379
  `Authorization: Basic` header's credentials and is its own entry point: a `401` carrying
@@ -383,6 +387,14 @@ and **`DefaultAuthenticationFailureHandler(http_utils, options=None, logger=None
383
387
  firewall_name=None)`** keeps the error on the session for the form that renders again and redirects
384
388
  by its own ladder (`failure_path_parameter`, `failure_path`, then `login_path`), keeping the
385
389
  `Referer` as the return trip's target when `use_referer` is set and the handler knows its firewall.
390
+ A target the client names — the `target_path_parameter` (`_target_path`) or the
391
+ `failure_path_parameter` (`_failure_path`) a form or a query string carries, and the `Referer` the
392
+ success handler weighs — is honoured only when it leads back to the request's own origin: a path
393
+ opening with a single `/`, or an absolute `http(s)` URL with the request's scheme, host and port (a
394
+ port left out read as the scheme's). A protocol-relative `//host`, a target carrying a backslash or
395
+ a control character, a relative path and an address on any other origin all fall to the next rung,
396
+ so a link written elsewhere cannot send a caller who has just signed in off the site; the domain
397
+ regexps of `HttpUtils`, when configured, still weigh whichever target wins.
386
398
  **`CustomAuthenticationSuccessHandler(handler, options, firewall_name)`** and
387
399
  **`CustomAuthenticationFailureHandler(handler, options)`** are the seams for an application's own
388
400
  handlers, handing them the wiring's options — and the firewall's name, for a success handler that
@@ -606,7 +618,8 @@ callable `(message) -> bool`, for a rule none of the matchers above express.
606
618
  ### The context listener: a session's token, restored and written back
607
619
 
608
620
  **`ContextListener(token_storage, user_providers, context_key, session_storage, *, logger=None,
609
- dispatcher=None, trust_resolver=None)`** is the chain step a *stateful* firewall runs: it reads
621
+ dispatcher=None, trust_resolver=None, cookie=SessionCookieConfig())`** is the chain step a
622
+ *stateful* firewall runs: it reads
610
623
  the token the request's session carries — under the key `_security.<context>`, the firewall's
611
624
  own name composed onto the prefix every user-facing key of the flow carries — and restores it
612
625
  into the token storage, after refreshing the user it carries through the firewall's user
@@ -630,14 +643,65 @@ the switch with it, because a switch whose origin is gone has nothing to return
630
643
  holding no token, or something that is not one — a corrupt
631
644
  payload, a foreign class — leaves the storage empty the same way, without failing the request.
632
645
 
646
+ The session is built from the request here and nowhere else, reading its ID from the cookie
647
+ `cookie` describes — its name, path, domain, `Secure`, `HttpOnly`, `SameSite` and lifetime.
648
+ Every later step of the request reaches that same session, so the cookie a login's rotation, a
649
+ logout's invalidation and the save stage is always this one.
650
+ Any step reads it with **`parked_session_of(request)`** — `None` for a request no stateful chain ran.
651
+
633
652
  The response half, **`on_response(response_event)`** — registered beside the chain on the
634
653
  kernel's response event — writes the token back: what the request authenticated is stored under
635
654
  the same session key, and an anonymous request's key is removed, so a logout does not linger in
636
655
  the session. It runs only for the requests the request half marked with its own session key —
637
656
  the firewall-run mark — so a response of a request another firewall ran is left to that
638
- firewall's listener. The token is stored as the object it is: the session storage's own contract
639
- owns the wire format, and the lazy-object initialisation guard the upstream listener opens with
640
- has no lazy user to guard on this stack.
657
+ firewall's listener.
658
+
659
+ A session holds JSON and nothing else, whatever storage keeps it, so the token is stored as the
660
+ envelope a **`SessionTokenSerializer`** (`xtr_security_http.session`) writes —
661
+ `{"v": 1, "kind": …, "state": …, "user": …}` — and rebuilt from it on the next request. The kind
662
+ names the token's class as `module:QualifiedName`; the state is what the token's own
663
+ `to_session(encode_token)` answers — the roles, the attributes, the firewall, a switch's original
664
+ nested through the same serializer — and a token class is kept only when it defines
665
+ `from_session(state, user, decode_token)` in its own class body. The user part is the user's own
666
+ state when it implements `SessionSerializableUserInterface` (from `xtr_security_core`), named by
667
+ its kind, and otherwise a snapshot: its identifier, its roles and the `password_digest` of its
668
+ password, never the hash. `encode(token)` refuses, with `InvalidArgumentError` naming the
669
+ culprit, a token class without its own `from_session`, an attribute that does not come back from
670
+ JSON exactly as it went in — a tuple, a set, an object — and a user state that does not; the
671
+ response half raises it, so a token that cannot be kept fails the response rather than vanishing.
672
+
673
+ Reading never trusts the session. `decode(value)` looks a kind up only among the classes already
674
+ loaded — the subclasses of the token, user and error contracts, walked as they are — and never
675
+ imports anything a session names. What it cannot rebuild reads as no token, and the request half
676
+ answers that the way it answers a corrupt payload: a warning naming the value's type, and the
677
+ request goes on anonymous. That is anything that is no envelope — an object a session held
678
+ before, another version — a kind no loaded class answers to, and a state its class's
679
+ `from_session` refuses as malformed. An envelope keeping no user rebuilds a token carrying none,
680
+ which the request half refuses with `InvalidArgumentError`; a user no provider supports is
681
+ `UnsupportedUserError`, raised by the refresh as ever.
682
+
683
+ What the providers are handed follows from what the session kept. A user kept whole is rebuilt
684
+ as its own class and refreshed through `refresh_user(user)`, the providers' contract unchanged. A
685
+ snapshot is rebuilt as a **`SessionUser`** stand-in — a **`PasswordSessionUser`** carrying the
686
+ digest as its password when the user carried one, so the comparison still sees which side
687
+ stopped carrying a password — and the refresh asks each provider for
688
+ `load_user_by_identifier(identifier)` instead, skipping one whose answer is of a class it does
689
+ not support: the stand-in never reaches `refresh_user`, where a provider might merge it into what
690
+ it stores. The answer is weighed against the stand-in exactly as a reload is weighed against the
691
+ user it reloads — the digest of an unchanged password reads as the same password — so a changed
692
+ password, a role granted or withdrawn, or another identifier still logs the user out.
693
+
694
+ The last authentication error a failed login redirects with is kept the same way:
695
+ `authentication_error_to_session(error)` (`xtr_security_http.session.authentication_error_serializer`)
696
+ stores its class, its message key and the entries of its message data that survive JSON — never
697
+ the internal message — and `AuthenticationUtils.get_last_authentication_error()` rebuilds it
698
+ through `authentication_error_from_session(value)`, as the class it was when that class is
699
+ loaded and as a plain `AuthenticationError` otherwise, its `str()` the key. The error a request
700
+ parks on its own security state stays the live error.
701
+
702
+ The session store is the trust boundary: nothing in an envelope is signed or encrypted, so token
703
+ attributes — the OIDC login's ID, access and refresh tokens among them — and the user's state sit
704
+ in it as plaintext JSON.
641
705
 
642
706
  The session itself reaches the storage through **`SaveSessionListener`** — the last word on
643
707
  the kernel's response event, at priority `-1000`, below every other listener, so the token
@@ -905,18 +969,26 @@ ever makes it: documentation.
905
969
  back to the token the storage holds. Without the fallback a switch's
906
970
  denial on a restored session would be read as an anonymous caller and
907
971
  answered with the entry point's redirect instead of the `403` it earned.
908
- - **The chain's request carries its body unparsed.** The firewall runs at
909
- the request event, where the served message is born with its body lazy:
910
- `get_parsed_body()` answers what has been materialised so far, and nothing
911
- in the chain materialises it — that happens where the route's own request
912
- service is built. A reader that awaits the body (the form-encoded
913
- access-token extractor) materialises it itself; the plain parameter
914
- readers see nothing of the body at chain time, so a submission's fields
915
- ride the query string, the fallback the landed readers document — a form
916
- login with `post_only` off reads the query first, and the logout's, the
917
- switch's and the login link's proofs all read the query string beside the
918
- body. A login page's own route, running after the materialisation, reads
919
- the body as ever.
972
+ - **The chain reads a posted form before asking for its fields.** The
973
+ firewall runs at the request event, where the served message is born with
974
+ its body lazy: `get_parsed_body()` answers what a read of the body has
975
+ materialised so far — on the message and on every copy of it a step is
976
+ handed. So every reader of a posted parameter reads the body first, and
977
+ only a form's: a body encoded `application/x-www-form-urlencoded` or
978
+ `multipart/form-data` is read before its fields are asked for, and a body
979
+ of any other media type is left unread — no step buffers an upload for a
980
+ parameter it cannot carry. A form login reads its username and password
981
+ from the posted body (the body alone while `post_only` stands, the query
982
+ first when it is off) and its forgery token from the query first, then the
983
+ body; `_target_path`, `_failure_path` and `_remember_me` are read from it
984
+ too, and so are the logout's forgery token, the switch's username and its
985
+ proof, a followed login link's parameters and an OIDC `form_post`
986
+ callback. The JSON login reads a JSON body before its document. The
987
+ authentication step reads a submitted form — a `POST` encoded as one —
988
+ before it hands the request to the manager, too, so an authenticator of
989
+ the application's own that asks for the parsed body directly finds the
990
+ form's fields. The body stays readable for the route behind the firewall,
991
+ which reads it as ever.
920
992
  - **A route cannot read the chain's parked state through its own request
921
993
  message.** What the chain parks — the session the context listener
922
994
  reattached, the error a failed login left, the last username — lives on
@@ -1011,9 +1083,9 @@ ever makes it: documentation.
1011
1083
  kernel's event accepts, so both are constructor parameters.
1012
1084
  - **The switch's target route is not ported.** Upstream can redirect a completed switch to
1013
1085
  a configured `target_route` through a routing component; no routing component exists here,
1014
- so the redirect falls to the request's own stripped URI — or the submitted `_target_path`
1015
- and then `/` on a dedicated path — and the generator refuses a dedicated path configured
1016
- as a route name.
1086
+ so the redirect falls to the request's own stripped URI — or, on a dedicated path, the
1087
+ submitted `_target_path` when it is on the request's own origin, and then `/` — and the
1088
+ generator refuses a dedicated path configured as a route name.
1017
1089
  - **The query strip is written on the URI's text.** Upstream removes the switch's parameters
1018
1090
  from the request's query bag and rebuilds the query string; a request message is immutable
1019
1091
  here, so the strip removes each parameter's pattern from the URI text and mends the join,
@@ -1678,7 +1750,8 @@ xtr_security_http/
1678
1750
  ├── logout/ LogoutUrlGenerator, LogoutForm — the logout addresses
1679
1751
  ├── remember_me/ the handlers, details, staged cookie and response pass of a
1680
1752
  │ login the user asked to outlive its session
1681
- ├── session/ what a login does to the session it reattached
1753
+ ├── session/ the JSON a session keeps of the token and the last error,
1754
+ │ and what a login does to the session it reattached
1682
1755
  ├── command/ the console command: security:oidc:generate-token
1683
1756
  └── exception/ the errors this package adds
1684
1757
  ```
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "xtr-security-http"
3
- version = "6.2.0"
3
+ version = "6.3.0"
4
4
  description = "The HTTP edge of xtr security: firewalls, authenticators, bearer access tokens and the request surface."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "xtr-security-http"
3
- version = "6.2.0"
3
+ version = "6.3.0"
4
4
  description = "The HTTP edge of xtr security: firewalls, authenticators, bearer access tokens and the request surface."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
@@ -172,6 +172,7 @@ from .login_link import (
172
172
  LoginLinkHandlerInterface,
173
173
  )
174
174
  from .logout import LogoutForm, LogoutUrlGenerator
175
+ from .parked_session import parked_session_of
175
176
  from .rate_limiter import DefaultLoginRateLimiter
176
177
  from .remember_me import (
177
178
  AbstractRememberMeHandler,
@@ -191,8 +192,11 @@ from .resolver import (
191
192
  from .security_events import SecurityEvents
192
193
  from .security_request_attributes import SecurityRequestAttributes
193
194
  from .session import (
195
+ PasswordSessionUser,
194
196
  SessionAuthenticationStrategy,
195
197
  SessionAuthenticationStrategyInterface,
198
+ SessionTokenSerializer,
199
+ SessionUser,
196
200
  )
197
201
  from .util import get_target_path, remove_target_path, save_target_path
198
202
 
@@ -303,6 +307,7 @@ __all__ = [
303
307
  "Passport",
304
308
  "PasswordCredentials",
305
309
  "PasswordMigratingListener",
310
+ "PasswordSessionUser",
306
311
  "PasswordUpgradeBadge",
307
312
  "PersistentRememberMeHandler",
308
313
  "PostAuthenticationToken",
@@ -328,6 +333,8 @@ __all__ = [
328
333
  "SessionAuthenticationStrategyInterface",
329
334
  "SessionLogoutListener",
330
335
  "SessionStrategyListener",
336
+ "SessionTokenSerializer",
337
+ "SessionUser",
331
338
  "SignatureRememberMeHandler",
332
339
  "SwitchUserConfig",
333
340
  "SwitchUserConfigLookupInterface",
@@ -350,6 +357,7 @@ __all__ = [
350
357
  "is_sensitive",
351
358
  "mask",
352
359
  "oauth2_scope",
360
+ "parked_session_of",
353
361
  "parse_oauth2_scope",
354
362
  "remove_target_path",
355
363
  "save_target_path",
@@ -0,0 +1,40 @@
1
+ """Telling a submitted form by the media type its body is encoded in.
2
+
3
+ Every step that reads a body for the form it may carry asks it first: the
4
+ chain's authentication step, which reads a submitted form before handing the
5
+ request on; the readers of a posted parameter; the form login, which may refuse
6
+ a submission that is not one; the extractor of a bearer token posted in a form.
7
+ They all read the ``Content-Type`` by the one rule here, so a request one of
8
+ them takes for a form the others do too.
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ from typing import Final
14
+
15
+ __all__ = ["is_form_content_type"]
16
+
17
+ #: The media types a submitted form is encoded in.
18
+ _FORM_MEDIA_TYPES: Final = frozenset({"application/x-www-form-urlencoded", "multipart/form-data"})
19
+
20
+
21
+ def is_form_content_type(
22
+ content_type: str,
23
+ *,
24
+ media_types: frozenset[str] = _FORM_MEDIA_TYPES,
25
+ ) -> bool:
26
+ """Tell whether a ``Content-Type`` header names one of the form encodings.
27
+
28
+ The media type is weighed whole — its parameters dropped, its case
29
+ ignored — and must be one of the encodings exactly: the rule by which the
30
+ kernel decides that a body parses into a form, so a request told for a
31
+ form here is one whose parsed body holds the form's fields. A type that
32
+ only starts like one, ``application/x-www-form-urlencodedX``, is no form.
33
+
34
+ Args:
35
+ content_type: The value of the ``Content-Type`` header.
36
+ media_types: The form encodings that count — both by default. A
37
+ reader that parses only one of them narrows the set to it, and
38
+ the media type is weighed against it by the same rule.
39
+ """
40
+ return content_type.partition(";")[0].strip().lower() in media_types
@@ -7,6 +7,12 @@ so the answer starts by narrowing: only a mapping carries named parameters,
7
7
  and anything else reads as carrying none. Each reader hands back the value
8
8
  as it arrived — narrowing it to text is the caller's, who knows what a
9
9
  parameter means to it.
10
+
11
+ A request the server is still serving is born with its body unread, and its
12
+ parsed side answers only what a read of the body has yielded — so the body of
13
+ a submitted form is read before its fields are asked for. Only a form's: a
14
+ body of any other media type carries no named parameter to find, and reading
15
+ it would buffer an upload for nothing.
10
16
  """
11
17
 
12
18
  from __future__ import annotations
@@ -14,13 +20,36 @@ from __future__ import annotations
14
20
  from collections.abc import Mapping
15
21
  from typing import TYPE_CHECKING, cast
16
22
 
23
+ from xtr_security_http._form_content_type import is_form_content_type
24
+
17
25
  if TYPE_CHECKING:
18
26
  from xtr_http_message_contracts import ServerRequestInterface
19
27
 
20
- __all__ = ["header_parameter", "payload_parameter", "query_parameter"]
28
+ __all__ = ["header_parameter", "payload_parameter", "query_parameter", "read_payload"]
29
+
30
+
31
+ async def read_payload(request: ServerRequestInterface) -> object | None:
32
+ """Return what the request's body parsed into, reading a submitted form first.
33
+
34
+ A served request fills its parsed side as its body is read, so a form's
35
+ fields are there only once something has read it: the read comes first,
36
+ and once the body is in the buffer it is a read of the buffer, the wire
37
+ left alone. A body of any other media type is not read here, and what it
38
+ parsed into — if anything has parsed it — is answered as it is.
39
+
40
+ Args:
41
+ request: The request whose body is read.
42
+
43
+ Returns:
44
+ Whatever parsing the body yielded, or ``None`` when nothing has been
45
+ parsed into the request.
46
+ """
47
+ if is_form_content_type(request.get_header_line("Content-Type")):
48
+ _ = await request.get_body().get_contents()
49
+ return request.get_parsed_body()
21
50
 
22
51
 
23
- def payload_parameter(
52
+ async def payload_parameter(
24
53
  request: ServerRequestInterface,
25
54
  name: str,
26
55
  default: object | None = None,
@@ -30,7 +59,9 @@ def payload_parameter(
30
59
  A body is parsed into whatever its content type says it carries, so what
31
60
  comes back need not be named parameters at all — a JSON array, or
32
61
  nothing for a request with no body. Either reads as carrying no
33
- parameter, which is what a request that is not a form amounts to.
62
+ parameter, which is what a request that is not a form amounts to. The
63
+ body is read first when it is a submitted form, the way
64
+ :func:`read_payload` reads it.
34
65
 
35
66
  Args:
36
67
  request: The request whose body is read.
@@ -40,7 +71,7 @@ def payload_parameter(
40
71
  Returns:
41
72
  The value under ``name``, or ``default``.
42
73
  """
43
- body = request.get_parsed_body()
74
+ body = await read_payload(request)
44
75
  if not isinstance(body, Mapping):
45
76
  return default
46
77
 
@@ -0,0 +1,76 @@
1
+ r"""Telling whether a redirect target the client named leads back to the request's origin.
2
+
3
+ A login, a failed login and a user switch can each be told where to send the
4
+ caller next: a field of the submitted form, a parameter of the query string,
5
+ the page the caller came from. The client wrote that target — and so did
6
+ whoever wrote the link or the page the client followed — so a target on
7
+ another site, honoured as it is, sends a caller who has just signed in off to
8
+ it. A target the client named is honoured only when it leads back to the
9
+ origin the request reached: a path of the application's own, or an absolute
10
+ URL carrying the request's scheme, host and port.
11
+
12
+ The target is weighed the way a browser reads it, not only the way a URL
13
+ parser does. A browser reads a ``\`` in an ``http(s)`` address as a ``/``, and
14
+ skips a tab or a line break wherever one stands, so ``/\host`` leads to
15
+ ``//host`` — another site — and where a parser and a browser split an
16
+ authority at different places, they name different hosts. A target carrying a
17
+ backslash or a control character is refused outright.
18
+ """
19
+
20
+ from __future__ import annotations
21
+
22
+ import re
23
+ from typing import TYPE_CHECKING, Final
24
+ from urllib.parse import urlsplit
25
+
26
+ if TYPE_CHECKING:
27
+ from xtr_http_message_contracts import ServerRequestInterface
28
+
29
+ __all__ = ["is_same_origin"]
30
+
31
+ #: What a browser does not read as it is written: a backslash, read as a slash
32
+ #: in an ``http(s)`` address, and the control characters — the tab and the line
33
+ #: breaks among them, which it skips wherever they stand.
34
+ _AMBIGUOUS: Final = re.compile(r"[\\\x00-\x1f\x7f]")
35
+
36
+ #: The schemes a redirect target may name, each with the port it answers on
37
+ #: when the address writes none.
38
+ _DEFAULT_PORTS: Final[dict[str, int]] = {"http": 80, "https": 443}
39
+
40
+
41
+ def is_same_origin(request: ServerRequestInterface, target: str) -> bool:
42
+ """Tell whether ``target`` leads back to the origin ``request`` reached.
43
+
44
+ A path qualifies when it opens with a single ``/``: a second one makes it
45
+ the address of another host, reached over the request's scheme. An
46
+ absolute URL qualifies when it names ``http`` or ``https`` and the
47
+ request's own scheme, host and port — a port it leaves out read as its
48
+ scheme's. A relative reference never qualifies, nor does a target
49
+ carrying a backslash or a control character.
50
+ """
51
+ if _AMBIGUOUS.search(target) is not None:
52
+ return False
53
+ if target.startswith("/"):
54
+ return not target.startswith("//")
55
+ origin = _origin_of(target)
56
+ return origin is not None and origin == _origin_of(str(request.get_uri()))
57
+
58
+
59
+ def _origin_of(url: str) -> tuple[str, str, int] | None:
60
+ """Return the scheme, host and port ``url`` leads to, or ``None`` for no web origin.
61
+
62
+ Both sides of the comparison are read here, through the one parser, so a
63
+ host is compared with a host written the same way — an IP literal without
64
+ its brackets on either side.
65
+ """
66
+ try:
67
+ parts = urlsplit(url)
68
+ port = parts.port
69
+ except ValueError:
70
+ # A port that is no number, or brackets holding no address: an
71
+ # authority no origin can be told from.
72
+ return None
73
+ default_port = _DEFAULT_PORTS.get(parts.scheme)
74
+ if default_port is None or parts.hostname is None:
75
+ return None
76
+ return parts.scheme, parts.hostname, default_port if port is None else port