Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Malicious site protection App settings #3734

Open
wants to merge 48 commits into
base: alessandro/malicious-site-protection-navigation-detection-integration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
1360413
Add Detection Logic
alessandroboron Nov 29, 2024
ef254a4
Integrate MaliciousSiteProtection
alessandroboron Dec 2, 2024
5c548fc
Hardcode malicious site detection
alessandroboron Dec 2, 2024
ff38770
Use isSpecialErrorPageRequest flag to avoid navigation loops
alessandroboron Dec 3, 2024
2677c74
Clean up due to integration with BSK
alessandroboron Dec 3, 2024
d4e9dff
Add test for malicious site navigation handler
alessandroboron Dec 3, 2024
413e3fe
Disable adding redirect to examption URLs
alessandroboron Dec 3, 2024
29c4ce3
Re-set bypassed threat kind at every page load
alessandroboron Dec 4, 2024
0948220
Refactor MaliciousSiteProtectionNavigationHandler
alessandroboron Dec 9, 2024
1951870
Refactor SpecialErrorPageNavigationHandler and handle synchronisation
alessandroboron Dec 9, 2024
a3b09c0
Fix typo for Malicious site Navigation Handler method
alessandroboron Dec 9, 2024
ab8d26a
Update the logic for handling malicious site protection
alessandroboron Dec 9, 2024
1e34d32
Close Tab when leaving malicious site
alessandroboron Dec 9, 2024
937bcab
Update BSK version
alessandroboron Dec 9, 2024
c187557
Clean up
alessandroboron Dec 10, 2024
1c0bc9d
Update BSK after rebasing
alessandroboron Dec 19, 2024
18405b2
Address PR comments
alessandroboron Jan 7, 2025
c3dbd41
Update BSK after merge conflicts resolve
alessandroboron Jan 9, 2025
72ba9b3
Rename AppState -> Testing to AppTesting
alessandroboron Jan 9, 2025
83cb6f0
Update privacy icon for special error pages
alessandroboron Dec 11, 2024
31282b9
Update Privacy Dashboard and omnibar icon for malicious websites
alessandroboron Dec 11, 2024
b4d4dd0
Updated BSK and Privacy Dashboard after merge conflict resolve
alessandroboron Jan 9, 2025
bfe728f
Fix unit tests after addressing PR comments
alessandroboron Jan 9, 2025
560ef30
Add feature flags for malicious site protection
alessandroboron Dec 11, 2024
d610ff0
Parse settings for Malicious Site protection remote config
alessandroboron Jan 9, 2025
7342913
Removed deinit from Malicious Site Protection test suite
alessandroboron Jan 10, 2025
744d6aa
Add Malicious Site Protection subfeature
alessandroboron Jan 10, 2025
965c759
Add MaliciouSiteProtectionManager config and resources
alessandroboron Dec 11, 2024
caea666
Add manager initial logic
alessandroboron Dec 11, 2024
3990bbe
Refactor logic and added unit tests
alessandroboron Dec 12, 2024
039ace3
Add MaliciousSiteProtection integration tests
alessandroboron Dec 13, 2024
26ca534
Reset Error Data when new navigation happens
alessandroboron Dec 13, 2024
49ec52b
Remove files added by mistake to ATBUITests target
alessandroboron Dec 13, 2024
8e24566
Fix closing tab for malicious site protection and open a new tab in s…
alessandroboron Dec 13, 2024
5eb3f8f
Move MaliciousSiteProtectionPreferences to its own file
alessandroboron Dec 13, 2024
2c039c9
Fix tests
alessandroboron Dec 13, 2024
8ef0343
Change file store directory to application support
alessandroboron Dec 16, 2024
1675882
Disable SwiftLint rule nesting
alessandroboron Dec 16, 2024
46f15da
clean up code
alessandroboron Dec 16, 2024
f575a61
Fixed tests
alessandroboron Jan 9, 2025
4d87dab
Use malicious site protection remote settings
alessandroboron Jan 10, 2025
61f677f
wip
alessandroboron Nov 22, 2024
f29fe92
Add Malicious Site Protection Learn More URL
alessandroboron Dec 16, 2024
14f096a
Add tests for Preferences Manager
alessandroboron Dec 16, 2024
1d44526
Add Settings VM and tests
alessandroboron Dec 16, 2024
d88ec93
Add View for settings
alessandroboron Dec 16, 2024
47540f5
Fix malicious site protection user preference being out of sync
alessandroboron Dec 19, 2024
5be55a9
Clean up code
alessandroboron Jan 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Core/AppURLs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public extension URL {
static let apps = URL(string: AppDeepLinkSchemes.quickLink.appending("\(ddg.host!)/apps?origin=funnel_app_ios"))!
static let searchSettings = URL(string: AppDeepLinkSchemes.quickLink.appending("\(ddg.host!)/settings"))!
static let autofillHelpPageLink = URL(string: AppDeepLinkSchemes.quickLink.appending("\(ddg.host!)/duckduckgo-help-pages/sync-and-backup/password-manager-security/"))!
static let maliciousSiteProtectionLearnMore = URL(string: AppDeepLinkSchemes.quickLink.appending("\(ddg.host!)/duckduckgo-help-pages/privacy/phishing-and-malware-protection/"))!

static let surrogates = URL(string: "\(staticBase)/surrogates.txt")!

Expand Down
6 changes: 6 additions & 0 deletions Core/FeatureFlag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public enum FeatureFlag: String {

/// https://app.asana.com/0/0/1208767141940869/f
case freeTrials

/// Feature flag to enable / disable phishing and malware protection
/// https://app.asana.com/0/1206329551987282/1207149365636877/f
case maliciousSiteProtection
}

extension FeatureFlag: FeatureFlagDescribing {
Expand Down Expand Up @@ -146,6 +150,8 @@ extension FeatureFlag: FeatureFlagDescribing {
return .remoteReleasable(.subfeature(PrivacyProSubfeature.isLaunchedROWOverride))
case .freeTrials:
return .remoteDevelopment(.subfeature(PrivacyProSubfeature.freeTrials))
case .maliciousSiteProtection:
return .remoteDevelopment(.subfeature(MaliciousSiteProtectionSubfeature.onByDefault))
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions Core/UserDefaultsPropertyWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ public struct UserDefaultsWrapper<T> {

// TipKit
case resetTipKitOnNextLaunch = "com.duckduckgo.ios.tipKit.resetOnNextLaunch"

// Malicious Site Protection
case maliciousSiteProtectionEnabled = "com.duckduckgo.ios.maliciousSiteProtection.enabled"
}

private let key: Key
Expand Down
153 changes: 133 additions & 20 deletions DuckDuckGo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/DuckDuckGo/BrowserServicesKit",
"state" : {
"revision" : "14384f05a6e43842c4626e06736e2c4f5d758057",
"version" : "224.1.0"
"branch" : "alessandro/malicious-site-protection-address-bar-and-privacy-dashboard",
"revision" : "99c0009d13e4b7ac1540e29f51d0a871adec1253"
}
},
{
Expand Down Expand Up @@ -122,8 +122,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/privacy-dashboard",
"state" : {
"revision" : "2e2baf7d31c7d8e158a58bc1cb79498c1c727fd2",
"version" : "7.5.0"
"branch" : "pr-releases/pr-252",
"revision" : "38ffba856dcc8cebcb21b4e0c49f512fe695e576"
}
},
{
Expand Down
2 changes: 2 additions & 0 deletions DuckDuckGo/AppDependencyProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ protocol DependencyProvider {
var serverInfoObserver: ConnectionServerInfoObserver { get }
var vpnSettings: VPNSettings { get }
var persistentPixel: PersistentPixelFiring { get }
var maliciousSiteProtectionPreferencesManager: MaliciousSiteProtectionPreferencesManaging { get }

}

Expand Down Expand Up @@ -91,6 +92,7 @@ final class AppDependencyProvider: DependencyProvider {
let serverInfoObserver: ConnectionServerInfoObserver = ConnectionServerInfoObserverThroughSession()
let vpnSettings = VPNSettings(defaults: .networkProtectionGroupDefaults)
let persistentPixel: PersistentPixelFiring = PersistentPixel()
let maliciousSiteProtectionPreferencesManager: MaliciousSiteProtectionPreferencesManaging = MaliciousSiteProtectionPreferencesManager()

private init() {
let featureFlaggerOverrides = FeatureFlagLocalOverrides(keyValueStore: UserDefaults(suiteName: FeatureFlag.localOverrideStoreName)!,
Expand Down
4 changes: 2 additions & 2 deletions DuckDuckGo/AppLifecycle/AppStateTransitions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extension Init {
switch event {
case .launching(let application, let isTesting):
if isTesting {
return Testing(application: application)
return AppTesting(application: application)
}
return Launched(stateContext: makeStateContext(application: application))
default:
Expand Down Expand Up @@ -116,7 +116,7 @@ extension Background {

}

extension Testing {
extension AppTesting {

func apply(event: AppEvent) -> any AppState { self }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Testing.swift
// AppTesting.swift
// DuckDuckGo
//
// Copyright © 2024 DuckDuckGo. All rights reserved.
Expand All @@ -21,7 +21,7 @@ import Core
import UIKit

@MainActor
struct Testing: AppState {
struct AppTesting: AppState {

init(application: UIApplication) {
Pixel.isDryRun = true
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "Alert-Recolorable-24.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
7 changes: 3 additions & 4 deletions DuckDuckGo/Base.lproj/OmniBar.xib
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
<constraint firstAttribute="width" constant="158" id="yFt-j7-mPi"/>
</constraints>
</view>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="center" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="LogoIcon" translatesAutoresizingMaskIntoConstraints="NO" id="eoZ-Ly-QHi">
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="center" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="eoZ-Ly-QHi">
<rect key="frame" x="0.0" y="2" width="43" height="38"/>
</imageView>
</subviews>
Expand All @@ -185,9 +185,9 @@
<constraint firstItem="eoZ-Ly-QHi" firstAttribute="leading" secondItem="99p-YW-bjm" secondAttribute="leading" id="VgX-60-gzX"/>
</constraints>
<connections>
<outlet property="daxLogoImageView" destination="eoZ-Ly-QHi" id="aTN-UG-1Em"/>
<outlet property="shieldAnimationView" destination="dqb-pm-Da8" id="m3S-lp-2hi"/>
<outlet property="shieldDotAnimationView" destination="D46-aN-352" id="yuP-Tc-fZl"/>
<outlet property="staticImageView" destination="eoZ-Ly-QHi" id="DD9-w9-GZy"/>
<outlet property="staticShieldAnimationView" destination="jQy-me-Afa" id="pez-0Q-5Gq"/>
<outlet property="staticShieldDotAnimationView" destination="KE6-Wh-7Yp" id="92x-it-Oyn"/>
<outletCollection property="gestureRecognizers" destination="qXd-RO-1cS" appends="YES" id="3xf-ou-ORG"/>
Expand Down Expand Up @@ -458,7 +458,6 @@
<image name="Clear-24" width="24" height="24"/>
<image name="Close-24" width="24" height="24"/>
<image name="Find-Search-20" width="20" height="20"/>
<image name="LogoIcon" width="24" height="24"/>
<image name="Microphone-24" width="24" height="24"/>
<image name="Reload-24" width="24" height="24"/>
<image name="Settings-24" width="24" height="24"/>
Expand All @@ -467,7 +466,7 @@
<color red="0.96078431372549022" green="0.96078431372549022" blue="0.96078431372549022" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</namedColor>
<systemColor name="systemGreenColor">
<color red="0.20392156862745098" green="0.7803921568627451" blue="0.34901960784313724" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color red="0.20392156859999999" green="0.78039215689999997" blue="0.34901960780000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
<systemColor name="systemYellowColor">
<color red="1" green="0.80000000000000004" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
Expand Down
18 changes: 13 additions & 5 deletions DuckDuckGo/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2320,8 +2320,8 @@ extension MainViewController: TabDelegate {
return newTab.webView
}

func tabDidRequestClose(_ tab: TabViewController) {
closeTab(tab.tabModel)
func tabDidRequestClose(_ tab: TabViewController, shouldCreateEmptyTabAtSamePosition: Bool) {
closeTab(tab.tabModel, andOpenEmptyOneAtSamePosition: shouldCreateEmptyTabAtSamePosition)
}

func tabLoadingStateDidChange(tab: TabViewController) {
Expand Down Expand Up @@ -2571,12 +2571,20 @@ extension MainViewController: TabSwitcherDelegate {
showFireButtonPulse()
}
}
func closeTab(_ tab: Tab) {

func closeTab(_ tab: Tab, andOpenEmptyOneAtSamePosition shouldOpen: Bool = false) {
guard let index = tabManager.model.indexOf(tab: tab) else { return }
hideSuggestionTray()
hideNotificationBarIfBrokenSitePromptShown()
tabManager.remove(at: index)

if shouldOpen {
let newTab = Tab()
tabManager.replaceTab(at: index, withNewTab: newTab)
tabManager.selectTab(newTab)
} else {
tabManager.remove(at: index)
}

updateCurrentTab()
tabsBarController?.refresh(tabsModel: tabManager.model)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
//
// MaliciousSiteProtectionFeatureFlags.swift
// DuckDuckGo
//
// Copyright © 2024 DuckDuckGo. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation
import BrowserServicesKit
import Core

protocol MaliciousSiteProtectionFeatureFlagger {
/// A Boolean value indicating whether malicious site protection is enabled.
/// - Returns: `true` if malicious site protection is enabled; otherwise, `false`.
var isMaliciousSiteProtectionEnabled: Bool { get }

/// Checks if should detect malicious threats for a specific domain.
/// - Parameter domain: The domain to check for malicious threat.
/// - Returns: `true` if should check for malicious threats for the specified domain; otherwise, `false`.
func shouldDetectMaliciousThreat(forDomain domain: String?) -> Bool
}

protocol MaliciousSiteProtectionFeatureFlagsSettingsProvider {
/// The frequency, in minutes, at which the hash prefix should be updated.
var hashPrefixUpdateFrequency: Int { get }
/// The frequency, in minutes, at which the filter set should be updated.
var filterSetUpdateFrequency: Int { get }
}

/// An enum representing the different settings for malicious site protection feature flags.
enum MaliciousSiteProtectionFeatureSettings: String {
/// The setting for hash prefix update frequency.
case hashPrefixUpdateFrequency
/// The setting for filter set update frequency.
case filterSetUpdateFrequency

var defaultValue: Int {
switch self {
case .hashPrefixUpdateFrequency: return 20 // Default frequency for hash prefix updates is 20 minutes.
case .filterSetUpdateFrequency: return 720 // Default frequency for filter set updates is 720 minutes (12 hours).
}
}
}

final class MaliciousSiteProtectionFeatureFlags {
private let featureFlagger: FeatureFlagger
private let privacyConfigManager: PrivacyConfigurationManaging

private var remoteSettings: PrivacyConfigurationData.PrivacyFeature.FeatureSettings {
privacyConfigManager.privacyConfig.settings(for: .maliciousSiteProtection)
}

init(
featureFlagger: FeatureFlagger = AppDependencyProvider.shared.featureFlagger,
privacyConfigManager: PrivacyConfigurationManaging = ContentBlocking.shared.privacyConfigurationManager
) {
self.featureFlagger = featureFlagger
self.privacyConfigManager = privacyConfigManager
}
}

// MARK: - MaliciousSiteProtectionFeatureFlagger

extension MaliciousSiteProtectionFeatureFlags: MaliciousSiteProtectionFeatureFlagger {

var isMaliciousSiteProtectionEnabled: Bool {
featureFlagger.isFeatureOn(.maliciousSiteProtection)
}

func shouldDetectMaliciousThreat(forDomain domain: String?) -> Bool {
isMaliciousSiteProtectionEnabled && privacyConfigManager.privacyConfig.isFeature(.maliciousSiteProtection, enabledForDomain: domain)
}

}

// MARK: - MaliciousSiteProtectionFeatureFlagsSettingsProvider

extension MaliciousSiteProtectionFeatureFlags: MaliciousSiteProtectionFeatureFlagsSettingsProvider {

var hashPrefixUpdateFrequency: Int {
getSettings(MaliciousSiteProtectionFeatureSettings.hashPrefixUpdateFrequency)
}

var filterSetUpdateFrequency: Int {
getSettings(MaliciousSiteProtectionFeatureSettings.filterSetUpdateFrequency)
}

private func getSettings(_ value: MaliciousSiteProtectionFeatureSettings) -> Int {
remoteSettings[value.rawValue] as? Int ?? value.defaultValue
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// MaliciousSiteProtectionManager+Config.swift
// DuckDuckGo
//
// Copyright © 2024 DuckDuckGo. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation
import MaliciousSiteProtection

extension MaliciousSiteProtectionManager {

static func fileName(for dataType: MaliciousSiteProtection.DataManager.StoredDataType) -> String {
switch (dataType, dataType.threatKind) {
case (.hashPrefixSet, .phishing): "phishingHashPrefixes.json"
case (.filterSet, .phishing): "phishingFilterSet.json"
case (.hashPrefixSet, .malware): "malwareHashPrefixes.json"
case (.filterSet, .malware): "malwareFilterSet.json"
}
}

struct EmbeddedDataProvider: MaliciousSiteProtection.EmbeddedDataProviding {

// swiftlint:disable:next nesting
private enum Constants {
static let embeddedDataRevision = 1696473
static let phishingEmbeddedHashPrefixDataSHA = "cdb609c37e950b7d0dcdaa80ae4071cf2c87223cfdd189caafae723722bd3158"
static let phishingEmbeddedFilterSetDataSHA = "4e52518aba04b0fd360fada76c9899001d3137d4a745cc13c484a54115a0fcd8"
static let malwareEmbeddedHashPrefixDataSHA = "6b5eb296e9e10ae9ea41c5b5356f532226d647e4f3b832c30ac670102446ea7a"
static let malwareEmbeddedFilterSetDataSHA = "4dc971fffaf244ee99267f28222a2c116743e35ef837dcbc0199693ed6a691cd"
}

func revision(for dataType: MaliciousSiteProtection.DataManager.StoredDataType) -> Int {
Constants.embeddedDataRevision
}

func url(for dataType: MaliciousSiteProtection.DataManager.StoredDataType) -> URL {
let fileName = fileName(for: dataType)
guard let url = Bundle.main.url(forResource: fileName, withExtension: nil) else {
fatalError("Could not find embedded data file \"\(fileName)\"")
}
return url
}

func hash(for dataType: MaliciousSiteProtection.DataManager.StoredDataType) -> String {
switch (dataType, dataType.threatKind) {
case (.hashPrefixSet, .phishing): Constants.phishingEmbeddedHashPrefixDataSHA
case (.filterSet, .phishing): Constants.phishingEmbeddedFilterSetDataSHA
case (.hashPrefixSet, .malware): Constants.malwareEmbeddedHashPrefixDataSHA
case (.filterSet, .malware): Constants.malwareEmbeddedFilterSetDataSHA
}
}

}
}
Loading
Loading