From 284e20a2905e694722b0e2b79107b8a19752ce51 Mon Sep 17 00:00:00 2001 From: stffabi Date: Thu, 5 Jan 2023 14:06:26 +0100 Subject: [PATCH] Add EnableFraudulentWebsiteDetection to options (#2269) This allows to explicitly opt-in to scan services for fraudulent content, such as malware or phishing attempts. --- v2/internal/frontend/desktop/darwin/Application.h | 2 +- v2/internal/frontend/desktop/darwin/Application.m | 4 ++-- v2/internal/frontend/desktop/darwin/WailsContext.h | 2 +- v2/internal/frontend/desktop/darwin/WailsContext.m | 8 ++++++-- v2/internal/frontend/desktop/darwin/main.m | 2 +- v2/internal/frontend/desktop/darwin/window.go | 4 +++- v2/internal/frontend/desktop/windows/frontend.go | 10 ++++++++++ v2/pkg/options/options.go | 7 ++++++- website/docs/reference/options.mdx | 10 ++++++++++ website/src/pages/changelog.mdx | 1 + 10 files changed, 41 insertions(+), 9 deletions(-) diff --git a/v2/internal/frontend/desktop/darwin/Application.h b/v2/internal/frontend/desktop/darwin/Application.h index 6c4710a06..2432e8906 100644 --- a/v2/internal/frontend/desktop/darwin/Application.h +++ b/v2/internal/frontend/desktop/darwin/Application.h @@ -17,7 +17,7 @@ #define WindowStartsMinimised 2 #define WindowStartsFullscreen 3 -WailsContext* Create(const char* title, int width, int height, int frameless, int resizable, int fullscreen, int fullSizeContent, int hideTitleBar, int titlebarAppearsTransparent, int hideTitle, int useToolbar, int hideToolbarSeparator, int webviewIsTransparent, int alwaysOnTop, int hideWindowOnClose, const char *appearance, int windowIsTranslucent, int debug, int windowStartState, int startsHidden, int minWidth, int minHeight, int maxWidth, int maxHeight); +WailsContext* Create(const char* title, int width, int height, int frameless, int resizable, int fullscreen, int fullSizeContent, int hideTitleBar, int titlebarAppearsTransparent, int hideTitle, int useToolbar, int hideToolbarSeparator, int webviewIsTransparent, int alwaysOnTop, int hideWindowOnClose, const char *appearance, int windowIsTranslucent, int debug, int windowStartState, int startsHidden, int minWidth, int minHeight, int maxWidth, int maxHeight, bool fraudulentWebsiteWarningEnabled); void Run(void*, const char* url); void SetTitle(void* ctx, const char *title); diff --git a/v2/internal/frontend/desktop/darwin/Application.m b/v2/internal/frontend/desktop/darwin/Application.m index f655490d4..9b4fe502b 100644 --- a/v2/internal/frontend/desktop/darwin/Application.m +++ b/v2/internal/frontend/desktop/darwin/Application.m @@ -13,7 +13,7 @@ #import "WailsMenu.h" #import "WailsMenuItem.h" -WailsContext* Create(const char* title, int width, int height, int frameless, int resizable, int fullscreen, int fullSizeContent, int hideTitleBar, int titlebarAppearsTransparent, int hideTitle, int useToolbar, int hideToolbarSeparator, int webviewIsTransparent, int alwaysOnTop, int hideWindowOnClose, const char *appearance, int windowIsTranslucent, int debug, int windowStartState, int startsHidden, int minWidth, int minHeight, int maxWidth, int maxHeight) { +WailsContext* Create(const char* title, int width, int height, int frameless, int resizable, int fullscreen, int fullSizeContent, int hideTitleBar, int titlebarAppearsTransparent, int hideTitle, int useToolbar, int hideToolbarSeparator, int webviewIsTransparent, int alwaysOnTop, int hideWindowOnClose, const char *appearance, int windowIsTranslucent, int debug, int windowStartState, int startsHidden, int minWidth, int minHeight, int maxWidth, int maxHeight, bool fraudulentWebsiteWarningEnabled) { [NSApplication sharedApplication]; @@ -25,7 +25,7 @@ WailsContext* Create(const char* title, int width, int height, int frameless, in fullscreen = 1; } - [result CreateWindow:width :height :frameless :resizable :fullscreen :fullSizeContent :hideTitleBar :titlebarAppearsTransparent :hideTitle :useToolbar :hideToolbarSeparator :webviewIsTransparent :hideWindowOnClose :safeInit(appearance) :windowIsTranslucent :minWidth :minHeight :maxWidth :maxHeight]; + [result CreateWindow:width :height :frameless :resizable :fullscreen :fullSizeContent :hideTitleBar :titlebarAppearsTransparent :hideTitle :useToolbar :hideToolbarSeparator :webviewIsTransparent :hideWindowOnClose :safeInit(appearance) :windowIsTranslucent :minWidth :minHeight :maxWidth :maxHeight :fraudulentWebsiteWarningEnabled]; [result SetTitle:safeInit(title)]; [result Center]; diff --git a/v2/internal/frontend/desktop/darwin/WailsContext.h b/v2/internal/frontend/desktop/darwin/WailsContext.h index 0619bc63d..cd187744d 100644 --- a/v2/internal/frontend/desktop/darwin/WailsContext.h +++ b/v2/internal/frontend/desktop/darwin/WailsContext.h @@ -57,7 +57,7 @@ @property (retain) NSString* aboutTitle; @property (retain) NSString* aboutDescription; -- (void) CreateWindow:(int)width :(int)height :(bool)frameless :(bool)resizable :(bool)fullscreen :(bool)fullSizeContent :(bool)hideTitleBar :(bool)titlebarAppearsTransparent :(bool)hideTitle :(bool)useToolbar :(bool)hideToolbarSeparator :(bool)webviewIsTransparent :(bool)hideWindowOnClose :(NSString *)appearance :(bool)windowIsTranslucent :(int)minWidth :(int)minHeight :(int)maxWidth :(int)maxHeight; +- (void) CreateWindow:(int)width :(int)height :(bool)frameless :(bool)resizable :(bool)fullscreen :(bool)fullSizeContent :(bool)hideTitleBar :(bool)titlebarAppearsTransparent :(bool)hideTitle :(bool)useToolbar :(bool)hideToolbarSeparator :(bool)webviewIsTransparent :(bool)hideWindowOnClose :(NSString *)appearance :(bool)windowIsTranslucent :(int)minWidth :(int)minHeight :(int)maxWidth :(int)maxHeight :(bool)fraudulentWebsiteWarningEnabled; - (void) SetSize:(int)width :(int)height; - (void) SetPosition:(int)x :(int) y; - (void) SetMinSize:(int)minWidth :(int)minHeight; diff --git a/v2/internal/frontend/desktop/darwin/WailsContext.m b/v2/internal/frontend/desktop/darwin/WailsContext.m index 996dad62c..d01331623 100644 --- a/v2/internal/frontend/desktop/darwin/WailsContext.m +++ b/v2/internal/frontend/desktop/darwin/WailsContext.m @@ -137,7 +137,7 @@ typedef void (^schemeTaskCaller)(id); return NO; } -- (void) CreateWindow:(int)width :(int)height :(bool)frameless :(bool)resizable :(bool)fullscreen :(bool)fullSizeContent :(bool)hideTitleBar :(bool)titlebarAppearsTransparent :(bool)hideTitle :(bool)useToolbar :(bool)hideToolbarSeparator :(bool)webviewIsTransparent :(bool)hideWindowOnClose :(NSString*)appearance :(bool)windowIsTranslucent :(int)minWidth :(int)minHeight :(int)maxWidth :(int)maxHeight { +- (void) CreateWindow:(int)width :(int)height :(bool)frameless :(bool)resizable :(bool)fullscreen :(bool)fullSizeContent :(bool)hideTitleBar :(bool)titlebarAppearsTransparent :(bool)hideTitle :(bool)useToolbar :(bool)hideToolbarSeparator :(bool)webviewIsTransparent :(bool)hideWindowOnClose :(NSString*)appearance :(bool)windowIsTranslucent :(int)minWidth :(int)minHeight :(int)maxWidth :(int)maxHeight :(bool)fraudulentWebsiteWarningEnabled { self.urlRequestsId = 0; self.urlRequests = [NSMutableDictionary new]; @@ -220,7 +220,11 @@ typedef void (^schemeTaskCaller)(id); [config setURLSchemeHandler:self forURLScheme:@"wails"]; // [config.preferences setValue:[NSNumber numberWithBool:true] forKey:@"developerExtrasEnabled"]; - + + if (@available(macOS 10.15, *)) { + config.preferences.fraudulentWebsiteWarningEnabled = fraudulentWebsiteWarningEnabled; + } + WKUserContentController* userContentController = [WKUserContentController new]; [userContentController addScriptMessageHandler:self name:@"external"]; config.userContentController = userContentController; diff --git a/v2/internal/frontend/desktop/darwin/main.m b/v2/internal/frontend/desktop/darwin/main.m index 5f4618d1b..d2f39bccb 100644 --- a/v2/internal/frontend/desktop/darwin/main.m +++ b/v2/internal/frontend/desktop/darwin/main.m @@ -219,7 +219,7 @@ int main(int argc, const char * argv[]) { int windowStartState = 0; int startsHidden = 0; WailsContext *result = Create("OI OI!",400,400, frameless, resizable, fullscreen, fullSizeContent, hideTitleBar, titlebarAppearsTransparent, hideTitle, useToolbar, hideToolbarSeparator, webviewIsTransparent, alwaysOnTop, hideWindowOnClose, appearance, windowIsTranslucent, debug, windowStartState, - startsHidden, 400, 400, 600, 600); + startsHidden, 400, 400, 600, 600, false); SetBackgroundColour(result, 255, 0, 0, 255); void *m = NewMenu(""); SetAbout(result, "Fake title", "I am a description", _Users_username_Pictures_SaltBae_png, _Users_username_Pictures_SaltBae_png_len); diff --git a/v2/internal/frontend/desktop/darwin/window.go b/v2/internal/frontend/desktop/darwin/window.go index 88d0e3aa9..8b4c77799 100644 --- a/v2/internal/frontend/desktop/darwin/window.go +++ b/v2/internal/frontend/desktop/darwin/window.go @@ -67,6 +67,8 @@ func NewWindow(frontendOptions *options.App, debugMode bool) *Window { title = c.String(frontendOptions.Title) + enableFraudulentWebsiteWarnings := C.bool(frontendOptions.EnableFraudulentWebsiteDetection) + if frontendOptions.Mac != nil { mac := frontendOptions.Mac if mac.TitleBar != nil { @@ -85,7 +87,7 @@ func NewWindow(frontendOptions *options.App, debugMode bool) *Window { var context *C.WailsContext = C.Create(title, width, height, frameless, resizable, fullscreen, fullSizeContent, hideTitleBar, titlebarAppearsTransparent, hideTitle, useToolbar, hideToolbarSeparator, webviewIsTransparent, alwaysOnTop, hideWindowOnClose, appearance, windowIsTranslucent, debug, windowStartState, startsHidden, - minWidth, minHeight, maxWidth, maxHeight) + minWidth, minHeight, maxWidth, maxHeight, enableFraudulentWebsiteWarnings) // Create menu result := &Window{ diff --git a/v2/internal/frontend/desktop/windows/frontend.go b/v2/internal/frontend/desktop/windows/frontend.go index 0b96b7d1a..34e26e1c2 100644 --- a/v2/internal/frontend/desktop/windows/frontend.go +++ b/v2/internal/frontend/desktop/windows/frontend.go @@ -409,6 +409,11 @@ func (f *Frontend) Quit() { func (f *Frontend) setupChromium() { chromium := f.chromium + disableFeatues := []string{} + if !f.frontendOptions.EnableFraudulentWebsiteDetection { + disableFeatues = append(disableFeatues, "msSmartScreenProtection") + } + if opts := f.frontendOptions.Windows; opts != nil { chromium.DataPath = opts.WebviewUserDataPath chromium.BrowserPath = opts.WebviewBrowserPath @@ -418,6 +423,11 @@ func (f *Frontend) setupChromium() { } } + if len(disableFeatues) > 0 { + arg := fmt.Sprintf("--disable-features=%s", strings.Join(disableFeatues, ",")) + chromium.AdditionalBrowserArgs = append(chromium.AdditionalBrowserArgs, arg) + } + chromium.MessageCallback = f.processMessage chromium.WebResourceRequestedCallback = f.processRequest chromium.NavigationCompletedCallback = f.navigationCompleted diff --git a/v2/pkg/options/options.go b/v2/pkg/options/options.go index 3f45c6b43..80c70296c 100644 --- a/v2/pkg/options/options.go +++ b/v2/pkg/options/options.go @@ -2,7 +2,6 @@ package options import ( "context" - "github.com/wailsapp/wails/v2/pkg/options/linux" "html" "io/fs" "log" @@ -10,6 +9,7 @@ import ( "runtime" "github.com/wailsapp/wails/v2/pkg/options/assetserver" + "github.com/wailsapp/wails/v2/pkg/options/linux" "github.com/wailsapp/wails/v2/pkg/options/mac" "github.com/wailsapp/wails/v2/pkg/options/windows" @@ -72,6 +72,11 @@ type App struct { // The CSS Value that the CSSDragProperty must have to be draggable, EG: "drag" CSSDragValue string + // EnableFraudulentWebsiteDetection enables scan services for fraudulent content, such as malware or phishing attempts. + // These services might send information from your app like URLs navigated to and possibly other content to cloud + // services of Apple and Microsoft. + EnableFraudulentWebsiteDetection bool + Windows *windows.Options Mac *mac.Options Linux *linux.Options diff --git a/website/docs/reference/options.mdx b/website/docs/reference/options.mdx index 72620d383..878512d25 100644 --- a/website/docs/reference/options.mdx +++ b/website/docs/reference/options.mdx @@ -51,6 +51,7 @@ func main() { OnBeforeClose: app.beforeClose, CSSDragProperty: "--wails-draggable", CSSDragValue: "drag", + EnableFraudulentWebsiteDetection: false, ZoomFactor: 1.0, IsZoomControlEnabled: false, Bind: []interface{}{ @@ -415,6 +416,15 @@ Indicates what value the `CSSDragProperty` style should have to drag the window. Name: CSSDragValue
Type: `string` +### EnableFraudulentWebsiteDetection + +EnableFraudulentWebsiteDetection enables scan services for fraudulent content, such as malware or phishing attempts. +These services might send information from your app like URLs navigated to and possibly other content to cloud +services of Apple and Microsoft. + +Name: EnableFraudulentWebsiteDetection
+Type: `bool` + ### ZoomFactor Name: ZoomFactor
diff --git a/website/src/pages/changelog.mdx b/website/src/pages/changelog.mdx index 3c06a7643..0322f636e 100644 --- a/website/src/pages/changelog.mdx +++ b/website/src/pages/changelog.mdx @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Added Webview GPU acceleration options for [Windows](/docs/reference/options#webviewgpuisdisabled) and [Linux](/docs/reference/options#webviewgpupolicy). Added by @Lyimmi in [PR](https://github.com/wailsapp/wails/pull/2266) +- Added `EnableFraudulentWebsiteDetection` option to opt-in to scan services for fraudulent content, such as malware or phishing attempts. Older releases had the scan services per default activated. Added by @stffabi in [PR](https://github.com/wailsapp/wails/pull/2269) ## v2.3.0 - 2022-12-29