@@ -51,6 +51,7 @@ pub(crate) fn effective(global: NipFiMode, required: bool) -> NipFiMode {
5151 global. with_requirement ( required)
5252}
5353
54+ #[ allow( clippy:: result_large_err) ] // Axum responses are the ingress error contract.
5455pub ( crate ) async fn resolve (
5556 state : & crate :: state:: AppState ,
5657 headers : & HeaderMap ,
@@ -96,32 +97,52 @@ pub(crate) async fn resolve(
9697 } )
9798}
9899
99- /// An unmapped request may retain legacy pre-auth error ordering, but must
100- /// never obtain a shared admission proof if a handler omits its host check.
101- pub ( crate ) fn unmapped_request ( ) -> bool {
102- REQUEST_POLICY . try_with ( |p| !p. mapped ) . unwrap_or ( false )
103- }
104-
105- /// Admission callers share the router's decision. Direct callers fail closed
106- /// when policy is unavailable, even if the global rollout mode is Off/Shadow.
100+ /// Preserve route-specific rejection ordering for an authoritative host miss.
101+ /// This is not admission: the full gate below still requires a mapped policy.
107102pub ( crate ) async fn mode ( state : & crate :: state:: AppState , headers : & HeaderMap ) -> NipFiMode {
108103 if state. config . nip_fi . mode . denies_unconditionally ( ) {
109104 return NipFiMode :: unavailable ( ) ;
110105 }
111106 match resolve ( state, headers) . await {
112- Ok ( p)
113- if p. stored_required
114- && ( state. nip_fi_verifier . is_none ( )
115- || state. nip_fi_deny_map . is_none ( )
116- || state. config . nip_fi . max_connection_lifetime ( ) . is_none ( ) ) =>
117- {
118- NipFiMode :: unavailable ( )
119- }
120- Ok ( p) => p. mode ,
107+ Ok ( policy) => configured_mode ( state, policy) ,
108+ Err ( response) if response. status ( ) == StatusCode :: NOT_FOUND => state. config . nip_fi . mode ,
121109 Err ( _) => NipFiMode :: unavailable ( ) ,
122110 }
123111}
124112
113+ /// A shared admission proof is impossible without a serving host policy,
114+ /// even when a route preserves legacy unauthenticated error precedence.
115+ #[ allow( clippy:: result_large_err) ] // Axum responses are the ingress error contract.
116+ pub ( crate ) async fn admission_mode (
117+ state : & crate :: state:: AppState ,
118+ headers : & HeaderMap ,
119+ ) -> Result < NipFiMode , Response < Body > > {
120+ if state. config . nip_fi . mode . denies_unconditionally ( ) {
121+ return Ok ( NipFiMode :: unavailable ( ) ) ;
122+ }
123+ let policy = resolve ( state, headers)
124+ . await
125+ . map_err ( |_| crate :: nip_fi_core:: http_denial ( DenialClass :: AuthorizationUnavailable ) ) ?;
126+ if !policy. mapped {
127+ return Err ( crate :: nip_fi_core:: http_denial (
128+ DenialClass :: AuthorizationUnavailable ,
129+ ) ) ;
130+ }
131+ Ok ( configured_mode ( state, policy) )
132+ }
133+
134+ fn configured_mode ( state : & crate :: state:: AppState , policy : Policy ) -> NipFiMode {
135+ if policy. stored_required
136+ && ( state. nip_fi_verifier . is_none ( )
137+ || state. nip_fi_deny_map . is_none ( )
138+ || state. config . nip_fi . max_connection_lifetime ( ) . is_none ( ) )
139+ {
140+ NipFiMode :: unavailable ( )
141+ } else {
142+ policy. mode
143+ }
144+ }
145+
125146fn not_found ( ) -> Response < Body > {
126147 (
127148 StatusCode :: NOT_FOUND ,
0 commit comments