Skip to content

Commit

Permalink
bug: check empty VAPID sub first (#835)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrconlin authored Jan 29, 2025
1 parent 2aaf9f2 commit c13717b
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions autoendpoint/src/headers/vapid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,14 @@ impl VapidHeader {
})?;

let Some(sub) = data.sub else { return Ok(None) };
if !sub.starts_with("mailto:") && !sub.starts_with("https://") {
info!("πŸ” Vapid: Bad Format {sub:?}");
return Err(VapidError::SubBadFormat);
};
if sub.is_empty() {
info!("πŸ” Empty Vapid sub");
return Err(VapidError::SubEmpty);
}
if !sub.starts_with("mailto:") && !sub.starts_with("https://") {
info!("πŸ” Vapid: Bad Format {sub:?}");
return Err(VapidError::SubBadFormat);
};
info!("πŸ” Vapid: sub: {sub}");
Ok(Some(sub))
}
Expand Down Expand Up @@ -269,6 +269,14 @@ mod tests {
)
}

#[test]
fn parse_no_sub() {
const VAPID_HEADER_NO_SUB:&str = "vapid t=eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NiJ9.eyJhdWQiOiJodHRwczovL3B1c2guc2VydmljZXMubW96aWxsYS5jb20iLCJleHAiOjE3MzgxMTE1OTN9.v3oneNnU-VWJK3rI0gNAvstaZHfbA57WdrYHEq0P2Od9nGsdpi1xN2aNS8412wJpdzsriYvLyEWdPEdsu3luAw,k=BLMymkOqvT6OZ1o9etCqV4jGPkvOXNz5FdBjsAR9zR5oeCV1x5CBKuSLTlHon-H_boHTzMtMoNHsAGDlDB6X7vI";

let returned_header = VapidHeader::parse(VAPID_HEADER_NO_SUB);
assert_eq!(returned_header.unwrap().insecure_sub(), Ok(None))
}

#[test]
fn extract_sub() {
let header = VapidHeader::parse(VALID_HEADER).unwrap();
Expand Down

0 comments on commit c13717b

Please sign in to comment.