-
Notifications
You must be signed in to change notification settings - Fork 423
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
support local storage fireproofing #3612
Merged
brindy
merged 18 commits into
release/7.148.0
from
brindy/support-local-storage-fireproofing
Dec 3, 2024
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
1e73bca
initial refactoring and migration code
brindy fcbdf72
migration logic and refactoring
brindy f80bf7b
update unit tests
brindy c52d9a5
swiftlint
brindy 1f9458e
re-use macos implementation
brindy 327a12f
added tests but need an abstraction for the data store container
brindy 1660429
Merge branch 'main' into brindy/support-local-storage-fireproofing
brindy 7ec9cde
abstract datastore removal to make it testable
brindy 5de2087
mock the observations data
brindy 7ea99d1
re-use domain cookie matching code to fix long-standing bug
brindy 62d96a0
merge main
brindy 4d88a1e
merge main
brindy b3e58e1
containers need to be removed on the main actor
brindy 0454552
remove print statements
brindy f54fb19
update maestro and add local storage test
brindy 5874ffd
Merge branch 'main' into brindy/support-local-storage-fireproofing
brindy 42b7063
address feedback comments
brindy ffe3448
fix api in mock
brindy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# local-storage.yaml | ||
appId: com.duckduckgo.mobile.ios | ||
tags: | ||
- release | ||
|
||
--- | ||
|
||
# Set up | ||
- runFlow: | ||
file: ../shared/setup.yaml | ||
|
||
# Load Site | ||
- assertVisible: | ||
id: "searchEntry" | ||
- tapOn: | ||
id: "searchEntry" | ||
- inputText: "https://privacy-test-pages.site/features/local-storage.html" | ||
- pressKey: Enter | ||
|
||
# Add a cookie | ||
- assertVisible: "Storage Counter: undefined" | ||
- assertVisible: "Cookie Counter:" | ||
- assertNotVisible: "Cookie Counter: 1" | ||
- assertNotVisible: "Storage Counter: 1" | ||
- assertVisible: "Manual Increment" | ||
- tapOn: "Manual Increment" | ||
- tapOn: "Manual Increment" | ||
- assertVisible: "Cookie Counter: 2" | ||
- assertVisible: "Storage Counter: 2" | ||
|
||
# Fireproofing | ||
- tapOn: "Browsing menu" | ||
- tapOn: "Fireproof This Site" | ||
- tapOn: "Fireproof" | ||
|
||
# Fire button | ||
- tapOn: "Close Tabs and Clear Data" | ||
- tapOn: "Close Tabs and Clear Data" | ||
|
||
- assertNotVisible: "https://privacy-test-pages.site/features/local-storage.html" | ||
|
||
# Load Site | ||
- assertVisible: | ||
id: "searchEntry" | ||
- tapOn: | ||
id: "searchEntry" | ||
|
||
- inputText: "https://privacy-test-pages.site/features/local-storage.html" | ||
- pressKey: Enter | ||
- assertVisible: "Storage Counter: 2" | ||
- assertVisible: "Cookie Counter: 2" | ||
|
||
# Remove Fireproofing | ||
- tapOn: "Browsing menu" | ||
- tapOn: "Remove Fireproofing" | ||
|
||
# Fire button | ||
- tapOn: "Close Tabs and Clear Data" | ||
- tapOn: "Close Tabs and Clear Data" | ||
|
||
- assertNotVisible: "https://privacy-test-pages.site/features/local-storage.html" | ||
|
||
# Load Site | ||
- assertVisible: | ||
id: "searchEntry" | ||
- tapOn: | ||
id: "searchEntry" | ||
|
||
- inputText: "https://privacy-test-pages.site/features/local-storage.html" | ||
- pressKey: Enter | ||
- assertVisible: "Storage Counter: undefined" | ||
- assertVisible: "Cookie Counter:" |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// DataStoreIDManager.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 WebKit | ||
import Persistence | ||
|
||
/// Supports an existing ID set in previous versions of the app, but moving forward does not allocate an ID. We have gone back to using the default | ||
/// peristence for the webview storage so that we can fireproof types that don't have an API for accessing their data. (e.g. localStorage) | ||
public protocol DataStoreIDManaging { | ||
|
||
var currentID: UUID? { get } | ||
|
||
func invalidateCurrentID() | ||
} | ||
|
||
public class DataStoreIDManager: DataStoreIDManaging { | ||
|
||
enum Constants: String { | ||
case currentWebContainerID = "com.duckduckgo.ios.webcontainer.id" | ||
} | ||
|
||
public static let shared = DataStoreIDManager() | ||
|
||
private let store: KeyValueStoring | ||
init(store: KeyValueStoring = UserDefaults.app) { | ||
self.store = store | ||
} | ||
|
||
public var currentID: UUID? { | ||
guard let uuidString = store.object(forKey: Constants.currentWebContainerID.rawValue) as? String else { | ||
return nil | ||
} | ||
return UUID(uuidString: uuidString) | ||
} | ||
|
||
public func invalidateCurrentID() { | ||
store.removeObject(forKey: Constants.currentWebContainerID.rawValue) | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// HTTPCookieExtension.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 WebKit | ||
|
||
extension HTTPCookie { | ||
|
||
/// Checks that the `cookieDomain` (provided by a cookie) matches a given domain. e.g. | ||
/// * cookie domain example.com would match a domain called example.com | ||
/// * cookie domain `.example.com` would also match a domain called example.com and also any subdomain, e.g. `docs.example.com` | ||
/// | ||
/// See `UserDefaultsFireproofingTests` for more examples. | ||
static func cookieDomain(_ cookieDomain: String, matchesTestDomain testDomain: String) -> Bool { | ||
return testDomain == cookieDomain | ||
|| ".\(testDomain)" == cookieDomain | ||
|| (cookieDomain.hasPrefix(".") && testDomain.hasSuffix(cookieDomain)) | ||
} | ||
|
||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you provide a piece of documentation what do we test here for and possible e.g of what matches means for us
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added comment and note to look at some unit tests