Repository navigation
iOS: retain the sign-in sheet's callback URL in CN1OidcBrowser.m - #6370
Merged
Merged
Conversation
CN1OidcBrowser.m was written for ARC, but the port compiles with CLANG_ENABLE_OBJC_ARC = NO. ASWebAuthenticationSession's completion handler stored [callbackURL absoluteString] -- autoreleased into the main thread's pool -- in a __block variable and signalled the waiting thread, which then called fromNSString on it after the pool had drained. That use-after-free raised EXC_BAD_ACCESS, which ParparVM's signal handler surfaces as a NullPointerException with no message, so SystemBrowser.authenticate and OidcClient.authorize failed on device after the person approved, with OidcException transport_error "Native sign-in sheet failed: null". Under manual reference counting: - the callback string is copied and the error retained on the main thread, and both are released by the waiting thread once it has read them; - the session and its presentation context, held at +1 from -alloc, are autoreleased when the flow clears them (inside the session's own completion handler, so the session outlives the handler's return) instead of being leaked. Found in a TestFlight build of an app that signs in with OidcClient: every sign-in failed with that transport_error until the generated project was patched the same way.
Contributor
✅ Continuous Quality ReportTest & Coverage
Static Analysis
Generated automatically by the PR CI workflow. |
The iOS native-source lint compiles with -fobjc-arc, where explicit retain/release/autorelease are errors. Guard them with __has_feature(objc_arc), so the file is correct both in the product build (ARC off) and under ARC. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SZMcbmatyXu26VSMeHqWHJ
shai-almog
marked this pull request as ready for review
December 1, 2026 16:26
shai-almog
approved these changes
Dec 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SystemBrowser.authenticate/OidcClient.authorizefail on an iOS device after the person approves, with:Cause:
Ports/iOSPort/nativeSources/CN1OidcBrowser.mwas written for ARC (its own comment talks about ARC keeping the session), but the port compiles with ARC off (CLANG_ENABLE_OBJC_ARC = NOinvm/ByteCodeTranslator/src/template; the rest of the port's natives callretain/releaseexplicitly).ASWebAuthenticationSession's completion handler stores[callbackURL absoluteString], autoreleased into the main thread's pool, in a__blockvariable, then signals the waiting thread.fromNSString(result). The resulting use-after-free raisesEXC_BAD_ACCESS.NullPointerExceptionwith no message.SystemBrowserwraps it astransport_error.Fix: make the file correct under manual reference counting.
-allocin the static slots. They're now autoreleased when the flow clears them, inside the session's own completion handler, so the session outlives the handler's return. Before, they were set toniland leaked.Testing
OidcClient(Codename One 7.0.267, iOS 27, TestFlight): every sign-in failed with the error above.CN1OidcBrowser.mhad only theresult = [[callbackURL absoluteString] copy];change signed in successfully.scripts/pre-push-gates.shpasses.BackendAuthTestBasedeliberately skips the system browser step, so nothing in CI reaches this native's completion handler.Possibly related
CN1WebAuthn.m,CN1Vision.m,CN1Bluetooth.m,CN1Language.m,CN1SmartHome.mandIOSNative.malso use__blockobject variables. I have not reviewed them. If any were written assuming ARC, they may hand an autoreleased object across threads the same way.Generated by Claude Code