@@ -71,27 +71,34 @@ pub async fn authenticator(
7171 return HttpResponse :: Unauthorized ( ) . finish ( )
7272 } ,
7373 } ;
74- let encoded = match auth_header. to_str ( ) {
74+ let auth_header = match auth_header. to_str ( ) {
7575 Ok ( header) => header,
7676 Err ( err) => {
7777 log:: warn!( "{}" , err) ;
7878 return HttpResponse :: Unauthorized ( ) . finish ( )
7979 } ,
8080 } ;
81+ let encoded = match auth_header. strip_prefix ( "Basic " ) {
82+ Some ( value) => value,
83+ None => {
84+ log:: warn!( "Authorization header missing Basic prefix" ) ;
85+ return HttpResponse :: Unauthorized ( ) . finish ( )
86+ } ,
87+ } ;
8188 let decoded = match base64_decode ( encoded) {
8289 Ok ( decoded_) => decoded_,
8390 Err ( err) => {
8491 log:: warn!( "{}" , err) ;
8592 return HttpResponse :: Unauthorized ( ) . finish ( )
8693 } ,
8794 } ;
88- let auth_header = decoded. split ( "," ) . collect :: < Vec < & str > > ( ) ;
89- if auth_header . len ( ) != 2 {
95+ let auth_parts = decoded. splitn ( 2 , ':' ) . collect :: < Vec < & str > > ( ) ;
96+ if auth_parts . len ( ) != 2 {
9097 log:: warn!( "Expected two Authorization headers, received {:?}" , auth_header) ;
9198 return HttpResponse :: Unauthorized ( ) . finish ( ) ;
9299 }
93- let username = auth_header . first ( ) . unwrap ( ) . to_string ( ) ;
94- let password = auth_header . last ( ) . unwrap ( ) . to_string ( ) ;
100+ let username = auth_parts [ 0 ] . to_string ( ) ;
101+ let password = auth_parts [ 1 ] . to_string ( ) ;
95102 if username == config. username && password == config. password {
96103 return HttpResponse :: Ok ( ) . json ( json ! ( { "apikey" : config. apikey } ) )
97104 }
0 commit comments