Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS App Fails to Connect Remotely via Cloudflare Tunnel After Successful 2FA - NSCocoaErrorDomain 3840 #3511

Open
Elad-Hanania opened this issue Mar 28, 2025 · 4 comments
Assignees

Comments

@Elad-Hanania
Copy link

Model Name: Iphone 14
Software Version: 18.3.2
App version: 2025.2
Home Assistant Core Version: 2025.3.4

The official Home Assistant iOS app fails to connect when outside the local network via a Cloudflare Tunnel setup, despite successful access through web browsers (both desktop and mobile) under the same conditions. The app allows login with username and password, followed by a successful two-factor authentication (2FA) step where the code from the authenticator app is entered. Immediately after successfully submitting the 2FA code, the app displays the error: "The data couldn’t be read because it isn’t in the correct format." with Error Code: NSCocoaErrorDomain 3840. The app connects successfully when the iOS device is on the local Wi-Fi network.

To Reproduce

Set up a Home Assistant container and a cloudflared container on the same machine.
Configure a Cloudflare Tunnel to expose the Home Assistant instance to a public domain.
Ensure remote access to the Home Assistant instance via a web browser (both on desktop and a mobile device outside the local network) is working through the Cloudflare Tunnel, including successful 2FA if enabled in your browser setup.
Open the official Home Assistant iOS app while the iOS device is not connected to the local Wi-Fi network.
Enter the correct username and password on the login screen.
If 2FA is enabled, enter the correct code from your authenticator app on the subsequent screen.
Observe the error message: "The data couldn’t be read because it isn’t in the correct format." with Error Code: NSCocoaErrorDomain 3840 appearing immediately after successfully submitting the 2FA code.
Expected behavior

The Home Assistant iOS app should successfully connect to the Home Assistant instance when outside the local network via the Cloudflare Tunnel after entering the correct credentials and completing the 2FA process, similar to the successful web browser access. The user should be able to access the Home Assistant dashboard and control their devices.

Additional context

Home Assistant is running in a Docker container.
The cloudflared tunnel container is configured on the same machine as the Home Assistant container.
Accessing Home Assistant via a web browser (both desktop and mobile) through the Cloudflare Tunnel works without any issues when outside the local network, including successful 2FA if enabled.
The iOS app connects successfully when the device is on the local Wi-Fi network (using the local IP address or hostname).
The issue seems to occur specifically during the data loading phase after successful authentication and 2FA completion within the iOS app when connected remotely via the Cloudflare Tunnel.

Image

@Artanovskaya
Copy link

The problem also exists on iPad and iPhone 12, but on Android with the same parameters this problem does not exist.

@bgoncal
Copy link
Member

bgoncal commented Mar 31, 2025

Thanks for reporting the issue, just to double check, when you say "2FA" you mean Home Assistant 2FA right (like in the image below)? Not another layer of protection from cloudflare, correct?

Image

Also please reproduce the issue once again, export the logs and submit here: https://forms.gle/Uoqz127Phx4mMTpS6

@bgoncal bgoncal self-assigned this Mar 31, 2025
@Elad-Hanania
Copy link
Author

@bgoncal Thanks! I can reproduce the issue and submit logs via the form.

Could you please clarify:

  1. Which specific logs do you need (are the default app logs sufficient)?
  2. What's the best way to export them from the iOS app after reproducing the error?

I'll send them as soon as I know exactly what's needed.

Thanks

@bgoncal
Copy link
Member

bgoncal commented Apr 7, 2025

It’s the companion app logs inside companion app settings >> debugging >> export logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants