@@ -26,11 +26,23 @@ use super::related_origins::{validate_related_origins, RelatedOrigins};
2626
2727pub type JsonError = serde_json:: Error ;
2828
29- /// Dependencies for origin validation: the Public Suffix List (rp.id suffix
30- /// check and related-origins matching) and the related-origins policy.
29+ /// Per-request settings (currently just the origin-validation policy).
3130pub struct RequestSettings < ' a > {
32- pub public_suffix_list : & ' a dyn PublicSuffixList ,
33- pub related_origins : RelatedOrigins < ' a > ,
31+ pub origin : OriginValidation < ' a > ,
32+ }
33+
34+ /// How the caller origin is validated against the request rp.id.
35+ pub enum OriginValidation < ' a > {
36+ /// Trust the caller's origin to rp.id binding with no check, for callers
37+ /// that have already validated it (e.g. a browser). Misuse defeats phishing
38+ /// resistance, so the caller owns that decision.
39+ Trust ,
40+ /// Validate rp.id against the caller origin: a registrable suffix of the
41+ /// effective domain, then related origins on mismatch.
42+ Validate {
43+ public_suffix_list : & ' a dyn PublicSuffixList ,
44+ related_origins : RelatedOrigins < ' a > ,
45+ } ,
3446}
3547
3648/// Builds a request from its parsed IDL model, validating origin against rp.id.
@@ -48,19 +60,26 @@ where
4860 ) -> Result < Self , Self :: Error > ;
4961}
5062
51- /// Whether `request_origin` may act for `rp_id`: a registrable suffix of the
52- /// caller's effective domain, or a matching related origin when enabled.
63+ /// Whether `request_origin` may act for `rp_id`. `Trust` accepts any rp.id;
64+ /// `Validate` requires a registrable suffix of the caller's effective domain or
65+ /// a matching related origin.
5366pub ( crate ) async fn rp_id_authorised (
5467 request_origin : & RequestOrigin ,
5568 rp_id : & RelyingPartyId ,
5669 settings : & RequestSettings < ' _ > ,
5770) -> bool {
71+ let ( public_suffix_list, related_origins) = match & settings. origin {
72+ OriginValidation :: Trust => return true ,
73+ OriginValidation :: Validate {
74+ public_suffix_list,
75+ related_origins,
76+ } => ( * public_suffix_list, related_origins) ,
77+ } ;
5878 let effective_rp_id = request_origin. origin . host . as_str ( ) ;
59- if is_registrable_domain_suffix_or_equal ( & rp_id. 0 , effective_rp_id, settings. public_suffix_list )
60- {
79+ if is_registrable_domain_suffix_or_equal ( & rp_id. 0 , effective_rp_id, public_suffix_list) {
6180 return true ;
6281 }
63- match & settings . related_origins {
82+ match related_origins {
6483 RelatedOrigins :: Disabled => false ,
6584 RelatedOrigins :: Enabled { source, max_labels } => {
6685 match source. allowed_origins ( rp_id) . await {
@@ -71,7 +90,7 @@ pub(crate) async fn rp_id_authorised(
7190 Ok ( origins) => match validate_related_origins (
7291 & request_origin. origin ,
7392 & origins,
74- settings . public_suffix_list ,
93+ public_suffix_list,
7594 * max_labels,
7695 ) {
7796 Ok ( ( ) ) => true ,
0 commit comments