fix: [SDK-5304] reject null and empty identity strings instead of crashing - #1997
abdulraqeeb33 wants to merge 4 commits into
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
nan-li
left a comment
There was a problem hiding this comment.
We have login(externalId: string) defined as string instead of optional string in the API:
react-native-onesignal/src/index.ts
Line 122 in 11cab78
Maybe we can do the check there instead of at both bridges, like we do for addTag where we check:
if (!key || value === undefined || value === null) {
console.error('OneSignal: addTag: must include a key and a value');
return;
}
Are there other methods where devs are submitting invalid inputs that can crash?
Kotlin non-null String APIs crash when JS passes null. Empty login is invalid too. Guard both in isNonEmptyString and skip the native call. Co-authored-by: Cursor <cursoragent@cursor.com>
Good cal @nan-li - updated it in other methods as well. please check it out. |
NSLog bypasses setLogLevel. Use the same OneSignalLog error path as the rest of the iOS bridge. Co-authored-by: Cursor <cursoragent@cursor.com>
| /** Initializes the OneSignal SDK. This should be called during startup of the application. */ | ||
| export function initialize(appId: string) { | ||
| if (!isNativeModuleLoaded(RNOneSignal)) return; | ||
| if (!isNonEmptyString(appId)) { |
There was a problem hiding this comment.
can just be !appId , similar in other places
There was a problem hiding this comment.
Kept isNonEmptyString. !appId lets a non-string through, and it would reject "" for tag values, trigger values, and setLanguage.
Empty language is the only reset path. Null is still rejected. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Empty string stays in this PR. Parent is SDK-5327, with a subtask per SDK.
|
Description
One Line Summary
Return from React Native identity string APIs when the value is null or empty instead of crashing Kotlin non-null
Stringparameters.Details
Motivation
Fixes SDK-5304. JS
nullreaches KotlinOneSignal.login(externalId: String)(and the same class of APIs:addEmail,initialize(appId)), which throwsIllegalArgumentException: Parameter specified as non-null is null. The TurboModule method is void and uncaught, so the host process dies.Empty string does not NPE, but
login("")is not a valid user id. Rejected in the same helper.Other SDKs: SDK-5327.
Scope
isNonEmptyStringrejects null, undefined, and empty for:initialize(appId)login(externalId)addAlias(label and id) andremoveAliasaddEmail/removeEmailaddSms/removeSmsaddTag(key only). An empty tag value is allowed. A null tag value is rejected.removeTagrejects an empty key.addTrigger(key only). An empty trigger value is allowed. A null trigger value is rejected.addTriggerreturns after the invalid-input log instead of still calling native.removeTriggerrejects an empty key.Native
loginalso returns on null/nil or empty. Public TS types staystring.setLanguage("")is not rejected. It is the reset to the device language, and there is no other reset path.nullis still rejected.addAliases,removeAliases,addTags,removeTags,addTriggers,removeTriggers, andtrackEventare unchanged.Testing
Unit testing
vp test: 291 tests passed. Covers login/initialize/addEmail null and empty,setLanguage("")still calling native, null language not calling native, and addTrigger no longer calling native after invalid input.Manual testing
Not run on a device. The crash is a null argument at the bridge. Unit coverage is the JS helper. Native login guards match null/empty.
Affected code checklist
Checklist
Overview
Testing
Final pass