Skip to content

iOS: retain the sign-in sheet's callback URL in CN1OidcBrowser.m - #6370

Merged
shai-almog merged 2 commits into
masterfrom
claude/magical-ritchie-qwfp1s
Dec 1, 2026
Merged

shai-almog merged 2 commits into
masterfrom
claude/magical-ritchie-qwfp1s

Conversation

@shannah

@shannah shannah commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

SystemBrowser.authenticate / OidcClient.authorize fail on an iOS device after the person approves, with:

OidcException transport_error: Native sign-in sheet failed: null [NullPointerException]

Cause: Ports/iOSPort/nativeSources/CN1OidcBrowser.m was written for ARC (its own comment talks about ARC keeping the session), but the port compiles with ARC off (CLANG_ENABLE_OBJC_ARC = NO in vm/ByteCodeTranslator/src/template; the rest of the port's natives call retain/release explicitly).

  • ASWebAuthenticationSession's completion handler stores [callbackURL absoluteString], autoreleased into the main thread's pool, in a __block variable, then signals the waiting thread.
  • The pool drains before the waiting thread calls fromNSString(result). The resulting use-after-free raises EXC_BAD_ACCESS.
  • ParparVM's signal handler surfaces that as a NullPointerException with no message. SystemBrowser wraps it as transport_error.

Fix: make the file correct under manual reference counting.

  • Copy the callback string and retain the error on the main thread. The waiting thread releases both after reading them.
  • The session and its presentation context are held at +1 from -alloc in 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 to nil and leaked.

Testing

  • Found in a production app that signs in with OidcClient (Codename One 7.0.267, iOS 27, TestFlight): every sign-in failed with the error above.
  • A build whose generated CN1OidcBrowser.m had only the result = [[callbackURL absoluteString] copy]; change signed in successfully.
  • scripts/pre-push-gates.sh passes.
  • Not exercised by the device suites: BackendAuthTestBase deliberately 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.m and IOSNative.m also use __block object 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

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.
@shannah
shannah requested a review from shai-almog December 1, 2026 14:41
@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

✅ Continuous Quality Report

Test & Coverage

Static Analysis

  • SpotBugs [Report archive]
    • ✅ ByteCodeTranslator: 0 findings (no issues)
    • ✅ android: 0 findings (no issues)
    • ✅ android-compat: 0 findings (no issues)
    • ✅ android-res-compiler: 0 findings (no issues)
    • ✅ backend: 0 findings (no issues)
    • ✅ backend-test: 0 findings (no issues)
    • ✅ build-engine: 0 findings (no issues)
    • ✅ build-hint-catalog: 0 findings (no issues)
    • ✅ build-hint-tools: 0 findings (no issues)
    • ✅ code-model: 0 findings (no issues)
    • ✅ codenameone-gradle-plugin: 0 findings (no issues)
    • ✅ codenameone-maven-plugin: 0 findings (no issues)
    • ✅ compose-compat: 0 findings (no issues)
    • ✅ core-unittests: 0 findings (no issues)
    • ✅ design-import: 0 findings (no issues)
    • ✅ desktop-compat-runtime: 0 findings (no issues)
    • ✅ fxml-compiler: 0 findings (no issues)
    • ✅ ios: 0 findings (no issues)
    • ✅ javac: 0 findings (no issues)
    • ✅ javafx-compat: 0 findings (no issues)
    • ✅ project-model: 0 findings (no issues)
    • ✅ python-runtime: 0 findings (no issues)
    • ✅ python-transpiler: 0 findings (no issues)
    • ✅ rive-runtime: 0 findings (no issues)
    • ✅ swing-compat: 0 findings (no issues)
  • ✅ PMD: 0 findings (no issues) [Report archive]
  • ✅ Checkstyle: 0 findings (no issues) [Report archive]

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
shai-almog marked this pull request as ready for review December 1, 2026 16:26
@shai-almog
shai-almog merged commit 7d2efca into master Dec 1, 2026
32 of 33 checks passed
@shai-almog
shai-almog deleted the claude/magical-ritchie-qwfp1s branch December 1, 2026 16:34
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.

3 participants