Use only one regex for domain matching.

This commit is contained in:
Kavin 2022-11-03 21:53:36 +00:00
parent 8755b0a76e
commit 567380d4aa
No known key found for this signature in database
GPG key ID: 49451E4482CC5BCD

View file

@ -28,8 +28,7 @@ async fn main() -> std::io::Result<()> {
}
lazy_static!(
static ref RE: Regex = Regex::new(r"^[a-z\d\.-]*$").unwrap();
static ref RE_DOMAIN: Regex = Regex::new(r"(?:^[a-z\d\.-]*\.)?((?:[a-z\d-]*)\.(?:[a-z\d-]*))$").unwrap();
static ref RE_DOMAIN: Regex = Regex::new(r"^(?:[a-z\d\.-]*\.)?((?:[a-z\d-]*)\.(?:[a-z\d-]*))$").unwrap();
static ref RE_MANIFEST: Regex = Regex::new("(?m)URI=\"([^\"]+)\"").unwrap();
);
@ -104,7 +103,7 @@ async fn index(req: HttpRequest) -> Result<HttpResponse, Box<dyn Error>> {
let host = res.unwrap();
if !RE.is_match(host) || !RE_DOMAIN.is_match(host) {
if !RE_DOMAIN.is_match(host) {
return Err("Invalid host provided".into());
}