Paul Beusterien 4f96b51a1c Reject invalid input in GULKeychainStorage and GULUserDefaults instead of crashing (#250)
* fix(keychain): reject nil objects and invalid keys in GULKeychainStorage

Validate arguments on the caller's thread and report an error through the
completion handler, instead of dispatching them to the internal queues.

Previously, a nil object made NSCache throw inside a dispatch_async block
on the in-memory cache queue. The caller could not catch the exception, so
the app crashed with a stack attributed to GoogleUtilities, the same
pattern as #248. A nil key did not throw, but it removed kSecAttrAccount
from the keychain query, so get/remove could match other items stored for
the same service.

Add GULKeychainStorageInvalidInputTests. The rejected input never reaches
the keychain, so these tests run under SwiftPM and on macOS, unlike
GULKeychainStorageTests.

* fix(userdefaults): validate entire value graph in GULUserDefaults

Use NSPropertyListSerialization to validate the whole value before writing
it to NSUserDefaults, instead of checking only the top-level class.

Previously, a collection containing non-property-list content, such as an
NSNull decoded from a JSON null or a dictionary with non-string keys,
passed the check. NSUserDefaults then aborted the process, which callers
cannot catch. Such values are now rejected with the existing warning log
and the stored value is left unchanged.

* test(keychain): avoid capturing self in GULKeychainStorage completion blocks

Record results in __block variables inside the completion handlers and
assert after waiting for the expectation. The blocks are retained by
self.storage, and capturing self in them (directly or through XCTAssert*
macros) triggered -Warc-retain-cycles in the CocoaPods lint.

* fix(keychain): report exceptions from decoding keychain items as errors

+[NSKeyedUnarchiver unarchivedObjectOfClass:fromData:error:] returns an
error for malformed archives, but an exception raised by the decoded
class's -initWithCoder: (for example while decoding corrupted keychain
data), or by a nil objectClass, still propagates. GULKeychainStorage
decodes on keychainQueue, where the caller cannot catch the exception, so
the app crashed.

Decode through a helper that catches the exception and returns an NSError,
which is passed to the completion handler.

* fix(keychain): allow empty string keys

An empty string is a valid, distinct keychain account: it does not throw
in NSCache and keeps kSecAttrAccount in the query, so it is not a
wildcard like a nil key. Rejecting it would make items already stored
under @"" unreadable and undeletable, and turn previously working saves
into errors. Only reject nil and non-string keys.
2026-09-29 16:27:18 -07:00
2021-01-14 07:55:44 -08:00
2021-01-28 09:23:45 -05:00
2021-01-08 15:37:57 -08:00
2026-04-10 10:03:41 -04:00

Version License Platform

Actions Status

GoogleUtilities

GoogleUtilities provides a set of utilities for Firebase and other Google SDKs for Apple platform development.

The utilities are not directly supported for non-Google library usage.

Integration Testing

These instructions apply to minor and patch version updates. Major versions need a customized adaptation.

After the CI is green:

  • Determine the next version for release by checking the tagged releases. Ensure that the next release version keeps the Swift PM and CocoaPods versions in sync.
  • Verify that the releasing version is the latest entry in the CHANGELOG.md, updating it if necessary.
  • Update the version in the podspec to match the latest entry in the CHANGELOG.md
  • Checkout the main branch and ensure it is up to date
    git checkout main
    git pull
    
  • Add the CocoaPods tag ({version} will be the latest version in the podspec)
    git tag CocoaPods-{version}
    git push origin CocoaPods-{version}
    
  • Push the podspec to the designated repo
    • If this version of GoogleUtilities is intended to launch before or with the next Firebase release:

      Push to SpecsStaging
      pod repo push --skip-tests --use-json staging GoogleUtilities.podspec
      

      If the command fails with Unable to find the 'staging' repo., add the staging repo with:

      pod repo add staging git@github.com:firebase/SpecsStaging.git
      
    • Otherwise:

      Push to SpecsDev
      pod repo push --skip-tests --use-json dev GoogleUtilities.podspec
      

      If the command fails with Unable to find the 'dev' repo., add the dev repo with:

      pod repo add dev git@github.com:firebase/SpecsDev.git
      
  • Run Firebase CI by waiting until next nightly or adding a PR that touches Gemfile.
  • On google3, run copybara using the command below. Then, start a global TAP on the generated CL. Deflake as needed.
    third_party/firebase/ios/Releases/run_copy_bara.py --directory GoogleUtilities --branch main
    

