Skip to content

fix(crashlytics): send the quota project on Crashlytics API requests - #11547

Open
yeegz wants to merge 2 commits into
firebase:mainfrom
yeegz:fix/11545-crashlytics-quota-header
Open

yeegz wants to merge 2 commits into
firebase:mainfrom
yeegz:fix/11545-crashlytics-quota-header

Conversation

@yeegz

@yeegz yeegz commented Nov 18, 2026

Copy link
Copy Markdown

Description

Fixes #11545.

The Crashlytics API needs a quota project when called with user credentials, but only generateAlertPolicy sent x-goog-user-project (from #11382). So every other Crashlytics call failed with a 403 that said "requires a quota project". That includes the MCP tools and things like getIssue and listEvents.

This adds the header, set to the project number from the app ID, to the rest of the Crashlytics requests in issues.ts, events.ts, notes.ts and reports.ts. GOOGLE_CLOUD_QUOTA_PROJECT still wins if it's set, since apiv2 applies it afterwards.

Scenarios Tested

New src/crashlytics/quotaProject.spec.ts stubs CRASHLYTICS_API_CLIENT.request and checks the header on all nine calls. It fails on main and passes with this change. All Crashlytics and MCP specs pass.

I checked the request options directly because the test nock helper's matchHeader is a no-op (src/test/helpers/nock.ts), so header checks written with it, including the one in alerts.spec.ts, pass no matter what's sent. Happy to open a separate issue about that.

Sample Commands

With firebase login and no GOOGLE_CLOUD_QUOTA_PROJECT, crashlytics_get_issue and the other Crashlytics MCP tools no longer return 403.


I used an AI coding assistant for this and reviewed it myself.

🤖 Generated with Claude Code

@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 addresses a Crashlytics API issue where requests fail when using user credentials by adding the required 'x-goog-user-project' header to all relevant API calls. A new unit test file was added to verify that this header is correctly included in requests. The review feedback highlights the need to use the existing 'GOOG_USER_PROJECT_HEADER' constant from 'src/apiv2.ts' instead of hardcoding the string literal, ensuring consistency and adherence to the repository's style guide.

Comment thread src/crashlytics/events.ts Outdated
method: "GET",
headers: {
"Content-Type": "application/json",
"x-goog-user-project": requestProjectNumber,

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.

medium

The header name "x-goog-user-project" is a repeated string that is already defined as a constant GOOG_USER_PROJECT_HEADER in src/apiv2.ts. To adhere to the repository style guide regarding extracting repeated strings and reusing existing utilities, please import and use GOOG_USER_PROJECT_HEADER instead of hardcoding the string literal here and in other Crashlytics API files.

References
  1. Define static IDs, default timeouts, millisecond offsets, and repeated strings as top-level constants (UPPER_SNAKE_CASE) instead of inlining magic values inside functions. (link)
  2. Reuse or extend existing utilities: Check imported modules, the immediate subsystem, and src/utils.ts first; reuse or extend existing helpers rather than writing bespoke inline logic. (link)

Comment thread src/crashlytics/quotaProject.spec.ts Outdated
import { expect } from "chai";
import * as sinon from "sinon";

import { ClientRequestOptions } from "../apiv2";

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.

medium

Import GOOG_USER_PROJECT_HEADER from ../apiv2 to avoid hardcoding the "x-goog-user-project" header string, adhering to the repository style guide.

Suggested change
import { ClientRequestOptions } from "../apiv2";
import { ClientRequestOptions, GOOG_USER_PROJECT_HEADER } from "../apiv2";
References
  1. Define static IDs, default timeouts, millisecond offsets, and repeated strings as top-level constants (UPPER_SNAKE_CASE) instead of inlining magic values inside functions. (link)

Comment thread src/crashlytics/quotaProject.spec.ts Outdated
expect(requestStub).to.have.been.calledOnce;
const options = requestStub.firstCall.args[0] as ClientRequestOptions<unknown>;
const headers = options.headers;
expect(headers).to.include({ "x-goog-user-project": projectNumber });

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.

medium

Use the imported GOOG_USER_PROJECT_HEADER constant instead of the hardcoded "x-goog-user-project" string.

Suggested change
expect(headers).to.include({ "x-goog-user-project": projectNumber });
expect(headers).to.include({ [GOOG_USER_PROJECT_HEADER]: projectNumber });
References
  1. Define static IDs, default timeouts, millisecond offsets, and repeated strings as top-level constants (UPPER_SNAKE_CASE) instead of inlining magic values inside functions. (link)

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@ac016ce). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #11547   +/-   ##
=======================================
  Coverage        ?   61.05%           
=======================================
  Files           ?      870           
  Lines           ?    51015           
  Branches        ?    10285           
=======================================
  Hits            ?    31145           
  Misses          ?    18750           
  Partials        ?     1120           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

The Crashlytics API rejects user credentials without a quota project, so
every Crashlytics MCP tool failed with "requires a quota project". Send the
app's project number as x-goog-user-project on all Crashlytics requests,
as generateAlertPolicy already does. GOOGLE_CLOUD_QUOTA_PROJECT still
overrides it.

Fixes firebase#11545
@yeegz
yeegz force-pushed the fix/11545-crashlytics-quota-header branch from 1a5243b to 19c66be Compare November 19, 2026 07:44

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MCP] Crashlytics tools 403 "requires a quota project": client never sends x-goog-user-project

3 participants