Sanitize Nightscout token to prevent WebSocket crash on launch#688
Sanitize Nightscout token to prevent WebSocket crash on launch#688bjorkert wants to merge 2 commits into
Conversation
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.
Test✅ This modification fixes the specific error of a token with white space I think the URL entry and token entry both need to be sanitized. I will approve this to avoid blocking the merge if this is urgent. ConfigurationiPhone SE 2nd gen running iOS 18.7.8
Test DetailsEnter URL with TokenI entered a properly formatted URL with embedded token.
I then copied that string and added both a space at the end and a return at the end for 2 different tests.
Enter URL and Token SeparatelyIf I separately input the URL and the token and enter a token with an extra space at the end, it correctly reads the token. Repeat that test with dev and get invalid token. |
There was a problem hiding this comment.
Based on code review and test:
✅ This modification fixes the specific error of a token with white space
❌ This modification does not fix the entry of a URL with embedded token with white space
I think the URL entry and token entry both need to be sanitized.
I approve this to avoid blocking the merge if this fix is urgent.
I would prefer this contain a more general fix.
|
Problem
LoopFollow crashes on startup (the reporting user has TestFlight 6.2.0, iPad on iOS 26.5) with an
EXC_BREAKPOINT/SIGTRAP fromURLComponents.percentEncodedQuery's setter, reached through Socket.IO'screateURLs()while opening the Nightscout WebSocket inMainViewController.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
tokenwe pass inconnectParams, and itsurlEncode()doesn't escape whitespace/control characters. On iOS 26 thepercentEncodedQuerysetter 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
NightscoutUtils.sanitizeToken(_:), which strips whitespace, newlines, and control characters.Verified by the user reporting the issue, it's no longer crashing on startup and works like it should