Skip to content

Commit 8c4f4a0

Browse files
authored
fix(matcher): improve subdomain matching case insensitivity (#252)
1 parent 1b3fa96 commit 8c4f4a0

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/client/proxy/matcher.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,12 +515,15 @@ impl DomainMatcher {
515515
fn contains(&self, domain: &str) -> bool {
516516
let domain_len = domain.len();
517517
for d in &self.0 {
518-
if d == domain
518+
if d.eq_ignore_ascii_case(domain)
519519
|| d.strip_prefix('.')
520520
.map_or(false, |s| s.eq_ignore_ascii_case(domain))
521521
{
522522
return true;
523-
} else if domain.ends_with(d) {
523+
} else if domain
524+
.get(domain_len.saturating_sub(d.len())..)
525+
.map_or(false, |s| s.eq_ignore_ascii_case(d))
526+
{
524527
if d.starts_with('.') {
525528
// If the first character of d is a dot, that means the first character of domain
526529
// must also be a dot, so we are looking at a subdomain of d and that matches
@@ -701,13 +704,19 @@ mod tests {
701704

702705
// domains match with leading `.`
703706
assert!(matcher.contains("foo.bar"));
707+
assert!(matcher.contains("FOO.BAR"));
708+
704709
// subdomains match with leading `.`
705710
assert!(matcher.contains("www.foo.bar"));
711+
assert!(matcher.contains("WWW.FOO.BAR"));
706712

707713
// domains match with no leading `.`
708714
assert!(matcher.contains("bar.foo"));
715+
assert!(matcher.contains("Bar.foo"));
716+
709717
// subdomains match with no leading `.`
710718
assert!(matcher.contains("www.bar.foo"));
719+
assert!(matcher.contains("WWW.BAR.FOO"));
711720

712721
// non-subdomain string prefixes don't match
713722
assert!(!matcher.contains("notfoo.bar"));
@@ -878,6 +887,10 @@ mod tests {
878887
assert!(matcher.contains("foo.bar"));
879888
assert!(matcher.contains("FOO.BAR"));
880889
assert!(matcher.contains("Foo.Bar"));
890+
891+
assert!(matcher.contains("www.foo.bar"));
892+
assert!(matcher.contains("WWW.FOO.BAR"));
893+
assert!(matcher.contains("Www.Foo.Bar"));
881894
}
882895

883896
#[test]
@@ -897,5 +910,16 @@ mod tests {
897910
assert!(p
898911
.intercept(&"http://Example.com".parse().unwrap())
899912
.is_none());
913+
914+
// subdomain should bypass proxy (case insensitive match)
915+
assert!(p
916+
.intercept(&"http://www.example.com".parse().unwrap())
917+
.is_none());
918+
assert!(p
919+
.intercept(&"http://WWW.EXAMPLE.COM".parse().unwrap())
920+
.is_none());
921+
assert!(p
922+
.intercept(&"http://Www.Example.Com".parse().unwrap())
923+
.is_none());
900924
}
901925
}

0 commit comments

Comments
 (0)