Repository navigation
fix: [SDK-5426] reject blank identity strings #1760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+395
−11
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9351b15
fix: [SDK-5426] reject blank identity strings
a2b5d52
fix: [SDK-5426] keep a nil trigger value off the dictionary
91bf646
test: [SDK-5426] catch a missing email and SMS guard
7bb6d3d
fix: [SDK-5426] reject identity strings that contain a null byte
fd4f56a
style: [SDK-5426] drop the redundant [OneSignal] log prefix
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSInputGuard.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| /* | ||
| Modified MIT License | ||
|
|
||
| Copyright 2026 OneSignal | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
|
|
||
| 1. The above copyright notice and this permission notice shall be included in | ||
| all copies or substantial portions of the Software. | ||
|
|
||
| 2. All copies of substantial portions of the Software may only be used in connection | ||
| with services provided by OneSignal. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| THE SOFTWARE. | ||
| */ | ||
|
|
||
| import Foundation | ||
| import OneSignalCore | ||
|
|
||
| @objc(OSInputGuard) | ||
| public final class OSInputGuard: NSObject { | ||
| @objc(isMissing:api:) | ||
| public static func isMissing(_ value: String?, _ api: String) -> Bool { | ||
| // A NUL cannot be stored in a text column, so it is never a usable value. | ||
| if let value, value.contains("\u{0000}") { | ||
|
abdulraqeeb33 marked this conversation as resolved.
|
||
| OneSignalLog.onesignalLog(.LL_ERROR, message: "\(api) contains a null byte") | ||
| return true | ||
| } | ||
| if let value, !value.isEmpty { | ||
| return false | ||
| } | ||
| OneSignalLog.onesignalLog(.LL_ERROR, message: "\(api) is required") | ||
| return true | ||
| } | ||
|
|
||
| @objc(isMissingAny:api:) | ||
| public static func isMissingAny(_ values: NSArray?, _ api: String) -> Bool { | ||
| guard let values else { | ||
| return isMissing(nil, api) | ||
| } | ||
| for item in values where isMissing(item as? String, api) { | ||
| return true | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| /// `allowEmptyValue` keeps "" and a value containing a null byte. A null value is still rejected. | ||
| @objc(hasMissingEntries:api:allowEmptyValue:) | ||
| public static func hasMissingEntries( | ||
| _ values: NSDictionary?, | ||
| _ api: String, | ||
| allowEmptyValue: Bool | ||
| ) -> Bool { | ||
| guard let values else { | ||
| return isMissing(nil, api) | ||
| } | ||
| for (key, item) in values { | ||
| if isMissing(key as? String, "\(api): key") { | ||
| return true | ||
| } | ||
| if allowEmptyValue { | ||
| if item is NSNull { | ||
| return isMissing(nil, "\(api): value") | ||
| } | ||
| continue | ||
| } | ||
| if isMissing(item as? String, "\(api): value") { | ||
| return true | ||
| } | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| @nonobjc | ||
| public static func isMissingAny(_ values: [String]?, _ api: String) -> Bool { | ||
| isMissingAny(values as NSArray?, api) | ||
| } | ||
|
|
||
| @nonobjc | ||
| public static func hasMissingEntries( | ||
| _ values: [String: String]?, | ||
| _ api: String, | ||
| allowEmptyValue: Bool | ||
| ) -> Bool { | ||
| hasMissingEntries(values as NSDictionary?, api, allowEmptyValue: allowEmptyValue) | ||
| } | ||
| } | ||
66 changes: 66 additions & 0 deletions
66
iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSInputGuardTests.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| /* | ||
| Modified MIT License | ||
|
|
||
| Copyright 2026 OneSignal | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
|
|
||
| 1. The above copyright notice and this permission notice shall be included in | ||
| all copies or substantial portions of the Software. | ||
|
|
||
| 2. All copies of substantial portions of the Software may only be used in connection | ||
| with services provided by OneSignal. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| THE SOFTWARE. | ||
| */ | ||
|
|
||
| import XCTest | ||
| @testable import OneSignalOSCore | ||
|
|
||
| final class OSInputGuardTests: XCTestCase { | ||
| func testIsMissingRejectsNilAndEmptyAndKeepsWhitespace() { | ||
| XCTAssertTrue(OSInputGuard.isMissing(nil, "login: externalId")) | ||
| XCTAssertTrue(OSInputGuard.isMissing("", "login: externalId")) | ||
| XCTAssertFalse(OSInputGuard.isMissing(" ", "login: externalId")) | ||
| XCTAssertFalse(OSInputGuard.isMissing("user", "login: externalId")) | ||
| XCTAssertTrue(OSInputGuard.isMissing("\u{0000}: 1", "login: externalId")) | ||
| XCTAssertTrue(OSInputGuard.isMissing("abc\u{0000}", "addAlias: id")) | ||
| } | ||
|
|
||
| func testIsMissingAnyRejectsABlankEntryAndANilCollection() { | ||
| XCTAssertTrue(OSInputGuard.isMissingAny(nil as NSArray?, "removeTags: key")) | ||
| XCTAssertTrue(OSInputGuard.isMissingAny(nil as [String]?, "removeTags: key")) | ||
| XCTAssertTrue(OSInputGuard.isMissingAny(["ok", ""], "removeTags: key")) | ||
| XCTAssertFalse(OSInputGuard.isMissingAny(["ok", " "], "removeTags: key")) | ||
| } | ||
|
|
||
| func testHasMissingEntriesRejectsBlankKeysAndBlankAliasIds() { | ||
| XCTAssertTrue(OSInputGuard.hasMissingEntries(nil as [String: String]?, "addAliases", allowEmptyValue: false)) | ||
| XCTAssertTrue(OSInputGuard.hasMissingEntries(["": "id"], "addAliases", allowEmptyValue: false)) | ||
| XCTAssertTrue(OSInputGuard.hasMissingEntries(["label": ""], "addAliases", allowEmptyValue: false)) | ||
| XCTAssertFalse(OSInputGuard.hasMissingEntries(["label": "id"], "addAliases", allowEmptyValue: false)) | ||
| XCTAssertFalse(OSInputGuard.hasMissingEntries(["label": " "], "addAliases", allowEmptyValue: false)) | ||
| XCTAssertTrue(OSInputGuard.hasMissingEntries(["external_id": "\u{0000}: 1"], "addAliases", allowEmptyValue: false)) | ||
| } | ||
|
|
||
| func testHasMissingEntriesAllowsAnEmptyTagValueAndRejectsNull() { | ||
| XCTAssertFalse(OSInputGuard.hasMissingEntries(["key": ""], "addTags", allowEmptyValue: true)) | ||
| XCTAssertTrue(OSInputGuard.hasMissingEntries(["": "value"], "addTags", allowEmptyValue: true)) | ||
| let tags = NSMutableDictionary() | ||
| tags["key"] = NSNull() | ||
| XCTAssertTrue(OSInputGuard.hasMissingEntries(tags, "addTags", allowEmptyValue: true)) | ||
| XCTAssertFalse(OSInputGuard.hasMissingEntries(["key": "a\u{0000}b"], "addTags", allowEmptyValue: true)) | ||
| XCTAssertTrue(OSInputGuard.hasMissingEntries(["a\u{0000}": "value"], "addTags", allowEmptyValue: true)) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.