Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances Firebase Functions by integrating support for limited-use App Check tokens. This feature provides an additional layer of security, specifically for replay protection, by allowing requests to callable functions to be made with tokens that are valid for a single use. The changes involve updating the API to accept new options, modifying internal token handling mechanisms, and ensuring compatibility across all supported platforms. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe 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
Customization To customize 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 Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. 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. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds support for limited-use App Check tokens in Firebase Functions across Android, iOS, and desktop platforms. While the core implementation appears solid, a critical security vulnerability has been identified: the new GetHttpsCallableFromURL functions across all platforms lack URL validation. This could lead to sensitive information leakage (e.g., Firebase Auth and App Check tokens) if user-controlled or insecure (HTTP) URLs are passed. It is highly recommended to enforce HTTPS and implement URL validation to ensure requests are only sent to trusted destinations. Furthermore, there are a couple of suggestions to improve the readability of the JNI code in the Android implementation.
| HttpsCallableReferenceInternal* FunctionsInternal::GetHttpsCallableFromURL( | ||
| const char* url, const HttpsCallableOptions& options) const { | ||
| return new HttpsCallableReferenceInternal( | ||
| const_cast<FunctionsInternal*>(this), url); | ||
| const_cast<FunctionsInternal*>(this), url, options); | ||
| } |
There was a problem hiding this comment.
The function GetHttpsCallableFromURL accepts an arbitrary URL and passes it to HttpsCallableReferenceInternal. When Call() is invoked, the SDK automatically attaches sensitive Firebase Auth tokens (Authorization: Bearer <token>) and App Check tokens (X-Firebase-AppCheck: <token>) to the request. If a developer passes a user-controlled URL, an attacker could steal these tokens. Additionally, the SDK does not enforce HTTPS, allowing tokens to be leaked over plaintext if an http:// URL is used.
Recommendation: Validate that the URL uses the https:// protocol and, if possible, restrict it to trusted Firebase domains.
| HttpsCallableReferenceInternal* FunctionsInternal::GetHttpsCallableFromURL( | ||
| const char* url, const HttpsCallableOptions& options) const { |
There was a problem hiding this comment.
The Android implementation of GetHttpsCallableFromURL lacks validation for the provided URL string. It directly converts the input to a java.net.URL and uses it to create a reference that will include sensitive Auth and App Check tokens in its requests. This poses a risk of sensitive information leakage if the URL is user-controlled or uses an insecure protocol.
Recommendation: Implement validation to ensure the URL is secure (HTTPS) and points to a trusted destination.
| HttpsCallableReferenceInternal* FunctionsInternal::GetHttpsCallableFromURL( | ||
| const char* url, const HttpsCallableOptions& options) const { |
There was a problem hiding this comment.
The iOS implementation of GetHttpsCallableFromURL does not validate the provided URL before passing it to the underlying native SDK. This inherits the same risks of SSRF and sensitive token leakage (Auth and App Check tokens) as the other platforms if the URL is not properly vetted.
Recommendation: Ensure the URL uses HTTPS and is validated against a list of trusted domains before use.
| jobject builder = env->NewObject( | ||
| callable_options_builder::GetClass(), | ||
| callable_options_builder::GetMethodId(callable_options_builder::kBuilderConstructor)); | ||
| jobject builder2 = env->CallObjectMethod( | ||
| builder, | ||
| callable_options_builder::GetMethodId(callable_options_builder::kSetLimitedUseAppCheckTokens), | ||
| options.limited_use_app_check_token); | ||
| env->DeleteLocalRef(builder); | ||
| builder = builder2; | ||
| jobject java_options = env->CallObjectMethod( | ||
| builder, | ||
| callable_options_builder::GetMethodId(callable_options_builder::kBuild)); | ||
| env->DeleteLocalRef(builder); |
There was a problem hiding this comment.
The way JNI local references are managed here for the builder pattern is a bit confusing. Reusing the builder variable makes it harder to track the lifecycle of the references. Consider using a separate variable for each step of the builder chain to improve readability and maintainability.
jobject builder = env->NewObject(
callable_options_builder::GetClass(),
callable_options_builder::GetMethodId(callable_options_builder::kBuilderConstructor));
jobject builder_with_token = env->CallObjectMethod(
builder,
callable_options_builder::GetMethodId(callable_options_builder::kSetLimitedUseAppCheckTokens),
options.limited_use_app_check_token);
jobject java_options = env->CallObjectMethod(
builder_with_token,
callable_options_builder::GetMethodId(callable_options_builder::kBuild));
env->DeleteLocalRef(builder);
env->DeleteLocalRef(builder_with_token);| jobject builder = env->NewObject( | ||
| callable_options_builder::GetClass(), | ||
| callable_options_builder::GetMethodId(callable_options_builder::kBuilderConstructor)); | ||
| jobject builder2 = env->CallObjectMethod( | ||
| builder, | ||
| callable_options_builder::GetMethodId(callable_options_builder::kSetLimitedUseAppCheckTokens), | ||
| options.limited_use_app_check_token); | ||
| env->DeleteLocalRef(builder); | ||
| builder = builder2; | ||
| jobject java_options = env->CallObjectMethod( | ||
| builder, | ||
| callable_options_builder::GetMethodId(callable_options_builder::kBuild)); | ||
| env->DeleteLocalRef(builder); |
There was a problem hiding this comment.
Similar to the comment above, the JNI local reference management for the builder pattern here is a bit confusing. Using separate variables for each step of the builder chain would improve readability.
jobject builder = env->NewObject(
callable_options_builder::GetClass(),
callable_options_builder::GetMethodId(callable_options_builder::kBuilderConstructor));
jobject builder_with_token = env->CallObjectMethod(
builder,
callable_options_builder::GetMethodId(callable_options_builder::kSetLimitedUseAppCheckTokens),
options.limited_use_app_check_token);
jobject java_options = env->CallObjectMethod(
builder_with_token,
callable_options_builder::GetMethodId(callable_options_builder::kBuild));
env->DeleteLocalRef(builder);
env->DeleteLocalRef(builder_with_token);
Description
Add support for limited use tokens in firebase functions.
Testing
Added new integrations test and tested on Macos, Android and iOS
Android:

iOS:

MacOs:

Type of Change
Place an
xthe applicable box:Notes
Release Notessection ofrelease_build_files/readme.md.