Skip to content

Commit 4164838

Browse files
committed
fix(matcher): improve subdomain matching case insensitivity
1 parent 1b3fa96 commit 4164838

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

src/client/proxy/matcher.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,10 @@ impl DomainMatcher {
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
@@ -878,6 +881,10 @@ mod tests {
878881
assert!(matcher.contains("foo.bar"));
879882
assert!(matcher.contains("FOO.BAR"));
880883
assert!(matcher.contains("Foo.Bar"));
884+
885+
assert!(matcher.contains("www.foo.bar"));
886+
assert!(matcher.contains("WWW.FOO.BAR"));
887+
assert!(matcher.contains("Www.Foo.Bar"));
881888
}
882889

883890
#[test]
@@ -897,5 +904,16 @@ mod tests {
897904
assert!(p
898905
.intercept(&"http://Example.com".parse().unwrap())
899906
.is_none());
907+
908+
// subdomain should bypass proxy (case insensitive match)
909+
assert!(p
910+
.intercept(&"http://www.example.com".parse().unwrap())
911+
.is_none());
912+
assert!(p
913+
.intercept(&"http://WWW.EXAMPLE.COM".parse().unwrap())
914+
.is_none());
915+
assert!(p
916+
.intercept(&"http://Www.Example.Com".parse().unwrap())
917+
.is_none());
900918
}
901919
}

0 commit comments

Comments
 (0)