Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

fix(api): Update scrape request logs (#5357)

Abimael Martelle0b48886c3f3
diff --git a/apps/api/src/scraper/scrapeURL/engines/fire-engine/index.ts b/apps/api/src/scraper/scrapeURL/engines/fire-engine/index.ts
index e22b92233..1bd425f05 100644
--- a/apps/api/src/scraper/scrapeURL/engines/fire-engine/index.ts
+++ b/apps/api/src/scraper/scrapeURL/engines/fire-engine/index.ts
@@ -49,6 +49,7 @@ function fireEngineHandoffEligible(meta: Meta): boolean {
}
import { fireEngineDelete } from "./delete";
import { MockState } from "../../lib/mock";
+import { redactRequestBodyForLog } from "../../lib/fetch";
import { getInnerJson } from "@mendable/firecrawl-rs";
import { hasFormatOfType } from "../../../../lib/format-utils";
import { InternalAction } from "../../../../controllers/v1/types";
@@ -541,7 +542,7 @@ export async function scrapeURLWithFireEngineChromeCDP(
meta,
meta.logger.child({
method: "scrapeURLWithFireEngineChromeCDP/callFireEngine",
- request,
+ request: redactRequestBodyForLog(request),
}),
request,
meta.mock,
@@ -752,7 +753,7 @@ export async function scrapeURLWithFireEngineTLSClient(
meta,
meta.logger.child({
method: "scrapeURLWithFireEngineTLSClient/callFireEngine",
- request,
+ request: redactRequestBodyForLog(request),
}),
request,
meta.mock,
diff --git a/apps/api/src/scraper/scrapeURL/lib/__tests__/fetch.test.ts b/apps/api/src/scraper/scrapeURL/lib/__tests__/fetch.test.ts
index 8528b0c4d..5d1f30e7b 100644
--- a/apps/api/src/scraper/scrapeURL/lib/__tests__/fetch.test.ts
+++ b/apps/api/src/scraper/scrapeURL/lib/__tests__/fetch.test.ts
@@ -1,4 +1,8 @@
-import { redactHeaders, robustFetch } from "../fetch";
+import {
+ redactHeaders,
+ redactRequestBodyForLog,
+ robustFetch,
+} from "../fetch";
import type { MockState } from "../mock";
const secretHeaders = {
@@ -10,6 +14,12 @@ const secretHeaders = {
"api-key": "secret-value",
"X-Auth-Token": "secret-value",
"X-Client-Secret": "secret-value",
+ "X-Password": "secret-value",
+ "X-Credential": "secret-value",
+ "X-Session-Id": "secret-value",
+ x_api_key: "secret-value",
+ "X-Signature": "secret-value",
+ "X-JWT": "secret-value",
"Content-Type": "application/json",
"User-Agent": "firecrawl",
};
@@ -58,6 +68,12 @@ describe("redactHeaders", () => {
"api-key": "[REDACTED]",
"X-Auth-Token": "[REDACTED]",
"X-Client-Secret": "[REDACTED]",
+ "X-Password": "[REDACTED]",
+ "X-Credential": "[REDACTED]",
+ "X-Session-Id": "[REDACTED]",
+ x_api_key: "[REDACTED]",
+ "X-Signature": "[REDACTED]",
+ "X-JWT": "[REDACTED]",
"Content-Type": "application/json",
"User-Agent": "firecrawl",
});
@@ -68,6 +84,72 @@ describe("redactHeaders", () => {
});
});
+const secretActions = [
+ { type: "wait", milliseconds: 1000 },
+ { type: "click", selector: "#password", all: false },
+ { type: "write", text: "secret-value" },
+ { type: "press", key: "Enter" },
+ {
+ type: "executeJavascript",
+ script: "window.token = 'secret-value'",
+ metadata: { __firecrawl_internal: true },
+ },
+];
+
+describe("redactRequestBodyForLog", () => {
+ it("redacts credential headers and secret-carrying action payloads", () => {
+ const body = {
+ url: "https://example.com/login",
+ engine: "chrome-cdp",
+ timeout: 30000,
+ mobileProxy: true,
+ headers: secretHeaders,
+ actions: secretActions,
+ };
+
+ const redacted = redactRequestBodyForLog(body);
+
+ expect(redacted).toEqual({
+ url: "https://example.com/login",
+ engine: "chrome-cdp",
+ timeout: 30000,
+ mobileProxy: true,
+ headers: redactHeaders(secretHeaders),
+ actions: [
+ { type: "wait", milliseconds: 1000 },
+ { type: "click", selector: "#password", all: false },
+ { type: "write", text: "[REDACTED]" },
+ { type: "press", key: "Enter" },
+ {
+ type: "executeJavascript",
+ script: "[REDACTED]",
+ metadata: { __firecrawl_internal: true },
+ },
+ ],
+ });
+ expect(JSON.stringify(redacted)).not.toContain("secret-value");
+ });
+
+ it("does not mutate the body that is sent", () => {
+ const body = {
+ headers: { Authorization: "Bearer secret-value" },
+ actions: [{ type: "write", text: "secret-value" }],
+ };
+
+ redactRequestBodyForLog(body);
+
+ expect(body.headers.Authorization).toBe("Bearer secret-value");
+ expect(body.actions[0].text).toBe("secret-value");
+ });
+
+ it("passes through bodies without headers or actions", () => {
+ const body = { url: "https://example.com", engine: "tlsclient" };
+ expect(redactRequestBodyForLog(body)).toEqual(body);
+ expect(redactRequestBodyForLog(undefined)).toBeUndefined();
+ expect(redactRequestBodyForLog("raw")).toBe("raw");
+ });
+});
+
describe("robustFetch error logging", () => {
it.each([
["a failure status", mockWith(500, "{}"), undefined],
@@ -120,4 +202,24 @@ describe("robustFetch error logging", () => {
expect(cause.params.body.url).toBe("https://example.com");
expect(cause.params.body.headers["User-Agent"]).toBe("firecrawl");
});
+
+ it("redacts action payloads forwarded inside the request body", async () => {
+ const logger = makeLogger();
+
+ const cause = await captureCause(
+ robustFetch({
+ url: "https://upstream.test/run",
+ method: "POST",
+ body: { url: "https://example.com", actions: secretActions },
+ logger,
+ mock: mockWith(500, "{}"),
+ }),
+ );
+
+ const serialized = JSON.stringify([cause, logger.debug.mock.calls]);
+ expect(serialized).not.toContain("secret-value");
+ expect(cause.params.body.actions.map((a: any) => a.type)).toEqual(
+ secretActions.map(a => a.type),
+ );
+ });
});
diff --git a/apps/api/src/scraper/scrapeURL/lib/fetch.ts b/apps/api/src/scraper/scrapeURL/lib/fetch.ts
index 524dc4b71..834b8f71b 100644
--- a/apps/api/src/scraper/scrapeURL/lib/fetch.ts
+++ b/apps/api/src/scraper/scrapeURL/lib/fetch.ts
@@ -26,8 +26,11 @@ type RobustFetchParams<Schema extends z.Schema<any>> = {
useCacheableLookup?: boolean;
};
+// Logs only, so err on the side of redacting: any header whose name looks like
+// it could carry a credential (Authorization, X-Auth-*, Cookie, X-Password,
+// X-Session-Id, X-Api-Key, X-Signature, ...).
const SENSITIVE_HEADER =
- /^(authorization|proxy-authorization|cookie|set-cookie|x-api-key|api-key)$|token|secret/i;
+ /auth|cookie|api[-_]?key|token|secret|passw|credential|session|signature|jwt/i;
export function redactHeaders(
headers: Record<string, string> | undefined,
@@ -41,6 +44,48 @@ export function redactHeaders(
);
}
+// Action fields that carry user-typed text or script bodies. `write` text can
+// be a password; `executeJavascript` scripts can embed tokens (and the branding
+// script is large), so neither belongs in logs.
+const SENSITIVE_ACTION_FIELDS = ["text", "script"] as const;
+
+/**
+ * A copy of a scrape request body that is safe to log: credential headers and
+ * secret-carrying action payloads are replaced with "[REDACTED]".
+ */
+export function redactRequestBodyForLog<T>(body: T): T {
+ if (
+ body === null ||
+ typeof body !== "object" ||
+ Array.isArray(body) ||
+ body instanceof FormData
+ ) {
+ return body;
+ }
+ const { headers, actions } = body as {
+ headers?: unknown;
+ actions?: unknown;
+ };
+ return {
+ ...body,
+ ...(headers !== null && typeof headers === "object"
+ ? { headers: redactHeaders(headers as Record<string, string>) }
+ : {}),
+ ...(Array.isArray(actions)
+ ? {
+ actions: actions.map(action => {
+ if (action === null || typeof action !== "object") return action;
+ const redacted: Record<string, unknown> = { ...action };
+ for (const field of SENSITIVE_ACTION_FIELDS) {
+ if (field in redacted) redacted[field] = "[REDACTED]";
+ }
+ return redacted;
+ }),
+ }
+ : {}),
+ };
+}
+
const robustAgent = new Agent({
headersTimeout: 0,
bodyTimeout: 0,
@@ -112,12 +157,7 @@ export async function robustFetch<
const logParams = {
...params,
headers: redactHeaders(headers),
- body:
- logBody?.headers !== null &&
- typeof logBody?.headers === "object" &&
- !(logBody instanceof FormData)
- ? { ...logBody, headers: redactHeaders(logBody.headers) }
- : logBody,
+ body: redactRequestBodyForLog(logBody),
logger: undefined,
};