Skip to content

Commit

Permalink
Merge branch 'main' into sam/set-vpn-user-agent
Browse files Browse the repository at this point in the history
* main:
  Bump C-S-S to 6.14.1 (#977)
  Bump C-S-S to 6.14.0 (#973)
  Remote feature flag for New Tab Page Improvements (#969)
  Adds new Autofill unknownUsernameCategorization feature flag (#968)
  Fix site owned by major network (#966)
  • Loading branch information
samsymons committed Sep 9, 2024
2 parents 07989cd + 6cb645f commit ee3f70e
Show file tree
Hide file tree
Showing 14 changed files with 314 additions and 41 deletions.
8 changes: 4 additions & 4 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/content-scope-scripts",
"state" : {
"revision" : "5876a5d2e2e7f5a2e11f6419c6c3fafb7cafdfca",
"version" : "6.12.0"
"revision" : "b8c858a33cfe665ddfe177df4dbd63d12f6777a6",
"version" : "6.14.1"
}
},
{
Expand Down Expand Up @@ -86,8 +86,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/TrackerRadarKit",
"state" : {
"revision" : "1403e17eeeb8493b92fb9d11eb8c846bb9776581",
"version" : "2.1.2"
"revision" : "5de0a610a7927b638a5fd463a53032c9934a2c3b",
"version" : "3.0.0"
}
}
],
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ let package = Package(
dependencies: [
.package(url: "https://github.com/duckduckgo/duckduckgo-autofill.git", exact: "13.0.0"),
.package(url: "https://github.com/duckduckgo/GRDB.swift.git", exact: "2.4.0"),
.package(url: "https://github.com/duckduckgo/TrackerRadarKit", exact: "2.1.2"),
.package(url: "https://github.com/duckduckgo/TrackerRadarKit", exact: "3.0.0"),
.package(url: "https://github.com/duckduckgo/sync_crypto", exact: "0.2.0"),
.package(url: "https://github.com/gumob/PunycodeSwift.git", exact: "2.1.0"),
.package(url: "https://github.com/duckduckgo/content-scope-scripts", exact: "6.12.0"),
.package(url: "https://github.com/duckduckgo/content-scope-scripts", exact: "6.14.1"),
.package(url: "https://github.com/duckduckgo/privacy-dashboard", exact: "5.1.1"),
.package(url: "https://github.com/httpswift/swifter.git", exact: "1.5.0"),
.package(url: "https://github.com/duckduckgo/bloom_cpp.git", exact: "3.0.0"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@ extension TrackerData {
return nil
}

/// Returns the parent of the entity associated with the host if any. If the entity associated with the host doesn't have a parent return the entity. Otherwise, return nil.
/// - Parameter host:
/// - Returns: The entity associated with the host.
public func findParentEntityOrFallback(forHost host: String) -> Entity? {
// If the entity associated with the host is owned by a parent company (e.g. Instagram is owned by Facebook) return the parent company.
// If the entity associated with the host is not owned by a parent company return the entity.
// If the are no entities associated with the host return nil
for host in variations(of: host) {
if let trackerOwner = trackers[host]?.owner?.ownedBy {
return entities[trackerOwner]
} else if let entityName = domains[host] {
return entities[entityName]
}
}
return nil
}

private func variations(of host: String) -> [String] {
var parts = host.components(separatedBy: ".")
var domains = [String]()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public struct ContentScopeFeatureToggles: Encodable {
public let inlineIconCredentials: Bool
public let thirdPartyCredentialsProvider: Bool

public let unknownUsernameCategorization: Bool

// Explicitly defined memberwise init only so it can be public
public init(emailProtection: Bool,
emailProtectionIncontextSignup: Bool,
Expand All @@ -86,7 +88,8 @@ public struct ContentScopeFeatureToggles: Encodable {
credentialsSaving: Bool,
passwordGeneration: Bool,
inlineIconCredentials: Bool,
thirdPartyCredentialsProvider: Bool) {
thirdPartyCredentialsProvider: Bool,
unknownUsernameCategorization: Bool) {

self.emailProtection = emailProtection
self.emailProtectionIncontextSignup = emailProtectionIncontextSignup
Expand All @@ -97,6 +100,7 @@ public struct ContentScopeFeatureToggles: Encodable {
self.passwordGeneration = passwordGeneration
self.inlineIconCredentials = inlineIconCredentials
self.thirdPartyCredentialsProvider = thirdPartyCredentialsProvider
self.unknownUsernameCategorization = unknownUsernameCategorization
}

enum CodingKeys: String, CodingKey {
Expand All @@ -113,6 +117,7 @@ public struct ContentScopeFeatureToggles: Encodable {

case inlineIconCredentials = "inlineIcon_credentials"
case thirdPartyCredentialsProvider = "third_party_credentials_provider"
case unknownUsernameCategorization = "unknown_username_categorization"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public enum PrivacyFeature: String {
case brokenSitePrompt
case remoteMessaging
case additionalCampaignPixelParams
case newTabPageImprovements
case syncPromotion
}

Expand All @@ -77,6 +78,7 @@ public enum AutofillSubfeature: String, PrivacySubfeature {
case onByDefault
case deduplicateLoginsOnImport
case onForExistingUsers
case unknownUsernameCategorization
}

public enum DBPSubfeature: String, Equatable, PrivacySubfeature {
Expand Down
2 changes: 1 addition & 1 deletion Sources/ContentBlocking/DetectedRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public struct DetectedRequest: Encodable {
self.url = url
self.eTLDplus1 = eTLDplus1
self.state = state
self.ownerName = knownTracker?.owner?.name
self.ownerName = knownTracker?.owner?.ownedBy ?? knownTracker?.owner?.name
self.entityName = entity?.displayName
self.category = knownTracker?.category
self.prevalence = entity?.prevalence
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ final class AdClickAttributionRulesSplitterTests: XCTestCase {
private func makeKnownTracker(withName name: String, ownerName: String) -> KnownTracker {
KnownTracker(domain: name,
defaultAction: .block,
owner: .init(name: ownerName, displayName: ownerName),
owner: .init(name: ownerName, displayName: ownerName, ownedBy: nil),
prevalence: 5.0,
subdomains: nil,
categories: nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ final class ClickToLoadRulesSplitterTests: XCTestCase {
private func makeKnownTracker(withName name: String, ownerName: String) -> KnownTracker {
KnownTracker(domain: name,
defaultAction: .block,
owner: .init(name: ownerName, displayName: ownerName),
owner: .init(name: ownerName, displayName: ownerName, ownedBy: nil),
prevalence: 5.0,
subdomains: nil,
categories: nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class ContentBlockingRulesHelper {

let tracker = KnownTracker(domain: "tracker.com",
defaultAction: .block,
owner: KnownTracker.Owner(name: "Tracker", displayName: "Tracker"),
owner: KnownTracker.Owner(name: "Tracker", displayName: "Tracker", ownedBy: nil),
prevalence: 0.1,
subdomains: nil,
categories: nil,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
//
// TrackerDataQueryExtensionTests.swift
//
// 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 XCTest
import TrackerRadarKit
@testable import BrowserServicesKit

final class TrackerDataQueryExtensionTests: XCTestCase {

func testWhenHostHasAnEntityAssociatedAndEntityHasAParentThenReturnParent() throws {
// GIVEN
let tds = try JSONDecoder().decode(TrackerData.self, from: Self.mockTDS)

// WHEN
let result = try XCTUnwrap(tds.findParentEntityOrFallback(forHost: "www.instagram.com"))

// THEN
XCTAssertEqual(result.displayName, "Facebook")
}

func testWhenHostHasAnEntityAssociatedAndEntityDoesNotHaveAParentThenReturnEntityAssociated() throws {
// GIVEN
let tds = try JSONDecoder().decode(TrackerData.self, from: Self.mockTDS)

// WHEN
let result = try XCTUnwrap(tds.findParentEntityOrFallback(forHost: "www.roku.com"))

// THEN
XCTAssertEqual(result.displayName, "Roku")
}

func testWhenHostDoesNotHaveAnEntityAssociatedThenReturnNil() throws {
// GIVEN
let tds = try JSONDecoder().decode(TrackerData.self, from: Self.mockTDS)

// WHEN
let result = tds.findParentEntityOrFallback(forHost: "www.test.com")

// THEN
XCTAssertNil(result)
}

}

private extension TrackerDataQueryExtensionTests {

static let mockTDS = """
{
"trackers": {
"instagram.com": {
"domain": "instagram.com",
"owner": {
"name": "Instagram",
"displayName": "Instagram (Facebook)",
"localizedName": "Instagram",
"ownedBy": "Facebook, Inc."
},
"prevalence": 0.00573,
"fingerprinting": 1,
"cookies": 0.00139,
"categories": [
"Ad Motivated Tracking",
"Advertising",
"Embedded Content",
"Social - Share",
"Social Network"
],
"default": "ignore",
"rules": [
{
"rule": "instagram\\.com\\/en_US\\/embeds\\.js",
"fingerprinting": 1,
"cookies": 0
},
{
"rule": "instagram\\.com\\/embed\\.js",
"fingerprinting": 1,
"cookies": 0
},
{
"rule": "instagram\\.com\\/ajax\\/bz",
"fingerprinting": 0,
"cookies": 0.000864
},
{
"rule": "instagram\\.com\\/logging\\/falco",
"fingerprinting": 0,
"cookies": 0.0000817
},
{
"rule": "instagram\\.com\\/static\\/bundles\\/es6\\/EmbedSDK\\.js\\/2fe3a16f6aeb\\.js",
"fingerprinting": 1,
"cookies": 0
},
{
"rule": "instagram\\.com\\/login\\/",
"fingerprinting": 0,
"cookies": 0,
"comment": "pixel"
},
{
"rule": "instagram\\.com\\/accounts\\/login\\/",
"fingerprinting": 0,
"cookies": 0,
"comment": "pixel"
},
{
"rule": "instagram\\.com\\/static\\/images\\/ig-badge-view-24\\.png",
"fingerprinting": 0,
"cookies": 0.0000408,
"comment": "pixel"
},
{
"rule": "instagram\\.com\\/static\\/images\\/ig-badge-view-sprite-24\\.png",
"fingerprinting": 0,
"cookies": 0.0000408,
"comment": "pixel"
},
{
"rule": "instagram\\.com\\/v1\\/users\\/self\\/media\\/recent",
"fingerprinting": 0,
"cookies": 0.0000613,
"comment": "pixel"
}
]
}
},
"entities": {
"Facebook, Inc.": {
"domains": [
"accountkit.com",
"atdmt.com",
"atdmt2.com",
"atlassbx.com",
"atlassolutions.com",
"cdninstagram.com",
"crowdtangle.com",
"facebook.com",
"facebook.net",
"facebookmail.com",
"fb.com",
"fb.gg",
"fb.me",
"fbcdn.net",
"fbsbx.com",
"fbthirdpartypixel.com",
"fbthirdpartypixel.net",
"fbthirdpartypixel.org",
"flow.org",
"flowtype.org",
"graphql.org",
"instagram.co",
"liverail.com",
"m.me",
"messenger.com",
"oculus.com",
"oculuscdn.com",
"oculusrift.com",
"oculusvr.com",
"onavo.com",
"onavo.net",
"onavo.org",
"onavoinsights.com",
"powersunitedvr.com",
"reactjs.org",
"thefind.com",
"vircado.com",
"wa.me",
"whatsapp.com",
"whatsapp.net",
"wit.ai"
],
"prevalence": 26.4,
"displayName": "Facebook"
},
"Roku, Inc.": {
"domains": [
"dataxu.com",
"ravm.net",
"ravm.tv",
"roku.com",
"rokulabs.net",
"rokutime.com",
"w55c.net"
],
"prevalence": 7.57,
"displayName": "Roku"
},
},
"Example Limited": {
"domains": [
"example.com",
"examplerules.com"
],
"prevalence": 1,
"displayName": "Example Ltd"
},
"domains": {
"instagram.com": "Instagram",
"roku.com": "Roku, Inc.",
},
"cnames": {}
}
""".data(using: .utf8)!
}
Loading

0 comments on commit ee3f70e

Please sign in to comment.