Skip to content

πŸ”’ Fix unsafe nonisolated construct in MapKitPlugin - #27

Closed
esenmx wants to merge 3 commits into
masterfrom
fix/remove-unsafe-nonisolated-registrar-3499962934664309862
Closed

esenmx wants to merge 3 commits into
masterfrom
fix/remove-unsafe-nonisolated-registrar-3499962934664309862

Conversation

@esenmx

@esenmx esenmx commented Aug 22, 2026

Copy link
Copy Markdown
Owner

πŸ”’ Security Fix: Remove unsafe 'nonisolated(unsafe)' construct during plugin registration

🎯 What: Removed nonisolated(unsafe) binding of registrar in MapKitPlugin.register(with:).
⚠️ Risk: The use of nonisolated(unsafe) bypassed Swift 6 compiler concurrency and memory safety checks for a shared resource during plugin initialization, potentially allowing data races or unsafe concurrent access if initialization semantics changed.
πŸ›‘οΈ Solution: registrar is safely passed and captured directly within MainActor.assumeIsolated { ... } without disabling compiler safety checks.


PR created automatically by Jules for task 3499962934664309862 started by @esenmx

Remove nonisolated(unsafe) opt-out for plugin registrar, ensuring
registration occurs strictly within MainActor isolation.

Co-authored-by: esenmx <43244505+esenmx@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

πŸ‘‹ Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a πŸ‘€ emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

google-labs-jules Bot and others added 2 commits August 22, 2026 14:35
Fix Swift 6 data race compiler error and remove nonisolated(unsafe)
opt-out by ensuring register(with:) inherits @mainactor isolation from
MapKitPlugin without assumeIsolated boundary crossing.

Co-authored-by: esenmx <43244505+esenmx@users.noreply.github.com>
Use @preconcurrency FlutterPlugin protocol conformance so register(with:)
inherits @mainactor isolation cleanly without nonisolated(unsafe) or
MainActor.assumeIsolated.

Co-authored-by: esenmx <43244505+esenmx@users.noreply.github.com>
@esenmx

esenmx commented Aug 23, 2026

Copy link
Copy Markdown
Owner Author

Closing: this change breaks every macOS consumer. Flutter's generated macos/Flutter/GeneratedPluginRegistrant.swift calls MapKitPlugin.register(with:) from a nonisolated global function compiled in Swift 5 mode, so making register main-actor-isolated fails with error: call to main actor-isolated static method 'register(with:)' in a synchronous nonisolated context (reproduced with flutter build macos --debug on Xcode 26.6 / Flutter 3.44.9 stable; base ba7857d builds green). CI passed only because it builds the iOS example, whose registrant is Objective-C and performs no Swift isolation checking.

The nonisolated(unsafe) binding is not a security issue: it rebinds a local non-Sendable reference that is consumed synchronously inside MainActor.assumeIsolated, which asserts main-thread at runtime. There is no shared mutable state or concurrent access; the existing comment and commit 6c298e3 document why Xcode 26 requires it.

There is no alternative shape to request: the plain deletion (this branch's first commit 71f2bb5) fails with MapKitPlugin.swift:19:27: error: sending 'registrar' risks causing data races, and a sending FlutterPluginRegistrar parameter cannot witness the FlutterPlugin requirement. The base design is forced by Flutter's macOS Swift registrant. (Separately, we will add a macOS build job to CI so this class of change is caught before review.)

@esenmx esenmx closed this Aug 23, 2026
@google-labs-jules

Copy link
Copy Markdown
Contributor

Closing: this change breaks every macOS consumer. Flutter's generated macos/Flutter/GeneratedPluginRegistrant.swift calls MapKitPlugin.register(with:) from a nonisolated global function compiled in Swift 5 mode, so making register main-actor-isolated fails with error: call to main actor-isolated static method 'register(with:)' in a synchronous nonisolated context (reproduced with flutter build macos --debug on Xcode 26.6 / Flutter 3.44.9 stable; base ba7857d builds green). CI passed only because it builds the iOS example, whose registrant is Objective-C and performs no Swift isolation checking.

The nonisolated(unsafe) binding is not a security issue: it rebinds a local non-Sendable reference that is consumed synchronously inside MainActor.assumeIsolated, which asserts main-thread at runtime. There is no shared mutable state or concurrent access; the existing comment and commit 6c298e3 document why Xcode 26 requires it.

There is no alternative shape to request: the plain deletion (this branch's first commit 71f2bb5) fails with MapKitPlugin.swift:19:27: error: sending 'registrar' risks causing data races, and a sending FlutterPluginRegistrar parameter cannot witness the FlutterPlugin requirement. The base design is forced by Flutter's macOS Swift registrant. (Separately, we will add a macOS build job to CI so this class of change is caught before review.)

Understood. Thank you for the detailed explanation regarding macOS GeneratedPluginRegistrant.swift behavior and the runtime guarantees of MainActor.assumeIsolated. Acknowledging and stopping work on this task.

@esenmx
esenmx deleted the fix/remove-unsafe-nonisolated-registrar-3499962934664309862 branch October 3, 2026 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant