From 8f404b5f9fea43451b6791a95710f23ae4b39bfb Mon Sep 17 00:00:00 2001 From: Matus Tomlein Date: Wed, 20 Nov 2024 15:18:08 +0100 Subject: [PATCH 1/2] Handle nan values and other non-serializable data in events from the WebView tracker (#909) --- .../Core/Tracker/WebViewMessageHandler.swift | 5 +++ Tests/TestWebViewMessageHandler.swift | 36 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/Sources/Core/Tracker/WebViewMessageHandler.swift b/Sources/Core/Tracker/WebViewMessageHandler.swift index 93a0c79fd..486ef0cbe 100644 --- a/Sources/Core/Tracker/WebViewMessageHandler.swift +++ b/Sources/Core/Tracker/WebViewMessageHandler.swift @@ -40,6 +40,11 @@ class WebViewMessageHandler: NSObject, WKScriptMessageHandler { let context = body["context"] as? [[AnyHashable : Any]] ?? [] let trackers = body["trackers"] as? [String] ?? [] + if !JSONSerialization.isValidJSONObject(event) || !JSONSerialization.isValidJSONObject(context) { + logError(message: "WebView: Received event payload is not serializable to JSON, skipping.") + return + } + if command == "trackSelfDescribingEvent" { trackSelfDescribing(event, withContext: context, andTrackers: trackers) } else if command == "trackStructEvent" { diff --git a/Tests/TestWebViewMessageHandler.swift b/Tests/TestWebViewMessageHandler.swift index a2ebe5e76..a33ef9c7f 100644 --- a/Tests/TestWebViewMessageHandler.swift +++ b/Tests/TestWebViewMessageHandler.swift @@ -126,5 +126,41 @@ class TestWebViewMessageHandler: XCTestCase { let context = payload?["co"] as? String XCTAssert(context?.contains("{\"a\":\"b\"}") ?? false) } + + func testHandlesNonJSONSerializableDataInEvent() { + let message = MockWKScriptMessage( + body: [ + "command": "trackSelfDescribingEvent", + "event": [ + "schema": "http://schema.com", + "data": [ + "key": Double.nan + ] + ] + ]) + webViewMessageHandler?.receivedMesssage(message) // shouldn't crash + } + + func testHandlesNonJSONSerializableDataInContext() { + let message = MockWKScriptMessage( + body: [ + "command": "trackSelfDescribingEvent", + "event": [ + "schema": "http://schema.com", + "data": [ + "key": "val" + ] + ], + "context": [ + [ + "schema": "http://context-schema.com", + "data": [ + "a": Double.nan + ] + ] + ] + ]) + webViewMessageHandler?.receivedMesssage(message) // shouldn't crash + } } #endif From be5f6c39876e5dbf7a00d7082f55001879c7128b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matu=CC=81s=CC=8C=20Tomlein?= Date: Wed, 20 Nov 2024 15:23:04 +0100 Subject: [PATCH 2/2] Prepare for 6.0.9 release --- CHANGELOG | 4 ++++ Examples | 2 +- SnowplowTracker.podspec | 2 +- Sources/Core/TrackerConstants.swift | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 5c5a53241..3611cf3e8 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +Version 6.0.9 (2024-11-21) +-------------------------- +Handle nan values and other non-serializable data in events from the WebView tracker (#909) + Version 6.0.8 (2024-08-19) -------------------------- Fix media tracking calls not being dispatched on the correct queue when tracking using AVPlayer diff --git a/Examples b/Examples index 17c63afb1..577dcae69 160000 --- a/Examples +++ b/Examples @@ -1 +1 @@ -Subproject commit 17c63afb1da94a86706d0400a9cc79115d000537 +Subproject commit 577dcae6938ce18501c38309a1fad3bde07c18d3 diff --git a/SnowplowTracker.podspec b/SnowplowTracker.podspec index 8281f5f43..c711c83e2 100644 --- a/SnowplowTracker.podspec +++ b/SnowplowTracker.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "SnowplowTracker" - s.version = "6.0.8" + s.version = "6.0.9" s.summary = "Snowplow event tracker for iOS, macOS, tvOS, watchOS for apps and games." s.description = <<-DESC Snowplow is a mobile and event analytics platform with a difference: rather than tell our users how they should analyze their data, we deliver their event-level data in their own data warehouse, on their own Amazon Redshift or Postgres database, so they can analyze it any way they choose. Snowplow mobile is used by data-savvy games companies and app developers to better understand their users and how they engage with their games and applications. Snowplow is open source using the business-friendly Apache License, Version 2.0 and scales horizontally to many billions of events. diff --git a/Sources/Core/TrackerConstants.swift b/Sources/Core/TrackerConstants.swift index c1f2b470e..ba712e2d4 100644 --- a/Sources/Core/TrackerConstants.swift +++ b/Sources/Core/TrackerConstants.swift @@ -14,7 +14,7 @@ import Foundation // --- Version -let kSPRawVersion = "6.0.8" +let kSPRawVersion = "6.0.9" #if os(iOS) let kSPVersion = "ios-\(kSPRawVersion)" #elseif os(tvOS)