Skip to content

Commit 6136536

Browse files
authored
Fix for Host header to domain matching where host is authority with port (#163)
Signed-off-by: Dawid Nowak <nowakd@gmail.com>
1 parent be1443e commit 6136536

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

orion-configuration/src/config/network_filters/http_connection_manager.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use http_filters::{FilterOverride, HttpFilter};
2929
use route::{Action, RouteMatch};
3030
use serde::{Deserialize, Serialize};
3131
use std::{collections::HashMap, str::FromStr, time::Duration};
32+
use tracing::info;
3233

3334
use crate::config::{
3435
common::*,
@@ -219,7 +220,12 @@ impl MatchHost {
219220
pub fn eval_lpm_request<B>(&self, req: &http::Request<B>) -> Option<MatchHostScoreLPM> {
220221
if let Some(header_value) = req.headers().get(http::header::HOST) {
221222
let host = header_value.to_str().ok()?;
222-
self.eval_lpm_host(host)
223+
if let Ok(authority) = http::uri::Authority::from_str(host) {
224+
self.eval_lpm_host(authority.host())
225+
} else {
226+
info!("Host header value is not a valid authority ..{host}");
227+
self.eval_lpm_host(host)
228+
}
223229
} else {
224230
self.eval_lpm_host(req.uri().host()?)
225231
}

orion-lib/src/listeners/http_connection_manager.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,11 +1259,12 @@ mod tests {
12591259
assert_eq!(select_virtual_host(&request, &[vh1.clone(), vh2.clone(), vh3.clone()]), Some(&vh3));
12601260

12611261
let request = Request::builder().header("host", "blah.domain3.com:8000").body(()).unwrap();
1262-
assert_eq!(select_virtual_host(&request, &[vh1.clone(), vh2.clone(), vh3.clone()]), None);
1262+
assert_eq!(select_virtual_host(&request, &[vh1.clone(), vh2.clone(), vh3.clone()]), Some(&vh3));
12631263

12641264
let request = Request::builder().header("host", "domain2.com:8000").body(()).unwrap();
1265-
assert_eq!(select_virtual_host(&request, &[vh1.clone(), vh2.clone(), vh3.clone()]), None);
1265+
assert_eq!(select_virtual_host(&request, &[vh1.clone(), vh2.clone(), vh3.clone()]), Some(&vh2));
12661266

1267+
// in theory this is an invalid domain...
12671268
let domains2 = vec!["domain2.com:8000"].into_iter().flat_map(MatchHost::try_from).collect();
12681269
let vh2 = VirtualHost { domains: domains2, ..Default::default() };
12691270
let request = Request::builder().header("host", "domain2.com").body(()).unwrap();

0 commit comments

Comments
 (0)