Publishing

The release process is as follows:

  1. Tag and release for Swift PM
  2. Publish to CocoaPods
  3. Create GitHub Release
  4. Perform post release cleanup

Swift Package Manager

By creating and pushing a tag for Swift PM, the newly tagged version will be immediately released for public use. Given this, please verify the intended time of release for Swift PM.

  • Add a version tag for Swift PM
git tag {version}
git push origin {version}

Note: Ensure that any inflight PRs that depend on the new GoogleUtilities version are updated to point to the newly tagged version rather than a checksum.

CocoaPods

  • Publish the newly versioned pod to CocoaPods

    It's recommended to point to the GoogleUtilities.podspec in staging to make sure the correct spec is being published.

    pod trunk push ~/.cocoapods/repos/staging/GoogleUtilities/{version}/GoogleUtilities.podspec.json
    

    Note: In some cases, it may be acceptable to pod trunk push with the --skip-tests flag. Please double check with the maintainers before doing so.

    The pod push was successful if the above command logs: 🚀 GoogleUtilities ({version}) successfully published. In addition, a new commit that publishes the new version (co-authored by CocoaPodsAtGoogle) should appear in the CocoaPods specs repo. Last, the latest version should be displayed on GoogleUtilities's CocoaPods page.

Create GitHub Release

Update the release template's Tag version and Release title fields with the latest version. In addition, reference the Release Notes in the release's description.

See this release for an example.

Don't forget to perform the post release cleanup!

Post Release Cleanup

Clean up SpecsStaging
pwd=$(pwd)
mkdir -p /tmp/release-cleanup && cd $_
git clone git@github.com:firebase/SpecsStaging.git
cd SpecsStaging/
git rm -rf GoogleUtilities/
git commit -m "Post publish cleanup"
git push origin master
rm -rf /tmp/release-cleanup
cd $pwd

Development

To develop in this repository, ensure that you have at least the following software:

For the pod that you want to develop:

pod gen GoogleUtilities.podspec --local-sources=./ --auto-open --platforms=ios

Note: If the CocoaPods cache is out of date, you may need to run pod repo update before the pod gen command.

Note: Set the --platforms option to macos or tvos to develop/test for those platforms. Since 10.2, Xcode does not properly handle multi-platform CocoaPods workspaces.

Development for Catalyst

  • pod gen GoogleUtilities.podspec --local-sources=./ --auto-open --platforms=ios
  • Check the Mac box in the App-iOS Build Settings
  • Sign the App in the Settings Signing & Capabilities tab
  • Click Pods in the Project Manager
  • Add Signing to the iOS host app and unit test targets
  • Select the Unit-unit scheme
  • Run it to build and test

Alternatively disable signing in each target:

  • Go to Build Settings tab
  • Click +
  • Select Add User-Defined Setting
  • Add CODE_SIGNING_REQUIRED setting with a value of NO

Code Formatting

See firebase-ios-sdk's code formatting docs.

Running Unit Tests

Select a scheme and press Command-u to build a component and run its unit tests.

Contributing

See Contributing.

License

The contents of this repository is licensed under the Apache License, version 2.0.

S
Description
No description provided
Readme Apache-2.0, MIT
1.5 MiB
0 Stars 1 Watchers 0 Forks
Languages
Objective-C 97.4%
Swift 1.6%
Ruby 0.9%
Shell 0.1%