Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add trailing dot strip (#2161)

Leendert de Borst2351d11475b6
diff --git a/core/rust/src/credential_matcher/domain.rs b/core/rust/src/credential_matcher/domain.rs
index df59ed1be..8bfec459f 100644
--- a/core/rust/src/credential_matcher/domain.rs
+++ b/core/rust/src/credential_matcher/domain.rs
@@ -133,10 +133,11 @@ pub fn extract_domain(url: &str) -> String {
extract_domain_with_port(url).domain
}
-/// Check if a host string is an IP address literal (IPv4 or IPv6, optionally bracketed).
+/// Check if a host string is an IP address literal (IPv4 with an optional trailing dot, or IPv6, optionally bracketed).
/// IP addresses have no domain hierarchy, so they must never be reduced to a "root domain".
fn is_ip_literal(host: &str) -> bool {
let bare = host.strip_prefix('[').and_then(|h| h.strip_suffix(']')).unwrap_or(host);
+ let bare = bare.strip_suffix('.').unwrap_or(bare);
bare.parse::<std::net::IpAddr>().is_ok()
}
diff --git a/core/rust/src/credential_matcher/public_suffix/mod.rs b/core/rust/src/credential_matcher/public_suffix/mod.rs
index d06adf7aa..d6ab45323 100644
--- a/core/rust/src/credential_matcher/public_suffix/mod.rs
+++ b/core/rust/src/credential_matcher/public_suffix/mod.rs
@@ -67,7 +67,8 @@ fn public_suffix_label_count(host: &str, starts: &[usize]) -> usize {
/// The registrable domain of `host`: its public suffix plus one label, kept as-is from the input.
pub fn registrable_domain(host: &str) -> Option<&str> {
- if host.is_empty() {
+ let host = host.strip_suffix('.').unwrap_or(host);
+ if host.split('.').any(str::is_empty) {
return None;
}
@@ -161,6 +162,23 @@ mod tests {
assert_eq!(registrable_domain("app.localhost"), Some("app.localhost"));
}
+ #[test]
+ fn trailing_dot_and_empty_labels() {
+ // A fully qualified host has the same registrable domain as without its trailing dot, never the bare TLD.
+ assert_eq!(registrable_domain("bank.com."), Some("bank.com"));
+ assert_eq!(registrable_domain("login.bank.com."), Some("bank.com"));
+ assert_eq!(registrable_domain("victim.vercel.app."), Some("victim.vercel.app"));
+ assert_eq!(registrable_domain("com."), None);
+ assert_eq!(registrable_domain("vercel.app."), None);
+
+ // Empty labels make a host malformed: no registrable domain at all.
+ assert_eq!(registrable_domain(".com"), None);
+ assert_eq!(registrable_domain("a..b.com"), None);
+ assert_eq!(registrable_domain("bank.com.."), None);
+ assert_eq!(registrable_domain(".."), None);
+ assert_eq!(registrable_domain("."), None);
+ }
+
#[test]
fn lookup_is_case_insensitive_and_keeps_input_casing() {
assert_eq!(registrable_domain("Login.Example.CO.UK"), Some("Example.CO.UK"));