Skip to content

Commit

Permalink
feat: add maskPhotoLibraryImages and maskSandboxedViews config
Browse files Browse the repository at this point in the history
  • Loading branch information
ioannisj committed Nov 25, 2024
1 parent e3a37b3 commit ff9291b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
30 changes: 11 additions & 19 deletions PostHog/Replay/PostHogReplayIntegration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
private let reactNativeTextView: AnyClass? = NSClassFromString("RCTTextView")
private let reactNativeImageView: AnyClass? = NSClassFromString("RCTImageView")
// These are usually views that don't belong to the current process and are most likely sensitive
private let systemRemoteView: AnyClass? = NSClassFromString("_UIRemoteView")
private let systemSandboxedView: AnyClass? = NSClassFromString("_UIRemoteView")

static let dispatchQueue = DispatchQueue(label: "com.posthog.PostHogReplayIntegration",
target: .global(qos: .utility))
Expand Down Expand Up @@ -286,25 +286,13 @@
}
}

// if view in photo library picker controller, always mask the whole view
if let pickerViewController = view.nearestViewController as? UIImagePickerController {
maskableWidgets.append(pickerViewController.view.toAbsoluteRect(window))
return
}

if #available(iOS 14, *) {
if let pickerViewController = view.nearestViewController as? PHPickerViewController {
maskableWidgets.append(pickerViewController.view.toAbsoluteRect(window))
return
}
}

// detect any views that don't belong to the current process (likely system views)
if let systemRemoteView {
if view.isKind(of: systemRemoteView) {
maskableWidgets.append(view.toAbsoluteRect(window))
return
}
if config.sessionReplayConfig.maskSandboxedViews,
let systemSandboxedView,
view.isKind(of: systemSandboxedView)
{
maskableWidgets.append(view.toAbsoluteRect(window))
return
}

// if its a generic type and has subviews, subviews have to be checked first
Expand Down Expand Up @@ -407,6 +395,10 @@
// Photo library images have a UUID identifier as _assetName (e.g 64EF5A48-2E96-4AB2-A79B-AAB7E9116E3D)
// SF symbol and bundle images have the actual symbol name as _assetName (e.g chevron.backward)
private func isPhotoLibraryImage(_ image: UIImage) -> Bool {
guard config.sessionReplayConfig.maskPhotoLibraryImages else {
return false
}

guard let assetName = image.imageAsset?.value(forKey: "_assetName") as? String else {
return false
}
Expand Down
11 changes: 11 additions & 0 deletions PostHog/Replay/PostHogSessionReplayConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@
/// Default: true
@objc public var maskAllImages: Bool = true

/// Enable masking of all sandboxed system views
/// These may include UIImagePickerController, PHPickerViewController and CNContactPickerViewController
/// Experimental support
/// Default: true
@objc public var maskSandboxedViews: Bool = true

/// Enable masking of images that likely originated from user's photo library
/// Experimental support (UIKit only)
/// Default: true
@objc public var maskPhotoLibraryImages: Bool = true

/// Enable capturing network telemetry
/// Experimental support
/// Default: true
Expand Down

0 comments on commit ff9291b

Please sign in to comment.