Skip to content

SDK-469 Fix CodeQL string length conflation in deep link check#1071

Open
sumeruchat wants to merge 2 commits into
masterfrom
fix/SDK-469-deeplink-string-length-conflation
Open

SDK-469 Fix CodeQL string length conflation in deep link check#1071
sumeruchat wants to merge 2 commits into
masterfrom
fix/SDK-469-deeplink-string-length-conflation

Conversation

@sumeruchat
Copy link
Copy Markdown
Contributor

@sumeruchat sumeruchat commented May 29, 2026

What

Fixes a CodeQL-flagged String-length conflation (CWE-135) in DeepLinkManager.isIterableDeepLink. The NSRegularExpression search range was built from urlString.count (a Swift String grapheme-cluster count) while NSRegularExpression operates on NSString/UTF-16 coordinates. For URLs with non-BMP characters (e.g. emoji), those measures diverge and the range under-covers the string, so a valid deep link can be missed. Ticket: SDK-469.

Changes

  • DeepLinkManager.swift: build the NSRange from the bridged NSString.length instead of String.count, so the range matches the UTF-16 coordinates NSRegularExpression uses. Matches the ticket's prescribed fix and CodeQL's own recommended example.
  • DeepLinkTests.swift: two regression tests — a URL with a long non-BMP prefix before the /a/... segment (this case returns false under the old String.count range and true with the fix), and a non-BMP URL without a deep-link path (stays false).

Impact

  • Breaking changes: None. Behavior only changes for previously-mishandled non-BMP URLs, which now match correctly.
  • Dependencies: None.
  • Performance: Negligible — one StringNSString bridge per call.

Testing

How to test:

  1. Run ./agent_test.sh DeepLinkTests — 11/11 pass, including the two new SDK-469 cases.
  2. Confirm CodeQL no longer flags the string-length conflation at DeepLinkManager.swift.
  3. Edge case: a deep link like https://links.iterable.com/👍🏿…/a/<id> is now correctly recognized as an Iterable deep link.

CodeQL flagged a String-length conflation (CWE-135) in
DeepLinkManager.isIterableDeepLink: the search range for
NSRegularExpression was built with NSMakeRange(0, urlString.count),
mixing a Swift String grapheme-cluster count with NSRegularExpression's
NSString/UTF-16 semantics. For URLs containing non-BMP characters (e.g.
emoji) the two measures diverge, producing a range that under-covers the
string and can cause the deep-link match to be missed.

- Build the NSRange from the bridged NSString.length so the range is
  expressed in the same UTF-16 coordinates NSRegularExpression uses.
- Add two regression tests: a URL with a long non-BMP prefix before the
  "/a/..." segment (fails against the old String.count range, passes with
  the fix), and a non-BMP URL without a deep-link path (stays false).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.28%. Comparing base (7eb259c) to head (ae8e94e).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1071      +/-   ##
==========================================
+ Coverage   71.22%   71.28%   +0.05%     
==========================================
  Files         112      112              
  Lines        9365     9370       +5     
==========================================
+ Hits         6670     6679       +9     
+ Misses       2695     2691       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Re-run CI after an unrelated flaky failure in
InboxTests.testInboxAndInAppCallbacksTogether (inbox-message-count race
on the first notification callback; passes 4/4 locally). No code change.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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