Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Only do text fallback search on credentials without a domain name (#1120)
Leendert de Borstb2c07f6de62f
diff --git a/apps/browser-extension/src/entrypoints/contentScript/Filter.ts b/apps/browser-extension/src/entrypoints/contentScript/Filter.tsindex 1c203bb62..65c80e8ee 100644--- a/apps/browser-extension/src/entrypoints/contentScript/Filter.ts+++ b/apps/browser-extension/src/entrypoints/contentScript/Filter.ts@@ -66,13 +66,16 @@ function domainsMatch(domain1: string, domain2: string): boolean {}/**- * Filter credentials based on current URL and page context to determine which credentials to show- * in the autofill popup. Credentials are sorted by priority:+ * Filter credentials based on current URL and page context with anti-phishing protection.+ *+ * **Security Note**: When searching with a URL, text search fallback only applies to+ * credentials with no service URL defined. This prevents phishing attacks where a+ * malicious site might match credentials intended for the legitimate site.+ *+ * Credentials are sorted by priority:* 1. Exact domain match (highest priority)* 2. Partial domain match (root domain match)- * 3. Base URL match AND page title word match- * 4. Base URL match only- * 5. Page title word match only (lowest priority)+ * 3. Page title word match (only for credentials without service URLs)*/export function filterCredentials(credentials: Credential[], currentUrl: string, pageTitle: string): Credential[] {const filtered: CredentialWithPriority[] = [];@@ -101,7 +104,10 @@ export function filterCredentials(credentials: Credential[], currentUrl: string,.slice(0, 3);}- // Prepare page title words for matching+ /*+ * SECURITY: Fallback to page title matching, but ONLY for credentials with no service URL+ * This prevents phishing attacks by ensuring URL-based credentials only match their domains+ */const titleWords = pageTitle.length > 0? pageTitle.toLowerCase().split(/\s+/)@@ -113,6 +119,11 @@ export function filterCredentials(credentials: Credential[], currentUrl: string,// Check for page title matches as fallbackcredentials.forEach(cred => {+ // CRITICAL: Only check credentials that have NO service URL defined+ if (cred.ServiceUrl && cred.ServiceUrl.length > 0) {+ return;+ }+// Skip if already in filtered listif (filtered.some(f => f.Id === cred.Id)) {return;diff --git a/apps/browser-extension/src/entrypoints/contentScript/__tests__/Filter.test.ts b/apps/browser-extension/src/entrypoints/contentScript/__tests__/Filter.test.tsindex 910bb6148..57d451e63 100644--- a/apps/browser-extension/src/entrypoints/contentScript/__tests__/Filter.test.ts+++ b/apps/browser-extension/src/entrypoints/contentScript/__tests__/Filter.test.ts@@ -235,6 +235,56 @@ describe('Filter - Credential URL Matching', () => {expect(matches[0].ServiceName).toBe('Title Only newyorktimes');});+ /* [#14] - Domain name part matching */+ it('should handle domain name part matching', () => {+ const matches = filterCredentials(+ testCredentials,+ 'https://coolblue.be',+ ''+ );++ // Browser extension should find no matches since domains don't match+ expect(matches).toHaveLength(0);+ });++ // [#15] - Package name matching+ it('should handle package name matching', () => {+ const matches = filterCredentials(+ testCredentials,+ 'com.coolblue.app',+ ''+ );++ // Browser extension should find exact URL match for "Coolblue App"+ expect(matches).toHaveLength(1);+ expect(matches[0].ServiceName).toBe('Coolblue App');+ });++ // [#16] - Invalid URL handling+ it('should handle invalid URL', () => {+ const matches = filterCredentials(+ testCredentials,+ 'not a url',+ ''+ );++ // Browser extension should find no matches for invalid URL+ expect(matches).toHaveLength(0);+ });++ // [#17] - Anti-phishing protection+ it('should prevent phishing attacks', () => {+ // Test that credentials with URLs don't match on text when URL is provided+ const matches = filterCredentials(+ testCredentials,+ 'https://secure-bankk.com', // Phishing domain (extra 'k')+ 'Bank Account'+ );++ // Should find no matches - Bank Account has URL so won't match on text+ expect(matches).toHaveLength(0);+ });+/*** Creates the shared test credential dataset used across all platforms.* Note: when making changes to this list, make sure to update the corresponding list for iOS and Android tests as well.@@ -251,6 +301,7 @@ describe('Filter - Credential URL Matching', () => {createTestCredential('Stack Overflow', 'https://stackoverflow.com', '[email protected]'),createTestCredential('Subdomain Example', 'https://app.example.com', '[email protected]'),createTestCredential('Title Only newyorktimes', '', ''),+ createTestCredential('Bank Account', 'https://secure-bank.com', '[email protected]'),];}diff --git a/apps/mobile-app/ios/VaultUI/Utils/CredentialFilter.swift b/apps/mobile-app/ios/VaultUI/Utils/CredentialFilter.swiftindex c4bf6aaab..d5be5e974 100644--- a/apps/mobile-app/ios/VaultUI/Utils/CredentialFilter.swift+++ b/apps/mobile-app/ios/VaultUI/Utils/CredentialFilter.swift@@ -58,11 +58,15 @@ public class CredentialFilter {return d1Root == d2Root}- /// Filter credentials based on search text. This matches the iOS filterCredentials logic exactly.+ /// Filter credentials based on search text with anti-phishing protection./// - Parameters:/// - credentials: List of credentials to filter/// - searchText: Search term (app info, URL, etc.)/// - Returns: Filtered list of credentials+ ///+ /// **Security Note**: When searching with a URL, text search fallback only applies to+ /// credentials with no service URL defined. This prevents phishing attacks where a+ /// malicious site might match credentials intended for the legitimate site.public static func filterCredentials(_ credentials: [Credential], searchText: String) -> [Credential] {if searchText.isEmpty {return credentials@@ -83,12 +87,16 @@ public class CredentialFilter {}}- // If no domain matches found, try text search in service name+ // SECURITY: If no domain matches found, only search text in credentials with NO service URL+ // This prevents phishing attacks by ensuring URL-based credentials only match their domainsif matches.isEmpty {let domainParts = searchDomain.components(separatedBy: ".")let domainWithoutExtension = domainParts.first?.lowercased() ?? searchDomain.lowercased()let nameMatches = credentials.filter { credential in+ // CRITICAL: Only search in credentials that have no service URL defined+ guard credential.service.url?.isEmpty != false else { return false }+let serviceNameMatch = credential.service.name?.lowercased().contains(domainWithoutExtension) ?? falselet notesMatch = credential.notes?.lowercased().contains(domainWithoutExtension) ?? falsereturn serviceNameMatch || notesMatchdiff --git a/apps/mobile-app/ios/VaultUITests/CredentialFilterTests.swift b/apps/mobile-app/ios/VaultUITests/CredentialFilterTests.swiftindex 1b5c224a9..288e5e909 100644--- a/apps/mobile-app/ios/VaultUITests/CredentialFilterTests.swift+++ b/apps/mobile-app/ios/VaultUITests/CredentialFilterTests.swift@@ -141,6 +141,45 @@ final class CredentialFilterTests: XCTestCase {XCTAssertEqual(matches.count, 1)XCTAssertEqual(matches.first?.service.name, "Title Only newyorktimes")}++ // [#12] - Priority ordering+ func testPriorityOrdering() {+ let matches = CredentialFilter.filterCredentials(testCredentials, searchText: "coolblue.nl")++ XCTAssertEqual(matches.count, 1)+ XCTAssertEqual(matches.first?.service.name, "Coolblue")+ }++ // [#14] - Domain name part matching+ func testDomainNamePartMatch() {+ let matches = CredentialFilter.filterCredentials(testCredentials, searchText: "https://coolblue.be")++ XCTAssertEqual(matches.count, 0)+ }++ // [#15] - Package name matching+ func testPackageNameMatch() {+ let matches = CredentialFilter.filterCredentials(testCredentials, searchText: "com.coolblue.app")++ XCTAssertEqual(matches.count, 1)+ XCTAssertEqual(matches.first?.service.name, "Coolblue App")+ }++ // [#16] - Invalid URL handling+ func testInvalidUrl() {+ let matches = CredentialFilter.filterCredentials(testCredentials, searchText: "not a url")++ XCTAssertTrue(matches.isEmpty)+ }++ // [#17] - Anti-phishing protection+ func testAntiPhishingProtection() {+ // Test that credentials with URLs don't match on text when a non-matching base URL is provided+ let matches = CredentialFilter.filterCredentials(testCredentials, searchText: "https://secure-bankk.com") // Phishing domain (extra 'k')++ // Should find no matches - Bank Account has URL so won't match on text+ XCTAssertTrue(matches.isEmpty)+ }// MARK: - Shared Test Data@@ -160,6 +199,7 @@ final class CredentialFilterTests: XCTestCase {createTestCredential(serviceName: "Stack Overflow", serviceUrl: "https://stackoverflow.com", username: "[email protected]"),createTestCredential(serviceName: "Subdomain Example", serviceUrl: "https://app.example.com", username: "[email protected]"),createTestCredential(serviceName: "Title Only newyorktimes", serviceUrl: "", username: ""),+ createTestCredential(serviceName: "Bank Account", serviceUrl: "https://secure-bank.com", username: "[email protected]"),]}