Skip to content

Commit f98e096

Browse files
committed
fix(oauth): gracefully skip non-ASCII session/loid headers instead of panicking
1 parent e51a396 commit f98e096

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

src/oauth.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -252,14 +252,16 @@ impl OauthBackend for MobileSpoofAuth {
252252
// Not worried about the privacy implications, since this is randomly changed
253253
// and really only as privacy-concerning as the OAuth token itself.
254254
if let Some(header) = resp.headers().get("x-reddit-loid") {
255-
let header_val: &wreq::header::HeaderValue = header;
256-
self.additional_headers.insert("x-reddit-loid".to_owned(), header_val.to_str().unwrap().to_string());
255+
if let Ok(val) = header.to_str() {
256+
self.additional_headers.insert("x-reddit-loid".to_owned(), val.to_string());
257+
}
257258
}
258259

259260
// Same with x-reddit-session
260261
if let Some(header) = resp.headers().get("x-reddit-session") {
261-
let header_val: &wreq::header::HeaderValue = header;
262-
self.additional_headers.insert("x-reddit-session".to_owned(), header_val.to_str().unwrap().to_string());
262+
if let Ok(val) = header.to_str() {
263+
self.additional_headers.insert("x-reddit-session".to_owned(), val.to_string());
264+
}
263265
}
264266

265267
trace!("Serializing response...");
@@ -365,14 +367,16 @@ impl OauthBackend for GenericWebAuth {
365367
// Not worried about the privacy implications, since this is randomly changed
366368
// and really only as privacy-concerning as the OAuth token itself.
367369
if let Some(header) = resp.headers().get("x-reddit-loid") {
368-
let header_val: &wreq::header::HeaderValue = header;
369-
self.additional_headers.insert("x-reddit-loid".to_owned(), header_val.to_str().unwrap().to_string());
370+
if let Ok(val) = header.to_str() {
371+
self.additional_headers.insert("x-reddit-loid".to_owned(), val.to_string());
372+
}
370373
}
371374

372375
// Same with x-reddit-session
373376
if let Some(header) = resp.headers().get("x-reddit-session") {
374-
let header_val: &wreq::header::HeaderValue = header;
375-
self.additional_headers.insert("x-reddit-session".to_owned(), header_val.to_str().unwrap().to_string());
377+
if let Ok(val) = header.to_str() {
378+
self.additional_headers.insert("x-reddit-session".to_owned(), val.to_string());
379+
}
376380
}
377381

378382
trace!("Serializing GenericWebAuth response...");

0 commit comments

Comments
 (0)