-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move wildcard support to Additional URLs only
- Loading branch information
varjolintu
committed
Jan 21, 2025
1 parent
9114eb2
commit a20fa8e
Showing
6 changed files
with
131 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (C) 2024 KeePassXC Team <[email protected]> | ||
* Copyright (C) 2025 KeePassXC Team <[email protected]> | ||
* Copyright (C) 2017 Sami Vänttinen <[email protected]> | ||
* Copyright (C) 2013 Francois Ferrand | ||
* | ||
|
@@ -51,6 +51,7 @@ | |
#include <QLocalSocket> | ||
#include <QLocale> | ||
#include <QProgressDialog> | ||
#include <QStringView> | ||
#include <QUrl> | ||
|
||
const QString BrowserService::KEEPASSXCBROWSER_NAME = QStringLiteral("KeePassXC-Browser Settings"); | ||
|
@@ -1375,9 +1376,15 @@ bool BrowserService::shouldIncludeEntry(Entry* entry, | |
return url.endsWith("by-path/" + entry->path()); | ||
} | ||
|
||
const auto allEntryUrls = entry->getAllUrls(); | ||
for (const auto& entryUrl : allEntryUrls) { | ||
if (handleURL(entryUrl, url, submitUrl, omitWwwSubdomain)) { | ||
// Handle the entry URL | ||
if (handleURL(entry->resolveUrl(), url, submitUrl, omitWwwSubdomain)) { | ||
return true; | ||
} | ||
|
||
// Handle additional URLs | ||
const auto additionalUrls = entry->getAdditionalUrls(); | ||
for (const auto& additionalUrl : additionalUrls) { | ||
if (handleURL(additionalUrl, url, submitUrl, omitWwwSubdomain, true)) { | ||
return true; | ||
} | ||
} | ||
|
@@ -1465,23 +1472,28 @@ QJsonObject BrowserService::getPasskeyError(int errorCode) const | |
bool BrowserService::handleURL(const QString& entryUrl, | ||
const QString& siteUrl, | ||
const QString& formUrl, | ||
const bool omitWwwSubdomain) | ||
const bool omitWwwSubdomain, | ||
const bool allowWildcards) | ||
{ | ||
if (entryUrl.isEmpty()) { | ||
return false; | ||
} | ||
|
||
// Exact match where URL is wrapped inside " characters | ||
if (entryUrl.startsWith("\"") && entryUrl.endsWith("\"") && entryUrl.midRef(1, entryUrl.length() - 2) == siteUrl) { | ||
return true; | ||
} | ||
bool isWildcardUrl = false; | ||
auto tempUrl = entryUrl; | ||
|
||
const auto isWildcardUrl = entryUrl.contains("*"); | ||
// Allows matching with exact URL and wildcards | ||
if (allowWildcards) { | ||
// Exact match where URL is wrapped inside " characters | ||
if (entryUrl.startsWith("\"") && entryUrl.endsWith("\"")) { | ||
return QStringView{entryUrl}.mid(1, entryUrl.length() - 2) == siteUrl; | ||
} | ||
|
||
// Replace wildcards | ||
auto tempUrl = entryUrl; | ||
if (isWildcardUrl) { | ||
tempUrl = tempUrl.replace("*", UrlTools::URL_WILDCARD); | ||
// Replace wildcards | ||
isWildcardUrl = entryUrl.contains("*"); | ||
if (isWildcardUrl) { | ||
tempUrl = tempUrl.replace("*", UrlTools::URL_WILDCARD); | ||
} | ||
} | ||
|
||
QUrl entryQUrl; | ||
|
@@ -1512,7 +1524,7 @@ bool BrowserService::handleURL(const QString& entryUrl, | |
|
||
// Match port, if used | ||
QUrl siteQUrl(siteUrl); | ||
if ((entryQUrl.port() > 0) && entryQUrl.port() != siteQUrl.port()) { | ||
if (entryQUrl.port() > 0 && entryQUrl.port() != siteQUrl.port()) { | ||
return false; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (C) 2024 KeePassXC Team <[email protected]> | ||
* Copyright (C) 2025 KeePassXC Team <[email protected]> | ||
* Copyright (C) 2017 Sami Vänttinen <[email protected]> | ||
* Copyright (C) 2013 Francois Ferrand | ||
* | ||
|
@@ -200,7 +200,8 @@ private slots: | |
bool handleURL(const QString& entryUrl, | ||
const QString& siteUrl, | ||
const QString& formUrl, | ||
const bool omitWwwSubdomain = false); | ||
const bool omitWwwSubdomain = false, | ||
const bool allowWildcards = false); | ||
bool handleURLWithWildcards(const QUrl& entryQUrl, const QString& siteUrl); | ||
QString getDatabaseRootUuid(); | ||
QString getDatabaseRecycleBinUuid(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (C) 2024 KeePassXC Team <[email protected]> | ||
* Copyright (C) 2025 KeePassXC Team <[email protected]> | ||
* Copyright (C) 2010 Felix Geyer <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
|
@@ -100,7 +100,9 @@ class Entry : public ModifiableObject | |
const AutoTypeAssociations* autoTypeAssociations() const; | ||
QString title() const; | ||
QString url() const; | ||
QString resolveUrl() const; | ||
QStringList getAllUrls() const; | ||
QStringList getAdditionalUrls() const; | ||
QString webUrl() const; | ||
QString displayUrl() const; | ||
QString username() const; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (C) 2023 KeePassXC Team <[email protected]> | ||
* Copyright (C) 2025 KeePassXC Team <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
|
@@ -53,7 +53,7 @@ private slots: | |
void testRestrictBrowserKey(); | ||
|
||
private: | ||
QList<Entry*> createEntries(QStringList& urls, Group* root) const; | ||
QList<Entry*> createEntries(QStringList& urls, Group* root, bool additionalUrl = false) const; | ||
void compareEntriesByPath(QSharedPointer<Database> db, QList<Entry*> entries, QString path); | ||
|
||
QScopedPointer<BrowserAction> m_browserAction; | ||
|