Repository navigation
fix(websockets): bracket IPv6 hosts in the iOS handshake - #27
Merged
Merged
Conversation
|
View your CI Pipeline Execution ↗ for commit ad54234
💡 With Ultracache enabled, Nx Cloud learns each task's file inputs in CI and uses them on later runs. Turn on Ultracache in workspace settings ↗ · Read docs ↗ ☁️ Nx Cloud last updated this comment at |
RCTSRWebSocket built the default Host and Origin headers from NSURL.host, which returns IPv6 literals without brackets. ws://[::1]:9897 sent "Host: ::1:9897" and "Origin: http://::1:9897", so servers that validate Host (e.g. Vite's dev server) rejected the upgrade. Add an RCTSR_hostForHeader helper on the private NSURL category that brackets a host containing ':' unless it already starts with '[', and use it for Host and Origin. The socket connection keeps using the raw host. Regenerate NativeScriptWebSockets.xcframework with native-src/ios/build.sh under Xcode 16.4 (iOS SDK 18.5, visionOS SDK 2.5), the toolchain of the previous artifact, so slices, architectures and deployment targets are unchanged.
edusperoni
force-pushed
the
fix/websockets-ipv6-host
branch
from
November 20, 2026 19:37
66d0186 to
3cc96fa
Compare
The Xcode project set no XROS_DEPLOYMENT_TARGET, so the visionOS slices took the building Xcode's SDK version as their minimum (2.5 with Xcode 16.4, 26.2 with Xcode 26.3). Set it to 1.0 in the project-level Debug and Release configurations, next to IPHONEOS_DEPLOYMENT_TARGET. Rebuilt the xcframework with native-src/ios/build.sh under Xcode 16.4. Only the xros-arm64 and xros-arm64-simulator slices change (minos 2.5 -> 1.0); the iOS and Mac Catalyst binaries are byte-identical.
4 of 5 tasks
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.
Symptom
On iOS, opening a
WebSocketto an IPv6-literal URL such asws://[fd7d:b219:4d03::2]:5173/sends a handshake whoseHostandOriginheaders have no brackets around the address:RFC 3986 §3.2.2 and RFC 7230 §5.4 require IPv6 literals to be bracketed there. Servers that validate
Hostreject the upgrade, so the connection never opens. Vite's dev server host check is one example. This was seen on physical iOS 26 devices that reach a dev server over the CoreDevice USB tunnel, which uses an IPv6 ULA.Root cause
The vendored SocketRocket fork,
RCTSRWebSocket, builds both default headers fromNSURL.host. For an IPv6 literal,NSURL.hostreturns the address without its brackets.Host:native-src/ios/NativeScriptWebSockets/RCTSRWebSocket.m,-didConnect(was line 452:[NSString stringWithFormat:@"%@:%@", _url.host, _url.port])Origin:-[NSURL RCTSR_origin]in the same file (was lines 1573-1575:@"%@://%@:%d", scheme, self.host, port)Fix
The fix is in the native code. A new
RCTSR_hostForHeaderproperty on the file-privateNSURL (RCTSRWebSocket)category returnsNSURL.hostwrapped in brackets when the host contains:and does not already start with[. Otherwise it returns the host unchanged.HostandOriginboth use it.Hostkeeps an explicit port.Origindrops the scheme's default port.CFStreamCreatePairWithSocketToHostin_initializeStreamsstill gets the raw, unbracketed host. The fork sets no explicit TLS peer name, so TLS uses that same raw host.Originstill wins.native-srcformats the host into a URL or header. There is no proxy orCONNECTpath in the fork.bridge.ios.tsoverrides, ahandshake-headers.tshelper, and a Jest target) has been removed.Zone-scoped literals such as
fe80::1%en0are bracketed asNSURL.hostreturns them. The zone is not re-encoded as%25.Regenerated xcframework
platforms/ios/NativeScriptWebSockets.xcframeworkwas rebuilt with the package's own script,native-src/ios/build.sh(thebuild.nativetarget), usingDEVELOPER_DIR=/Applications/Xcode-16.4.0.appon macOS 15.8.3.lipo -infoandvtool -show-buildoutput (architectures, platform, minos, sdk) is identical before and after. The visionOS minos then changes in the follow-up commit; see the next section.BuildMachineOSBuildin the per-sliceInfo.plists and a reordering of the library entries in the top-levelInfo.plist.visionOS deployment target
The Xcode project set
IPHONEOS_DEPLOYMENT_TARGET = 9.0but noXROS_DEPLOYMENT_TARGET. The visionOS slices therefore took the building Xcode's visionOS SDK version as their minimum: 2.5 with Xcode 16.4, or 26.2 with Xcode 26.3. A second commit setsXROS_DEPLOYMENT_TARGET = 1.0in the project-level Debug and Release configurations, next to the iOS setting.Why 1.0:
MinimumDeploymentTargetinSDKSettings.json)..visionOS(.v1)), so the plugin never raises the bar above the runtime. The runtime's libffi build targets 2.0, and the shipped@nativescript/visionos9.0.1 binaries currently carry minos 26.0, because the runtime also leaves its own target unset.CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE.minosper slice (fromotool -l):LC_VERSION_MIN_IPHONEOS)Toolchain: I built with
native-src/ios/build.shunder the machine's default Xcode 26.3. That build gave visionOS minos 1.0, which shows the setting makes the result independent of the Xcode version. It also moved every iOS and Catalyst slice to SDK 26.2 and changed their binaries, although their minos stayed the same. The committed framework is therefore the Xcode 16.4 build (DEVELOPER_DIR=/Applications/Xcode-16.4.0.app/Contents/Developer, iOS SDK 18.5, visionOS SDK 2.5). Only the two xros slices and their dSYMs differ from the previous commit.I re-ran the iOS 26.3 simulator smoke test with the committed framework (same
dwarfdump --uuid).ws://[::1]:9897sentHost: [::1]:9897andOrigin: http://[::1]:9897, got101, and firedonopen. I did not run a visionOS launch, because the demo app has no visionOS runtime dependency or config. The xros dSYM UUIDs match their binaries. The xros relocation maps are now populated like the iOS ones (previously empty).Verification
I ran a raw TCP server bound to
[::]:9897. It logs the request head and answers101only whenHostis a bracketed IPv6 literal. The demo app ran four probes in sequence. On iOS, the built.appembedded the rebuilt simulator slice (samedwarfdump --uuid).HostsentOriginsentws://[::1]:9897::1:9897http://::1:9897onerrorws://[::1]:9897[::1]:9897http://[::1]:9897onopenws://127.0.0.1:9897127.0.0.1:9897http://127.0.0.1:9897ws://localhost:9897localhost:9897http://localhost:9897ws://[::1]:9897+headers.origin[::1]:9897http://custom.exampleonopenws://[::1]:9897[::1]:9897http://[::1]:9897onopenws://127.0.0.1:9897127.0.0.1:9897http://127.0.0.1:9897ws://localhost:9897localhost:9897http://localhost:9897ws://[::1]:9897+headers.origin[::1]:9897http://custom.exampleonopenThe iOS "before" row comes from the earlier run of this PR on the same simulator against the same server, using the previously committed framework.
Every request carried exactly one
Hostline and oneOriginline.Android already handles IPv6 literals correctly, so it needs no change. OkHttp 4.9.3 brackets the
Hostheader, and the plugin's defaultOrigincomes fromjava.net.URI.getHost(), which keeps the brackets. On the emulator,adb reverse tcp:9897 tcp:9897listens on the device's[::]:9897. Sows://[::1]:9897went over the device's IPv6 loopback, and the headers above are what the app sent.Also ran:
nx run nativescript-websockets:lint: no errors. The 4 warnings were already there.nx run nativescript-websockets:build --exclude-task-dependencies: passes.distcarries the rebuilt framework.