Include path in hash

This commit is contained in:
Kavin 2023-11-20 08:32:37 +00:00
parent 01697ebb86
commit d72fb3c445
No known key found for this signature in database
GPG key ID: 6E4598CA5C92C41F

View file

@ -155,6 +155,8 @@ async fn index(req: HttpRequest) -> Result<HttpResponse, Box<dyn Error>> {
return Err("Invalid qhash provided".into()); return Err("Invalid qhash provided".into());
} }
let path = req.path().as_bytes().to_owned();
// Store sorted key-value pairs // Store sorted key-value pairs
let mut set = BTreeSet::new(); let mut set = BTreeSet::new();
{ {
@ -175,12 +177,16 @@ async fn index(req: HttpRequest) -> Result<HttpResponse, Box<dyn Error>> {
hasher.update(&value); hasher.update(&value);
} }
hasher.update(&path);
hasher.update(secret.as_bytes()); hasher.update(secret.as_bytes());
let hash = hasher.finalize().to_hex(); let hash = hasher.finalize().to_hex();
hash[..8].to_owned() hash[..8].to_owned()
}).await.unwrap(); })
.await
.unwrap();
if hash != qhash { if hash != qhash {
return Err("Invalid qhash provided".into()); return Err("Invalid qhash provided".into());
@ -306,7 +312,9 @@ async fn index(req: HttpRequest) -> Result<HttpResponse, Box<dyn Error>> {
} else { } else {
(resp_bytes.into(), "image/jpeg") (resp_bytes.into(), "image/jpeg")
} }
}).await.unwrap(); })
.await
.unwrap();
response.content_type(content_type); response.content_type(content_type);
return Ok(response.body(body)); return Ok(response.body(body));
} }
@ -346,8 +354,9 @@ async fn index(req: HttpRequest) -> Result<HttpResponse, Box<dyn Error>> {
} else { } else {
(resp_bytes.into(), "image/jpeg") (resp_bytes.into(), "image/jpeg")
} }
})
}).await.unwrap(); .await
.unwrap();
response.content_type(content_type); response.content_type(content_type);
return Ok(response.body(body)); return Ok(response.body(body));
} }