[SwiftUI macOS] SecureField within an Alert is not obscured

Description

I am working on a SwiftUI macOS application that has a 2FA prompt inside an alert, with SecureFields for the user to input their password and 2FA code.

The SecureFields in the alert function fine as TextFields but are not obscured ('password' -> '********'), which raises a major security risk. I have tested the exact same code on iOS and the SecureFields are obscured as intended (see below screenshots).

I believe this is a bug in macOS Ventura, I have tried updating to the 13.1 beta 3 and beta 4 but neither build fixes the issue. Any ideas on what to do here?


Example Code:

struct ContentView: View {
    @State private var alertShown: Bool = true
    @State private var username: String = ""
    @State private var password: String = ""
    
    var body: some View {
        VStack {
            Image(systemName: "globe")
                .imageScale(.large)
                .foregroundColor(.accentColor)
            Text("Hello, world!")
        }
        .padding()
        .alert("Sign In",
               isPresented: $alertShown,
               actions: {
                    TextField("Username", text: $username)
                    SecureField("Password", text: $password)
                    Button("Submit", action: {
                        print("Username: \(username), Password: \(password)")
                    })
                })
    }
}

Compiled for macOS:

Compiled for iOS:

Post not yet marked as solved Up vote post of b521i9s Down vote post of b521i9s
534 views

Replies

Thank you for the report! Can you please turn this into a Feedback and post the number here? https://feedbackassistant.apple.com