fix(security): prevent eager keychain password fetch on startup

Defers fetching site login passwords until they are strictly needed (when a download starts or when viewing properties) to prevent the OS from showing the keychain prompt before the in-app primer UI.
This commit is contained in:
NimBold
2026-06-10 12:03:11 +03:30
parent 14924cf254
commit fd90055ccd
2 changed files with 7 additions and 5 deletions
+5 -4
View File
@@ -503,6 +503,11 @@ final class DownloadController: ObservableObject {
private func injectedEngineItem(from item: DownloadItem) -> DownloadItem {
var engineItem = item
if engineItem.credentials != nil {
if let storedPassword = KeychainCredentialStore.password(for: engineItem.id) {
engineItem.credentials?.password = storedPassword
}
}
let ua = settings.customUserAgent.trimmingCharacters(in: .whitespacesAndNewlines)
if !ua.isEmpty, !(engineItem.requestHeaders?.contains(where: { $0.name.caseInsensitiveCompare("user-agent") == .orderedSame }) ?? false) {
var headers = engineItem.requestHeaders ?? []
@@ -1044,10 +1049,6 @@ final class DownloadController: ObservableObject {
adjusted.queueID = DownloadQueue.mainQueueID
}
if adjusted.credentials != nil, let storedPassword = KeychainCredentialStore.password(for: adjusted.id) {
adjusted.credentials?.password = storedPassword
}
if adjusted.status == .completed && adjusted.progress != 1 {
adjusted.progress = 1
shouldRewriteStoredDownloads = true
@@ -60,7 +60,8 @@ struct DownloadPropertiesView: View {
if let credentials = item.credentials {
_loginMode = State(initialValue: .custom)
_username = State(initialValue: credentials.username)
_password = State(initialValue: credentials.password)
let storedPassword = KeychainCredentialStore.password(for: item.id) ?? credentials.password
_password = State(initialValue: storedPassword)
} else {
_loginMode = State(initialValue: .matching)
_username = State(initialValue: "")