File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -198,6 +198,10 @@ async fn check_origin(
198198 ) ;
199199 return Err ( WebAuthnError :: SecurityError ) ;
200200 } ;
201+ if !origin. starts_with ( "https://" ) {
202+ tracing:: warn!( "Caller requested non-HTTPS schemed origin, which is not supported." ) ;
203+ return Err ( WebAuthnError :: SecurityError ) ;
204+ }
201205 let is_same_origin = is_same_origin. unwrap_or ( false ) ;
202206 let top_origin = if is_same_origin {
203207 origin. clone ( )
@@ -264,3 +268,25 @@ impl From<WebAuthnError> for Error {
264268 }
265269 }
266270}
271+
272+ #[ cfg( test) ]
273+ mod test {
274+ use std:: future:: Future ;
275+
276+ use credentialsd_common:: model:: WebAuthnError ;
277+
278+ use crate :: dbus:: gateway:: check_origin;
279+
280+ #[ tokio:: test]
281+ async fn test_only_https_origins ( ) {
282+ let check = |origin : & ' static str | async { check_origin ( Some ( origin) , Some ( true ) ) . await } ;
283+ assert ! ( matches!(
284+ check( "https://example.com" ) . await ,
285+ Ok ( ( o, ..) ) if o == "https://example.com"
286+ ) ) ;
287+ assert ! ( matches!(
288+ check( "http://example.com" ) . await ,
289+ Err ( WebAuthnError :: SecurityError )
290+ ) ) ;
291+ }
292+ }
Original file line number Diff line number Diff line change @@ -312,6 +312,8 @@ pub(super) fn get_credential_request_try_into_ctap2(
312312 }
313313 } ;
314314 let relying_party_id = options. rp_id . unwrap_or_else ( || {
315+ // TODO: We're assuming that the origin is `<scheme>://data`, which is
316+ // currently checked by the caller, but we should encode this in a type.
315317 let ( _, effective_domain) = origin. rsplit_once ( '/' ) . unwrap ( ) ;
316318 effective_domain. to_string ( )
317319 } ) ;
You can’t perform that action at this time.
0 commit comments