Skip to content

Commit

Permalink
Update protections update script and data
Browse files Browse the repository at this point in the history
  • Loading branch information
mallexxx committed Nov 28, 2024
1 parent 6f29625 commit 87fd08c
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15223,7 +15223,7 @@
repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit";
requirement = {
kind = revision;
revision = 620ce5bbf41b0f41ea54b5dd4c9c1dafb7bf3b89;
revision = 6def39a7ba44240ee634805a1a163ee317c279d2;
};
};
9FF521422BAA8FF300B9819B /* XCRemoteSwiftPackageReference "lottie-spm" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ extension MaliciousSiteProtectionManager {

private enum Constants {
static let embeddedDataRevision = 1692083
static let phishingEmbeddedHashPrefixDataSHA = "b423fa3cf21d82a8f537ae3c817c7aa5338603401c77a6ed7094f0b20af30055"
static let phishingEmbeddedFilterSetDataSHA = "6633f7a2e521071485128c6bf3b84ce2a2dc7bd09750fed7b0300913ed8bfa96"
static let malwareEmbeddedHashPrefixDataSHA = "b423fa3cf21d82a8f537ae3c817c7aa5338603401c77a6ed7094f0b20af30055"
static let malwareEmbeddedFilterSetDataSHA = "6633f7a2e521071485128c6bf3b84ce2a2dc7bd09750fed7b0300913ed8bfa96"
static let phishingEmbeddedHashPrefixDataSHA = "86e9b69a6224e22755408f8ec1d13354ca8d59048f11d0728d9c664602500e8e"
static let phishingEmbeddedFilterSetDataSHA = "6c29956071ef76d83a65c6c34646f361e9d6b5007b7251f0c5473428486aa9ee"
static let malwareEmbeddedHashPrefixDataSHA = "07c4f1bd44881974f53e07f67090bac60770378fb8f68d45bbf8451f6545b423"
static let malwareEmbeddedFilterSetDataSHA = "37517e5f3dc66819f61f5a7bb8ace1921282415f10551d2defa5c3eb0985b570"
}

func revision(for dataType: MaliciousSiteProtection.DataManager.StoredDataType) -> Int {
Expand Down Expand Up @@ -92,7 +92,7 @@ public class MaliciousSiteProtectionManager: MaliciousSiteDetecting {

init(
fileStoreUrl: URL? = nil,
apiClient: MaliciousSiteProtection.APIClientProtocol = MaliciousSiteProtection.APIClient(environment: .dev),
apiClient: MaliciousSiteProtection.APIClientProtocol = .production,
embeddedDataProvider: MaliciousSiteProtection.EmbeddedDataProviding? = nil,
dataManager: MaliciousSiteProtection.DataManaging? = nil,
detector: MaliciousSiteProtection.MaliciousSiteDetecting? = nil,
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/MaliciousSiteProtection/malwareFilterSet.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion DuckDuckGo/MaliciousSiteProtection/phishingFilterSet.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ extension ErrorPageTabExtensionNavigationDelegate {
func reloadPage() -> WKNavigation? {
guard let wevView = self as? WKWebView else { return nil }
if let item = wevView.backForwardList.currentItem {
return wevView.go(to: item) // TODO: Doesn‘t work for phishing
return wevView.go(to: item)
}
return nil
}
Expand Down
18 changes: 14 additions & 4 deletions scripts/update_phishing_detection_data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fi
temp_filename="phishing_data_new_file"
new_revision=$(curl -s "${API_URL}/revision" | jq -r '.revision')

printf "Embedded revision: %s, actual revision: %s\n" "${old_revision}" "${new_revision}"
printf "Embedded revision: %s, actual revision: %s\n\n" "${old_revision}" "${new_revision}"
rm -f "$temp_filename"

performUpdate() {
Expand All @@ -35,17 +35,27 @@ performUpdate() {

printf "Embedded SHA256: %s\n" "${old_sha}"

curl -o "$temp_filename" -s "${API_URL}/${data_type}"
url="${API_URL}/${data_type}?category=${threat_type}"
printf "Fetching %s\n" "${url}"
curl -o "$temp_filename" -s "${url}"
jq -rc '.insert' "$temp_filename" > "$data_path"

new_sha="$(shasum -a 256 "$data_path" | awk -F ' ' '{print $1}')"

printf "New SHA256: %s\n" "$new_sha"
if [ "$new_sha" == "$old_sha" ]; then
printf "🆗 Data not modified.\n"
else
printf "New SHA256: %s ✨\n" "$new_sha"
fi

sed -i '' -e "s/$old_sha/$new_sha/g" "${def_filename}"
sed -i '' -e "s/${threat_type}EmbeddedDataRevision =.*/${threat_type}EmbeddedDataRevision = $new_revision/" "${def_filename}"

printf "${threat_type}Embedded${capitalized_data_type}DataSHA updated\n\n"
if [ "$new_sha" == "$old_sha" ]; then
printf "\n"
else
printf "${threat_type}Embedded${capitalized_data_type}DataSHA updated\n\n"
fi
rm -f "$temp_filename"
}

Expand Down

0 comments on commit 87fd08c

Please sign in to comment.