Skip to content

[Storage,Functions] Fix credentials for emulator - #16395

Merged
paulb777 merged 9 commits into
mainfrom
pb-emulator-credentials
Jul 14, 2026
Merged

[Storage,Functions] Fix credentials for emulator#16395
paulb777 merged 9 commits into
mainfrom
pb-emulator-credentials

Conversation

@paulb777

@paulb777 paulb777 commented Jul 14, 2026

Copy link
Copy Markdown
Member

See internal b/511890380. Review with https://github.com/firebase/firebase-ios-sdk/pull/16395/changes?w=1

Enforce token transport security for non-loopback HTTP connections

Description

This PR introduces stricter transport security checks for how Auth, FCM, and AppCheck tokens are handled over HTTP connections within the Firebase Storage and Firebase Functions iOS SDKs.
Previously, when developers configured their SDK to use an emulator running on a remote, non-loopback host (e.g., 10.0.0.x) over standard HTTP, the SDKs would unconditionally attach the app's bearer tokens to outgoing network requests.
To align with modern transport security best practices (and mirror the default behavior of gRPC in Firestore), this change ensures that we only attach session tokens if the underlying request is securely encrypted (https://) or targeting a local loopback interface (localhost, 127.0.0.1, ::1).

Changes Include

  • Firebase Storage: Updated StorageTokenAuthorizer to evaluate the outgoing request's scheme and host. If the request is over HTTP and destined for a non-loopback host, the token fetching and attachment logic is safely bypassed, and a warning is logged via FirebaseLogger.
  • Firebase Functions: Updated makeFetcher and makeRequestForStreamableContent to apply identical scheme/host validation logic before attaching tokens from the FunctionsContext.
  • Testing: Added corresponding unit tests to StorageAuthorizerTests.swift and FunctionsTests.swift to verify that headers are properly omitted under these conditions while retaining normal behavior for secure/local emulator workflows.

@gemini-code-assist

Copy link
Copy Markdown
Contributor
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

@paulb777

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request enforces stricter transport layer security across Firebase Functions and Firebase Storage by preventing Auth, FCM, and AppCheck tokens from being sent over insecure HTTP connections to non-loopback hosts. Review feedback suggests refactoring duplicated URL validation logic in Functions.swift into a private URL extension to improve maintainability, and guarding the warning log in StorageTokenAuthorizer.swift to prevent false positive logs when the request or URL is nil.

Comment thread FirebaseStorage/Sources/Internal/StorageTokenAuthorizer.swift Outdated
Comment thread FirebaseFunctions/Sources/Functions.swift Outdated
Comment thread FirebaseFunctions/Sources/Functions.swift Outdated
@paulb777

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request enforces stricter transport layer security in both Firebase Functions and Firebase Storage by preventing Auth, FCM, and AppCheck tokens from being attached to outbound HTTP requests directed to non-loopback hosts. While the implementation correctly identifies "localhost", "127.0.0.1", and "::1" as loopback addresses, the review feedback highlights that Foundation's URL.host returns IPv6 loopback addresses enclosed in square brackets (i.e., "[::1]"). To ensure robust IPv6 loopback detection, it is recommended to update the loopback checks in both Functions.swift and StorageTokenAuthorizer.swift to also match "[::1]".

Comment thread FirebaseFunctions/Sources/Functions.swift Outdated
Comment thread FirebaseStorage/Sources/Internal/StorageTokenAuthorizer.swift Outdated
@paulb777

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request enforces stricter transport layer security in both FirebaseFunctions and FirebaseStorage by preventing Auth, FCM, and AppCheck tokens from being attached to outbound HTTP requests directed to non-loopback hosts. Feedback on the changes suggests improving consistency and developer experience by adding warning logs in FirebaseFunctions when tokens are withheld (matching the behavior in FirebaseStorage), and adding a unit test to verify that loopback hosts successfully attach tokens over HTTP.

Comment thread FirebaseFunctions/Sources/Functions.swift
Comment thread FirebaseFunctions/Sources/Functions.swift
Comment thread FirebaseFunctions/Tests/Unit/FunctionsTests.swift
@paulb777

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request enforces stricter transport layer security in both Firebase Functions and Firebase Storage by preventing Auth, FCM, and AppCheck tokens from being attached to outbound requests over insecure HTTP connections to non-loopback hosts. While the implementation is solid, the new unit tests in FunctionsTests.swift pass nil for the fake auth provider, which prevents them from properly verifying whether the Authorization header is correctly attached or omitted based on the connection security. Updating these tests to use a fake auth provider will make the test suite more robust.

Comment thread FirebaseFunctions/Tests/Unit/FunctionsTests.swift
Comment thread FirebaseFunctions/Tests/Unit/FunctionsTests.swift
@paulb777

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request enforces stricter transport layer security when using the emulator for both Firebase Functions and Firebase Storage. Auth, FCM, and AppCheck tokens are no longer attached to outbound requests if the connection is made over HTTP to a non-loopback host. Appropriate warnings are logged when refusing to send tokens, and unit tests have been added to verify these changes. No review comments were provided, so I have no additional feedback.

@ncooke3 ncooke3 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

One optional refactor would be to prefer a guard statement that catches the else blocks.

@paulb777

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request enforces stricter transport layer security in Firebase Functions and Firebase Storage when using the emulator by preventing Auth, FCM, and AppCheck tokens from being attached to outbound HTTP requests to non-loopback hosts. The feedback suggests a minor optimization in StorageTokenAuthorizer.swift to extract the lowercased URL scheme into a local variable to avoid redundant evaluations and improve readability.

Comment thread FirebaseStorage/Sources/Internal/StorageTokenAuthorizer.swift Outdated
@paulb777
paulb777 merged commit 56213d8 into main Jul 14, 2026
128 checks passed
@paulb777
paulb777 deleted the pb-emulator-credentials branch July 14, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants