Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

9 changes: 0 additions & 9 deletions packages/core/ios/RNSentryExperimentalOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,6 @@ NS_ASSUME_NONNULL_BEGIN
*/
+ (void)setEnableLogs:(BOOL)enabled sentryOptions:(SentryOptions *)sentryOptions;

/**
* Sets the enableSessionReplayInUnreliableEnvironment experimental option on SentryOptions
* @param sentryOptions The SentryOptions instance to configure
* @param enabled Whether enableSessionReplayInUnreliableEnvironment from sentry Cocoa should be
* enabled
*/
+ (void)setEnableSessionReplayInUnreliableEnvironment:(BOOL)enabled
sentryOptions:(SentryOptions *)sentryOptions;

/**
* Configures iOS UI profiling options on SentryOptions
* @param profilingOptions Dictionary containing profiling configuration
Expand Down
9 changes: 0 additions & 9 deletions packages/core/ios/RNSentryExperimentalOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,6 @@ + (void)setEnableLogs:(BOOL)enabled sentryOptions:(SentryOptions *)sentryOptions
sentryOptions.enableLogs = enabled;
}

+ (void)setEnableSessionReplayInUnreliableEnvironment:(BOOL)enabled
sentryOptions:(SentryOptions *)sentryOptions
{
if (sentryOptions == nil) {
return;
}
sentryOptions.experimental.enableSessionReplayInUnreliableEnvironment = enabled;
}

+ (void)configureProfilingWithOptions:(NSDictionary *)profilingOptions
sentryOptions:(SentryOptions *)sentryOptions
{
Expand Down
3 changes: 1 addition & 2 deletions packages/core/ios/RNSentryReplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

/**
* Updates the session replay options
* @return true when session replay is enabled
*/
+ (BOOL)updateOptions:(NSMutableDictionary *)options;
+ (void)updateOptions:(NSMutableDictionary *)options;

+ (void)postInit;

Expand Down
6 changes: 2 additions & 4 deletions packages/core/ios/RNSentryReplay.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
@implementation RNSentryReplay {
}

+ (BOOL)updateOptions:(NSMutableDictionary *)options
+ (void)updateOptions:(NSMutableDictionary *)options
{
NSNumber *sessionSampleRate = options[@"replaysSessionSampleRate"];
NSNumber *errorSampleRate = options[@"replaysOnErrorSampleRate"];

if (sessionSampleRate == nil && errorSampleRate == nil) {
NSLog(@"Session replay disabled via configuration");
return NO;
return;
}

NSLog(@"Setting up session replay");
Expand All @@ -45,8 +45,6 @@ + (BOOL)updateOptions:(NSMutableDictionary *)options
@ { @"name" : REACT_NATIVE_SDK_NAME, @"version" : REACT_NATIVE_SDK_PACKAGE_VERSION }
}
forKey:@"sessionReplay"];
return (errorSampleRate != nil && [errorSampleRate doubleValue] > 0)
|| (sessionSampleRate != nil && [sessionSampleRate doubleValue] > 0);
}

+ (NSArray *_Nonnull)getReplayRNRedactClasses:(NSDictionary *_Nullable)replayOptions
Expand Down
9 changes: 1 addition & 8 deletions packages/core/ios/RNSentryStart.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ + (SentryOptions *_Nullable)createOptionsWithDictionary:(NSDictionary *_Nonnull)
NSMutableDictionary *mutableOptions = [options mutableCopy];

#if SENTRY_TARGET_REPLAY_SUPPORTED
BOOL isSessionReplayEnabled = [RNSentryReplay updateOptions:mutableOptions];
#else
BOOL isSessionReplayEnabled = NO;
[RNSentryReplay updateOptions:mutableOptions];
#endif

SentryOptions *sentryOptions = [PrivateSentrySDKOnly optionsWithDictionary:mutableOptions
Expand Down Expand Up @@ -170,11 +168,6 @@ + (SentryOptions *_Nullable)createOptionsWithDictionary:(NSDictionary *_Nonnull)
}
}

if (isSessionReplayEnabled) {
[RNSentryExperimentalOptions setEnableSessionReplayInUnreliableEnvironment:YES
sentryOptions:sentryOptions];
}

return sentryOptions;
}

Expand Down
2 changes: 0 additions & 2 deletions packages/core/ios/SentrySDKWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
+ (void)startWithOptions:(SentryOptions *)options;

+ (SentryOptions *)createOptionsWithDictionary:(NSDictionary *)options
isSessionReplayEnabled:(BOOL)isSessionReplayEnabled
error:(NSError **)errorPointer;

+ (void)setupWithDictionary:(NSDictionary *)options
isSessionReplayEnabled:(BOOL)isSessionReplayEnabled
error:(NSError **)errorPointer;

+ (BOOL)debug;
Expand Down
7 changes: 0 additions & 7 deletions packages/core/ios/SentrySDKWrapper.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
}

+ (SentryOptions *)createOptionsWithDictionary:(NSDictionary *)options
isSessionReplayEnabled:(BOOL)isSessionReplayEnabled
error:(NSError *__autoreleasing *)errorPointer
{
NSString *dsn = [self getURLFromDSN:[options valueForKey:@"dsn"]];
Expand Down Expand Up @@ -115,10 +114,6 @@
}
}

if (isSessionReplayEnabled) {
Comment thread
cursor[bot] marked this conversation as resolved.
[RNSentryExperimentalOptions setEnableSessionReplayInUnreliableEnvironment:YES
sentryOptions:sentryOptions];
}
return sentryOptions;
}

Expand All @@ -132,15 +127,13 @@
}

+ (void)setupWithDictionary:(NSDictionary *_Nonnull)options
isSessionReplayEnabled:(BOOL)isSessionReplayEnabled
error:(NSError *_Nonnull *_Nonnull)errorPointer
{
SentryOptions *sentryOptions = [self createOptionsWithDictionary:options
isSessionReplayEnabled:isSessionReplayEnabled
error:errorPointer];
if (!options) {
return;
Comment on lines 127 to 135
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The nil-check in setupWithDictionary incorrectly validates the input options instead of the sentryOptions object, potentially causing startWithOptions to be called with nil.
Severity: HIGH

Suggested Fix

Modify the conditional check from if (!options) to if (!sentryOptions) to ensure the SentryOptions object was successfully created before it is used to initialize the SDK.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: packages/core/ios/SentrySDKWrapper.m#L127-L135

Potential issue: In the `setupWithDictionary` method, `createOptionsWithDictionary` can
return `nil` if initialization fails, for example, due to an invalid DSN. The code then
incorrectly checks if the input `options` dictionary is `nil` instead of checking the
returned `sentryOptions` object. Consequently, if `sentryOptions` is `nil`, the program
proceeds to call `[SentrySDKWrapper startWithOptions:nil]`, which can lead to a crash or
undefined behavior during SDK initialization.

Did we get this right? 👍 / 👎 to inform future reviews.

}

Check failure on line 136 in packages/core/ios/SentrySDKWrapper.m

View check run for this annotation

@sentry/warden / warden: find-bugs

setupWithDictionary checks wrong variable, allowing nil sentryOptions to be used

On line 134, the code checks `if (!options)` but should check `if (!sentryOptions)`. The variable `options` is the input NSDictionary parameter (which is `_Nonnull`), while `sentryOptions` is the result of `createOptionsWithDictionary:error:` which can return `nil` when parsing fails (e.g., invalid DSN). This means when `createOptionsWithDictionary` returns nil due to an error, the code proceeds to call `[SentrySDKWrapper startWithOptions:nil]`, which may crash or cause undefined behavior.

NSString *sdkVersion = [PrivateSentrySDKOnly getSdkVersionString];
[PrivateSentrySDKOnly setSdkName:NATIVE_SDK_NAME andVersionString:sdkVersion];
Expand Down
Loading