From 7033b0d6f166ac8152cff602f1a1301641f4da60 Mon Sep 17 00:00:00 2001 From: Shane Osbourne Date: Tue, 19 Nov 2024 15:31:55 +0000 Subject: [PATCH] CSS: adding a new messageSecret properties for injected scripts (#1077) Please review the release process for BrowserServicesKit [here](https://app.asana.com/0/1200194497630846/1200837094583426). **Required**: Task/Issue URL: https://app.asana.com/0/0/1208773745506348/f iOS PR: https://github.com/duckduckgo/iOS/pull/3588 macOS PR: https://github.com/duckduckgo/macos-browser/pull/3558 What kind of version bump will this require?: Major/Minor/Patch **Optional**: Tech Design URL: CC: **Description**: **Steps to test this PR**: 1. See the macOS PR https://github.com/duckduckgo/macos-browser/pull/3558 **OS Testing**: * [ ] iOS 14 * [ ] iOS 15 * [ ] iOS 16 * [ ] macOS 10.15 * [ ] macOS 11 * [ ] macOS 12 --- ###### Internal references: [Software Engineering Expectations](https://app.asana.com/0/59792373528535/199064865822552) [Technical Design Template](https://app.asana.com/0/59792373528535/184709971311943) Co-authored-by: Shane Osbourne --- Package.resolved | 4 ++-- Package.swift | 2 +- Sources/BrowserServicesKit/Autofill/AutofillUserScript.swift | 1 + .../ContentScopeScript/ContentScopeUserScript.swift | 5 ++++- .../Autofill/AutofillEmailUserScriptTests.swift | 2 +- .../Autofill/AutofillUserScriptSourceProviderTests.swift | 2 +- .../Autofill/AutofillVaultUserScriptTests.swift | 2 +- .../ContentScopePropertiesTests.swift | 2 +- Tests/BrowserServicesKitTests/Email/EmailManagerTests.swift | 1 + .../Fingerprinting/FingerprintingReferenceTests.swift | 1 + Tests/BrowserServicesKitTests/GPC/GPCReferenceTests.swift | 1 + .../SecureVault/SecureVaultManagerTests.swift | 2 +- 12 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Package.resolved b/Package.resolved index 4fdfdd927..e6f405a33 100644 --- a/Package.resolved +++ b/Package.resolved @@ -14,8 +14,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/duckduckgo/content-scope-scripts", "state" : { - "revision" : "32c3e2bce3cc20a079d96b3ee23a9cde5d2337c3", - "version" : "6.35.0" + "revision" : "f2caf4ff814f4714d07d6fc2cf02498cb54a1389", + "version" : "6.36.0" } }, { diff --git a/Package.swift b/Package.swift index d8e9535ce..36703767e 100644 --- a/Package.swift +++ b/Package.swift @@ -53,7 +53,7 @@ let package = Package( .package(url: "https://github.com/duckduckgo/TrackerRadarKit", exact: "3.0.0"), .package(url: "https://github.com/duckduckgo/sync_crypto", exact: "0.3.0"), .package(url: "https://github.com/gumob/PunycodeSwift.git", exact: "3.0.0"), - .package(url: "https://github.com/duckduckgo/content-scope-scripts", exact: "6.35.0"), + .package(url: "https://github.com/duckduckgo/content-scope-scripts", exact: "6.36.0"), .package(url: "https://github.com/duckduckgo/privacy-dashboard", exact: "7.2.0"), .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"), diff --git a/Sources/BrowserServicesKit/Autofill/AutofillUserScript.swift b/Sources/BrowserServicesKit/Autofill/AutofillUserScript.swift index 8dfba18e2..06325172c 100644 --- a/Sources/BrowserServicesKit/Autofill/AutofillUserScript.swift +++ b/Sources/BrowserServicesKit/Autofill/AutofillUserScript.swift @@ -76,6 +76,7 @@ public class AutofillUserScript: NSObject, UserScript, UserScriptMessageEncrypti public var isBurnerWindow: Bool = false public var sessionKey: String? + public var messageSecret: String? public weak var emailDelegate: AutofillEmailDelegate? public weak var vaultDelegate: AutofillSecureVaultDelegate? diff --git a/Sources/BrowserServicesKit/ContentScopeScript/ContentScopeUserScript.swift b/Sources/BrowserServicesKit/ContentScopeScript/ContentScopeUserScript.swift index 69f058183..8c6ed973c 100644 --- a/Sources/BrowserServicesKit/ContentScopeScript/ContentScopeUserScript.swift +++ b/Sources/BrowserServicesKit/ContentScopeScript/ContentScopeUserScript.swift @@ -27,13 +27,15 @@ public final class ContentScopeProperties: Encodable { public let globalPrivacyControlValue: Bool public let debug: Bool = false public let sessionKey: String + public let messageSecret: String public let languageCode: String public let platform = ContentScopePlatform() public let features: [String: ContentScopeFeature] - public init(gpcEnabled: Bool, sessionKey: String, featureToggles: ContentScopeFeatureToggles) { + public init(gpcEnabled: Bool, sessionKey: String, messageSecret: String, featureToggles: ContentScopeFeatureToggles) { self.globalPrivacyControlValue = gpcEnabled self.sessionKey = sessionKey + self.messageSecret = messageSecret languageCode = Locale.current.languageCode ?? "en" features = [ "autofill": ContentScopeFeature(featureToggles: featureToggles) @@ -47,6 +49,7 @@ public final class ContentScopeProperties: Encodable { case globalPrivacyControlValue case debug case sessionKey + case messageSecret case platform case features } diff --git a/Tests/BrowserServicesKitTests/Autofill/AutofillEmailUserScriptTests.swift b/Tests/BrowserServicesKitTests/Autofill/AutofillEmailUserScriptTests.swift index 7d42b6804..230e6a9d8 100644 --- a/Tests/BrowserServicesKitTests/Autofill/AutofillEmailUserScriptTests.swift +++ b/Tests/BrowserServicesKitTests/Autofill/AutofillEmailUserScriptTests.swift @@ -37,7 +37,7 @@ class AutofillEmailUserScriptTests: XCTestCase { } """.data(using: .utf8)! let privacyConfig = AutofillTestHelper.preparePrivacyConfig(embeddedConfig: embeddedConfig) - let properties = ContentScopeProperties(gpcEnabled: false, sessionKey: "1234", featureToggles: ContentScopeFeatureToggles.allTogglesOn) + let properties = ContentScopeProperties(gpcEnabled: false, sessionKey: "1234", messageSecret: "1234", featureToggles: ContentScopeFeatureToggles.allTogglesOn) let sourceProvider = DefaultAutofillSourceProvider.Builder(privacyConfigurationManager: privacyConfig, properties: properties) .withJSLoading() diff --git a/Tests/BrowserServicesKitTests/Autofill/AutofillUserScriptSourceProviderTests.swift b/Tests/BrowserServicesKitTests/Autofill/AutofillUserScriptSourceProviderTests.swift index 64b2c3504..b78c1d160 100644 --- a/Tests/BrowserServicesKitTests/Autofill/AutofillUserScriptSourceProviderTests.swift +++ b/Tests/BrowserServicesKitTests/Autofill/AutofillUserScriptSourceProviderTests.swift @@ -88,7 +88,7 @@ final class AutofillUserScriptSourceProviderTests: XCTestCase { } """.data(using: .utf8)! lazy var privacyConfig = AutofillTestHelper.preparePrivacyConfig(embeddedConfig: embeddedConfig) - let properties = ContentScopeProperties(gpcEnabled: false, sessionKey: "1234", featureToggles: ContentScopeFeatureToggles.allTogglesOn) + let properties = ContentScopeProperties(gpcEnabled: false, sessionKey: "1234", messageSecret: "1234", featureToggles: ContentScopeFeatureToggles.allTogglesOn) func testWhenBuildWithLoadJSThenSourceStrIsBuilt() { let autofillSourceProvider = DefaultAutofillSourceProvider.Builder(privacyConfigurationManager: privacyConfig, diff --git a/Tests/BrowserServicesKitTests/Autofill/AutofillVaultUserScriptTests.swift b/Tests/BrowserServicesKitTests/Autofill/AutofillVaultUserScriptTests.swift index f146e9447..9177065b1 100644 --- a/Tests/BrowserServicesKitTests/Autofill/AutofillVaultUserScriptTests.swift +++ b/Tests/BrowserServicesKitTests/Autofill/AutofillVaultUserScriptTests.swift @@ -42,7 +42,7 @@ class AutofillVaultUserScriptTests: XCTestCase { } """.data(using: .utf8)! let privacyConfig = AutofillTestHelper.preparePrivacyConfig(embeddedConfig: embeddedConfig) - let properties = ContentScopeProperties(gpcEnabled: false, sessionKey: "1234", featureToggles: ContentScopeFeatureToggles.allTogglesOn) + let properties = ContentScopeProperties(gpcEnabled: false, sessionKey: "1234", messageSecret: "1234", featureToggles: ContentScopeFeatureToggles.allTogglesOn) let sourceProvider = DefaultAutofillSourceProvider(privacyConfigurationManager: privacyConfig, properties: properties, isDebug: false) diff --git a/Tests/BrowserServicesKitTests/ContentScopeScriptTests/ContentScopePropertiesTests.swift b/Tests/BrowserServicesKitTests/ContentScopeScriptTests/ContentScopePropertiesTests.swift index 234a45ecc..bd63155c6 100644 --- a/Tests/BrowserServicesKitTests/ContentScopeScriptTests/ContentScopePropertiesTests.swift +++ b/Tests/BrowserServicesKitTests/ContentScopeScriptTests/ContentScopePropertiesTests.swift @@ -22,7 +22,7 @@ import WebKit class ContentScopePropertiesTests: XCTestCase { func testContentScopePropertiesInitializeCorrectly() { - let properties = ContentScopeProperties(gpcEnabled: true, sessionKey: "123456", featureToggles: ContentScopeFeatureToggles.allTogglesOn) + let properties = ContentScopeProperties(gpcEnabled: true, sessionKey: "123456", messageSecret: "123456", featureToggles: ContentScopeFeatureToggles.allTogglesOn) // ensure the properties can be encoded to valid JSON XCTAssertNotNil(try? JSONEncoder().encode(properties)) diff --git a/Tests/BrowserServicesKitTests/Email/EmailManagerTests.swift b/Tests/BrowserServicesKitTests/Email/EmailManagerTests.swift index 0ec6c1934..ee9e6e3ca 100644 --- a/Tests/BrowserServicesKitTests/Email/EmailManagerTests.swift +++ b/Tests/BrowserServicesKitTests/Email/EmailManagerTests.swift @@ -49,6 +49,7 @@ class EmailManagerTests: XCTestCase { let sourceProvider = DefaultAutofillSourceProvider(privacyConfigurationManager: privacyConfigManager, properties: ContentScopeProperties(gpcEnabled: false, sessionKey: "1234", + messageSecret: "1234", featureToggles: ContentScopeFeatureToggles.allTogglesOn), isDebug: false) let userScript = AutofillUserScript(scriptSourceProvider: sourceProvider) diff --git a/Tests/BrowserServicesKitTests/Fingerprinting/FingerprintingReferenceTests.swift b/Tests/BrowserServicesKitTests/Fingerprinting/FingerprintingReferenceTests.swift index 68ce6e903..e908e471c 100644 --- a/Tests/BrowserServicesKitTests/Fingerprinting/FingerprintingReferenceTests.swift +++ b/Tests/BrowserServicesKitTests/Fingerprinting/FingerprintingReferenceTests.swift @@ -223,6 +223,7 @@ final class FingerprintingReferenceTests: XCTestCase { let contentScopeProperties = ContentScopeProperties(gpcEnabled: false, sessionKey: UUID().uuidString, + messageSecret: UUID().uuidString, featureToggles: configFeatureToggle) let contentScopeScript = ContentScopeUserScript(self.privacyManager, diff --git a/Tests/BrowserServicesKitTests/GPC/GPCReferenceTests.swift b/Tests/BrowserServicesKitTests/GPC/GPCReferenceTests.swift index afc346069..b70afbca3 100644 --- a/Tests/BrowserServicesKitTests/GPC/GPCReferenceTests.swift +++ b/Tests/BrowserServicesKitTests/GPC/GPCReferenceTests.swift @@ -171,6 +171,7 @@ final class GPCReferenceTests: XCTestCase { let properties = ContentScopeProperties(gpcEnabled: gpcEnabled, sessionKey: UUID().uuidString, + messageSecret: UUID().uuidString, featureToggles: ContentScopeFeatureToggles.allTogglesOn) let contentScopeScript = ContentScopeUserScript(privacyManager, diff --git a/Tests/BrowserServicesKitTests/SecureVault/SecureVaultManagerTests.swift b/Tests/BrowserServicesKitTests/SecureVault/SecureVaultManagerTests.swift index b4b910998..71e65449a 100644 --- a/Tests/BrowserServicesKitTests/SecureVault/SecureVaultManagerTests.swift +++ b/Tests/BrowserServicesKitTests/SecureVault/SecureVaultManagerTests.swift @@ -45,7 +45,7 @@ class SecureVaultManagerTests: XCTestCase { } """.data(using: .utf8)! let privacyConfig = AutofillTestHelper.preparePrivacyConfig(embeddedConfig: embeddedConfig) - let properties = ContentScopeProperties(gpcEnabled: false, sessionKey: "1234", featureToggles: ContentScopeFeatureToggles.allTogglesOn) + let properties = ContentScopeProperties(gpcEnabled: false, sessionKey: "1234", messageSecret: "1234", featureToggles: ContentScopeFeatureToggles.allTogglesOn) let sourceProvider = DefaultAutofillSourceProvider(privacyConfigurationManager: privacyConfig, properties: properties, isDebug: false)