# Enforce App Check on Firebase Callable Functions from a Linear Issue

Yes. An agent reads the issue, sets enforceAppCheck on each onCall function, tests the rejected and accepted paths with firebase-functions-test and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/add-app-check/firebase-functions/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent starts from the Linear issue and the repository in its own sandbox and reads the functions before it changes how they are called. In a codebase shaped like `Node/quickstarts/callable-functions` in firebase/functions-samples, `functions/index.js` exports two callables built with `onCall` from `firebase-functions/https`: `addnumbers`, which validates `request.data.firstNumber` and `secondNumber` with `Number.isFinite` and throws an `HttpsError` with code `invalid-argument` otherwise, and `addmessage`, which requires `request.auth`, sanitizes `request.data.text` through `sanitizer.js` and pushes it to `/messages` in the Realtime Database. Both are called as `onCall((request) => ...)` with no options object, so a request with no App Check token is served like any other.

`functions/package.json` pins `firebase-functions ^7.4.0` and `firebase-admin ^14.5.0`, runs on Node 24, lints with `eslint .` and `eslint-config-google`, and already lists `firebase-functions-test ^3.5.0` in `devDependencies` with no test file to use it. `firebase.json` sets the codebase name and a `predeploy` lint step. The sibling `test-functions-jest` sample shows the repository's own testing shape: `wrap` from `firebase-functions-test` around an exported function, a Jest spy on `logger`, and `jest` in `package.json` with `NODE_OPTIONS=--experimental-vm-modules`.

The agent changes each `onCall` to take an options object first, `onCall({ enforceAppCheck: true }, (request) => ...)`, so the SDK rejects a request whose App Check token is missing or invalid with an `unauthenticated` error before the handler runs, as `wrapOnCallHandler` in the SDK's `https.ts` does for both cases. For `addmessage`, which writes to the database, it also sets `consumeAppCheckToken: true` so a captured token cannot be replayed. It leaves the existing `request.auth` and argument checks as they are, since App Check says which app is calling and authentication says which user.

Then it writes `index.test.js` with Jest and `firebase-functions-test`: wrapping each function, calling it with a request that carries `app` and a valid `rawRequest` to see the handler run, calling without `app` to see the `unauthenticated` error, and checking that `addnumbers` still adds. It adds `jest` and a `test` script to `package.json`, runs `npm run lint` and `npm test`, runs `firebase emulators:start --only functions` to see the functions load with the new options, and opens a pull request that links the issue.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "A Linear issue labeled agent says: \"Enforce App Check on all callable Cloud Functions so only our registered apps can call them.\" Do the work in this repository: pass enforceAppCheck: true in the options of every onCall function, and consumeAppCheckToken: true on the ones that write data, without changing their existing auth or argument checks. Add Jest tests with firebase-functions-test that cover a request with a valid App Check token and one without, add the test script, run lint and the tests, start the functions emulator once to confirm the functions load, and open a pull request that links back to the issue.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request on its own branch that links the Linear issue. The diff changes each `onCall` call in `functions/index.js` to pass an options object with `enforceAppCheck: true`, adds `consumeAppCheckToken: true` on the writer, adds `functions/index.test.js`, and adds `jest` with a `test` script to `functions/package.json` and its lockfile. The description lists each function and the options it now carries.

The run's record keeps `npm run lint`, the `jest` run with the accepted and rejected cases, and the emulator start showing both functions registered. No deploy happens: the run has no Firebase project credentials, and the pull request says the deploy and the client-side `initializeAppCheck` setup are the reviewer's steps.

Before merging, a reviewer confirms every client app that calls these functions already initializes App Check with reCAPTCHA, Play Integrity or App Attest, since enforcement turns every unregistered caller away at once, and decides whether to roll it out with monitoring first by deploying without `enforceAppCheck` and reading the App Check metrics in the console.

## Run it on every Linear issue labelled agent

In the console, an automation with a `linear` trigger on `linear.issue.labeled` and the label `agent` starts one run per labelled issue, with the issue as its context, in the Project that has the repository. Changes made by an app integration never fire it, so the agent's own updates do not start new runs.

From your own server, the same run is one `POST /o/{org}/sessions` per issue: the repository in `resources`, plus the issue's `https://linear.app/<workspace>/issue/<ID>` URL there too, read through your Linear connection into the prompt. A webhook on the API key posts `run.completed` or `run.failed` when the turn finishes, with the `session_url` to read the pull request link.

## Why run it on Rush?

App Check enforcement is a one-line option with a large blast radius, and the useful check is a test that shows the rejected path and the accepted path side by side. The sandbox installs the functions, runs Jest with `firebase-functions-test` and starts the emulator, and keeps that output with the run, without a Firebase project or a deploy.

A labelled issue becomes a pull request that touches every callable in the codebase consistently, with tests that keep the option from being dropped in a later edit. A project with several codebases runs one sandbox per codebase at once, each with its own pull request.

## Frequently asked questions

### Will existing users be locked out?

Users of apps that already send App Check tokens are unaffected. Any client that does not initialize App Check, including a script calling the function by URL, gets an `unauthenticated` error. The pull request lists the functions so you can check each caller first.

### Can I monitor before enforcing?

Yes. Without `enforceAppCheck`, requests still carry `request.app` when a token is present, and the Firebase console shows verified and unverified request counts. The agent can open the pull request with the option set to `false` and a comment, if the issue asks for a monitoring period.

### Does it touch HTTP functions built with onRequest?

No. `enforceAppCheck` is an option of callable functions. An `onRequest` function needs an explicit token check in its handler, which the agent writes only when the issue names those functions.

### What about the client side?

The functions change is the server half. Each app needs `initializeAppCheck` with its provider before calling the functions; the pull request describes that step for web, Android and iOS but does not edit app code outside the repository.

## More Firebase Functions jobs

- [Deploy Firebase Functions from GitHub Actions](https://getrush.ai/run/add-deploy-workflow/firebase-functions/)
- [Add Input Validation to Firebase Cloud Functions](https://getrush.ai/run/add-input-validation/firebase-functions/)
- [Add Rate Limiting to Firebase Callable Functions](https://getrush.ai/run/add-rate-limiting/firebase-functions/)

## More jobs like this: Turn a Linear label into a PR

- [Add Article Search to a SvelteKit App from a Linear Issue](https://getrush.ai/run/add-article-search/sveltekit/)
- [Add Asset Checks to a Dagster Project from a Linear Issue](https://getrush.ai/run/add-asset-checks/dagster/)
- [Add Async Username Validation to a Conform Form](https://getrush.ai/run/add-async-username-validation/conform/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
