tauri-apps / tao

The TAO of cross-platform windowing. A library in Rust built for Tauri.
Apache License 2.0
1.59k stars 188 forks source link

[bug] MacOS Secure Coding Warning #841

Closed tauri-bot closed 10 months ago

tauri-bot commented 11 months ago

This issue has been upstreamed from https://github.com/tauri-apps/tauri/issues/8185

Describe the bug

Since MacOS 14 (Sonoma) we're now receiving these error when running Tauri apps via CLI:

(Even when the MacOS binary has been properly signed and notarized by Apple)

WARNING: Secure coding is not enabled for restrable state! Enable secure coding by implementing 
NSApplicationDelegate.applicationSupportsSecureRestorableState: and returning YES

T

Reproduction

No response

Expected behavior

No response

Platform and versions

[✔] Environment
    - OS: Mac OS 14.0.0 X64
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.70.0 (90c541806 2023-05-31)
    ✔ cargo: 1.70.0 (ec8a8a0ca 2023-04-25)
    ✔ rustup: 1.26.0 (5af9b9484 2023-04-05)
    ✔ Rust toolchain: stable-aarch64-apple-darwin (default)
    - node: 18.14.0
    - yarn: 1.22.19
    - npm: 9.3.1

[-] Packages
    - tauri [RUST]: 1.5.2
    - tauri-build [RUST]: 1.5.0
    - wry [RUST]: 0.24.4
    - tao [RUST]: 0.16.5
    - @tauri-apps/api [NPM]: 1.5.1
    - @tauri-apps/cli [NPM]: 1.5.6

[-] App
    - build-type: bundle
    - CSP: unset
    - distDir: ../dist
    - devPath: http://localhost:1420/
    - framework: Svelte
    - bundler: Vite

Stack trace

No response

Additional context

No response

hjmallon commented 10 months ago
diff --git a/src/platform_impl/macos/app_delegate.rs b/src/platform_impl/macos/app_delegate.rs
index 8cb6c009..6beea942 100644
--- a/src/platform_impl/macos/app_delegate.rs
+++ b/src/platform_impl/macos/app_delegate.rs
@@ -8,7 +8,7 @@ use cocoa::base::id;
 use cocoa::foundation::NSString;
 use objc::{
   declare::ClassDecl,
-  runtime::{Class, Object, Sel},
+  runtime::{Class, Object, Sel, BOOL},
 };
 use std::{
   cell::{RefCell, RefMut},
@@ -54,6 +54,10 @@ lazy_static! {
       sel!(application:openURLs:),
       application_open_urls as extern "C" fn(&Object, Sel, id, id),
     );
+    decl.add_method(
+      sel!(applicationSupportsSecureRestorableState:),
+      application_supports_secure_restorable_state as extern "C" fn(&Object, Sel, id) -> BOOL,
+    );
     decl.add_ivar::<*mut c_void>(AUX_DELEGATE_STATE_NAME);

     AppDelegateClass(decl.register())
@@ -120,3 +124,9 @@ extern "C" fn application_open_urls(_: &Object, _: Sel, _: id, urls: id) -> () {
   AppState::open_urls(urls);
   trace!("Completed `application:openURLs:`");
 }
+
+extern "C" fn application_supports_secure_restorable_state(_: &Object, _: Sel, _: id) -> BOOL {
+  trace!("Triggered `applicationSupportsSecureRestorableState`");
+  trace!("Completed `applicationSupportsSecureRestorableState`");
+  objc::runtime::YES
+}

I dont have github signing set up so can't make a pull request at the moment, but does that fix it for you?