Skip to content

Commit 5e5ffa9

Browse files
committed
fix auth token crashes
Signed-off-by: Denys Fedoryshchenko <denys.f@collabora.com>
1 parent 256aee4 commit 5e5ffa9

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/main.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,12 +1136,18 @@ fn parse_range(range: &str) -> (u64, u64) {
11361136
/// Verify the Authorization header
11371137
/// Return error message + owner if the token is correct
11381138
fn verify_auth_hdr(headers: &HeaderMap) -> Result<String, Option<String>> {
1139-
let auth = headers.get("Authorization");
1140-
if auth == None {
1139+
let auth = match headers.get("Authorization") {
1140+
Some(auth) => auth,
1141+
None => return Err(None),
1142+
};
1143+
let auth_str = match auth.to_str() {
1144+
Ok(s) => s,
1145+
Err(_) => return Err(None),
1146+
};
1147+
let token_parts: Vec<&str> = auth_str.split_whitespace().collect();
1148+
if token_parts.is_empty() {
11411149
return Err(None);
11421150
}
1143-
let token = auth.unwrap().to_str().unwrap().split_whitespace();
1144-
let token_parts: Vec<&str> = token.collect();
11451151
if token_parts.len() != 2 {
11461152
let verif_result = storjwt::verify_jwt_token(token_parts[0]);
11471153
let bmap = match verif_result {

0 commit comments

Comments
 (0)