Skip to content

Sanitize Nightscout token to prevent WebSocket crash on launch#688

Open
bjorkert wants to merge 1 commit into
devfrom
fix/ws-token-sanitize-crash
Open

Sanitize Nightscout token to prevent WebSocket crash on launch#688
bjorkert wants to merge 1 commit into
devfrom
fix/ws-token-sanitize-crash

Conversation

@bjorkert

@bjorkert bjorkert commented Jun 22, 2026

Copy link
Copy Markdown
Member

Problem

LoopFollow crashes on startup (the reporting user has TestFlight 6.2.0, iPad on iOS 26.5) with an EXC_BREAKPOINT/SIGTRAP from URLComponents.percentEncodedQuery's setter, reached through Socket.IO's createURLs() while opening the Nightscout WebSocket in MainViewController.viewDidLoad.

The Nightscout WebSocket (Socket.IO) is new in 6.2.0, so this is the first build that exercises this path. Socket.IO builds its connect URL query from the token we pass in connectParams, and its urlEncode() doesn't escape whitespace/control characters. On iOS 26 the percentEncodedQuery setter is strict and traps on a string that isn't already valid percent-encoding. So a token holding a stray character (e.g. a trailing newline from a paste) produces an invalid query and crashes the app at launch.

Fix

  • Add NightscoutUtils.sanitizeToken(_:), which strips whitespace, newlines, and control characters.
  • Sanitize the token when it's written from the Nightscout settings screen.
  • Sanitize defensively at WebSocket connect time so already-saved bad tokens stop crashing without the user re-entering anything.

Verified by the user reporting the issue, it's no longer crashing on startup and works like it should

Strip whitespace, newlines, and control characters from the token
before storing it and before opening the WebSocket. A stray character
(typically pasted in) produced an invalid percent-encoded query in
Socket.IO's URL builder, which traps on iOS 26 and crashed the app on
startup. Existing saved tokens are sanitized defensively at connect time.
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