Skip to content

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

Add trim to credential_matcher values (#2159)

Leendert de Borst29db377b4252
diff --git a/core/rust/src/credential_matcher/domain.rs b/core/rust/src/credential_matcher/domain.rs
index b89661946..9ea5868ad 100644
--- a/core/rust/src/credential_matcher/domain.rs
+++ b/core/rust/src/credential_matcher/domain.rs
@@ -151,7 +151,7 @@ impl DomainWithPort {
/// Extract domain and port from URL, handling both full URLs and partial domains.
/// Returns DomainWithPort with empty domain if not a valid URL/domain.
pub fn extract_domain_with_port(url: &str) -> DomainWithPort {
- let lowered = url.to_lowercase();
+ let lowered = url.trim().to_lowercase();
let (scheme, authority, _) = split_url(&lowered);
// A web scheme is what allows single-word hostnames like "http://plex" or "https://nas",
diff --git a/core/rust/src/credential_matcher/mod.rs b/core/rust/src/credential_matcher/mod.rs
index aea127a4d..10d3c2520 100644
--- a/core/rust/src/credential_matcher/mod.rs
+++ b/core/rust/src/credential_matcher/mod.rs
@@ -152,7 +152,7 @@ pub fn filter_credentials(input: CredentialMatcherInput) -> CredentialMatcherOut
fn match_package_name(credentials: &[Credential], package_name: &str, max_results: usize) -> Vec<String> {
credentials
.iter()
- .filter(|cred| cred.item_urls.iter().any(|url| url == package_name))
+ .filter(|cred| cred.item_urls.iter().any(|url| url.trim() == package_name))
.map(|cred| cred.id.clone())
.take(max_results)
.collect()
@@ -217,7 +217,7 @@ fn match_item_names(credentials: &[Credential], words: &[String], require_no_url
credentials
.iter()
- .filter(|cred| !require_no_urls || !cred.item_urls.iter().any(|url| !url.is_empty()))
+ .filter(|cred| !require_no_urls || !cred.item_urls.iter().any(|url| !url.trim().is_empty()))
.filter(|cred| {
cred.item_name.as_deref().is_some_and(|name| {
let name_words = extract_words(name);
diff --git a/core/rust/src/credential_matcher/tests.rs b/core/rust/src/credential_matcher/tests.rs
index 2c8a39735..d5579903f 100644
--- a/core/rust/src/credential_matcher/tests.rs
+++ b/core/rust/src/credential_matcher/tests.rs
@@ -1025,3 +1025,15 @@ fn test_single_word_hostname_extraction_requires_protocol() {
let with_match = filter(credentials_with_protocol.clone(), "http://plex:32400", "");
assert_eq!(with_match.len(), 1, "Credential with protocol should match");
}
+
+/// [#2299] - Whitespace around a stored URL or package name must not prevent a match
+#[test]
+fn test_stored_urls_are_trimmed() {
+ let credentials = vec![
+ create_test_credential_multi_url("Amazon", vec!["https://amazon.fr/", " https://amazon.de", "amazon.it\t", " com.amazon.app \n"], "[email protected]"),
+ ];
+
+ assert_eq!(filter(credentials.clone(), "https://www.amazon.de/ap/signin", "").len(), 1, "Leading space should be ignored");
+ assert_eq!(filter(credentials.clone(), "https://amazon.it", "").len(), 1, "Trailing whitespace should be ignored");
+ assert_eq!(filter(credentials, "com.amazon.app", "").len(), 1, "Package name should match when padded");
+}