@fireemu/linux-x64 0.15.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # @fireemu/linux-x64
2
2
 
3
3
  The [fireemu](https://www.npmjs.com/package/fireemu) daemon built for `linux-x64`
4
- (Rust target `x86_64-unknown-linux-musl`), version 0.15.0.
4
+ (Rust target `x86_64-unknown-linux-musl`), version 0.17.0.
5
5
 
6
6
  Statically linked against musl: any glibc or musl distribution, including distroless and Alpine.
7
7
 
package/bin/fireemu CHANGED
Binary file
@@ -0,0 +1,53 @@
1
+ // Withholding an App Check token from a callable that could consume it (specification 13.4).
2
+ //
3
+ // Without the trusted protocol the runner has no `skipTokenVerification`, so the installed
4
+ // onCall wrapper hands a presented `X-Firebase-AppCheck` to the Admin SDK's `verifyToken`, and
5
+ // with `consumeAppCheckToken: true` that call consumes the token against the production App
6
+ // Check API. The daemon's proxy already removes the field for such callables, but a request can
7
+ // reach this runner on other paths too: a task dispatched to a queue a configured manifest named
8
+ // after the callable, for one. So the runner applies the same rule at the one point every path
9
+ // shares, using its own discovery of what the export is, whatever trigger type the daemon
10
+ // assigned to the name.
11
+
12
+ const APP_CHECK_HEADER = "x-firebase-appcheck";
13
+ const TRUSTED_DEBUG_FEATURE = "skipTokenVerification";
14
+
15
+ /// Whether the trusted protocol is active: the daemon turns `skipTokenVerification` on (with
16
+ /// `FIREBASE_DEBUG_MODE`) only when it verifies App Check itself.
17
+ export function tokenVerificationSkipped(env) {
18
+ if (env.FIREBASE_DEBUG_MODE !== "true") return false;
19
+ let features;
20
+ try {
21
+ features = JSON.parse(env.FIREBASE_DEBUG_FEATURES ?? "{}");
22
+ } catch {
23
+ return false;
24
+ }
25
+ return features?.[TRUSTED_DEBUG_FEATURE] === true;
26
+ }
27
+
28
+ /// Whether a request to the export behind `spec` (this runner's own discovery) must not carry
29
+ /// an App Check token: a callable whose `consumeAppCheckToken` is not known to be off, while
30
+ /// App Check is off.
31
+ export function withholdsAppCheckToken(spec, env) {
32
+ const trigger = spec?.trigger;
33
+ const mayConsume =
34
+ trigger?.type === "http" &&
35
+ trigger.callable === true &&
36
+ trigger.consumeAppCheckToken !== "disabled";
37
+ return mayConsume && !tokenVerificationSkipped(env);
38
+ }
39
+
40
+ /// Removes every `X-Firebase-AppCheck` field from a Node request, from both `headers` and
41
+ /// `rawHeaders`.
42
+ export function removeAppCheckToken(req) {
43
+ delete req.headers[APP_CHECK_HEADER];
44
+ if (Array.isArray(req.rawHeaders)) {
45
+ const kept = [];
46
+ for (let i = 0; i + 1 < req.rawHeaders.length; i += 2) {
47
+ if (String(req.rawHeaders[i]).toLowerCase() !== APP_CHECK_HEADER) {
48
+ kept.push(req.rawHeaders[i], req.rawHeaders[i + 1]);
49
+ }
50
+ }
51
+ req.rawHeaders = kept;
52
+ }
53
+ }
@@ -19,6 +19,7 @@ import { createRuntimeClock } from "./clock.mjs";
19
19
  import { execFileSync, spawn } from "node:child_process";
20
20
  import { url as inspectorUrl } from "node:inspector";
21
21
  import { instrumentCallables } from "./callable-app-check.mjs";
22
+ import { removeAppCheckToken, withholdsAppCheckToken } from "./app-check-token.mjs";
22
23
  import { blockingFailure } from "./blocking-error.mjs";
23
24
  import { blockingEvent, loadIdentityParsers, portedIdentityParsers } from "./blocking-event.mjs";
24
25
  import { blockingResult } from "./blocking-response.mjs";
@@ -1320,6 +1321,9 @@ async function makeHttpServer(functions, manifest) {
1320
1321
  .send(`no HTTP function ${req.params.project}/${req.params.region}/${req.params.name}`);
1321
1322
  return;
1322
1323
  }
1324
+ // Without App Check a callable that could consume a token never sees one, whichever path
1325
+ // the request took here (spec 13.4; app-check-token.mjs).
1326
+ if (withholdsAppCheckToken(spec, process.env)) removeAppCheckToken(req);
1323
1327
  // The function sees the path relative to its mount point: drop the three route segments.
1324
1328
  const original = req.url;
1325
1329
  const queryAt = original.indexOf("?");
@@ -1508,11 +1512,22 @@ async function invoke(functions, manifest, msg) {
1508
1512
  await fn({ ...msg.event, data: storageObjectInRecordedOrder(msg.event.data) });
1509
1513
  return;
1510
1514
  case "pubsub":
1511
- // A custom event reaches the handler as the CloudEvent itself, exactly as the official
1512
- // Eventarc emulator POSTs it to the functions emulator.
1513
- case "eventarc":
1514
1515
  await fn(msg.event);
1515
1516
  return;
1517
+ case "eventarc": {
1518
+ // Eventarc Standard delivers binary CloudEvents. The production JSON body parser
1519
+ // admits objects and arrays before invoking the function; the emulator sends a
1520
+ // structured envelope instead. Strict conversion omits datacontenttype for JSON.
1521
+ const contentType = msg.event.datacontenttype;
1522
+ const jsonBody = contentType === undefined ||
1523
+ (typeof contentType === "string" && /^application\/json(?:\s*;|$)/i.test(contentType.trim()));
1524
+ if (strictProfile() && jsonBody && Object.hasOwn(msg.event, "data") &&
1525
+ (msg.event.data === null || typeof msg.event.data !== "object")) {
1526
+ throw new SyntaxError("Eventarc binary JSON body must be an object or array");
1527
+ }
1528
+ await fn(msg.event);
1529
+ return;
1530
+ }
1516
1531
  case "auth":
1517
1532
  throw new Error("Auth user events are delivered to v1 auth.user() handlers only");
1518
1533
  default:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fireemu/linux-x64",
3
- "version": "0.15.0",
3
+ "version": "0.17.0",
4
4
  "description": "The fireemu daemon for linux-x64",
5
5
  "homepage": "https://github.com/t-k/fireemu#readme",
6
6
  "repository": {