Skip to content

An open-source, faster Devin alternative

TypeScript

fix(edge): redact request secrets and validate budgets

Igor Zalutski413cddbc5734
diff --git a/cloudflare-workers/log-tail/src/index.test.ts b/cloudflare-workers/log-tail/src/index.test.ts
index c5a6ed67..e36803db 100644
--- a/cloudflare-workers/log-tail/src/index.test.ts
+++ b/cloudflare-workers/log-tail/src/index.test.ts
@@ -22,7 +22,10 @@ test("records a silent HTTP 5xx even when the invocation outcome is ok", async (
outcome: "ok",
eventTimestamp: Date.parse("2026-07-13T20:00:00Z"),
event: {
- request: { method: "POST", url: "https://dispatch.test/agents/example/session" },
+ request: {
+ method: "POST",
+ url: "https://user:[email protected]/agents/example/session?token=secret#fragment",
+ },
response: { status: 500 },
},
logs: [],
@@ -37,6 +40,9 @@ test("records a silent HTTP 5xx even when the invocation outcome is ok", async (
assert.equal(records[0]?.msg, "worker request returned HTTP 500");
assert.equal(records[0]?.service, "agt_test");
assert.equal(records[0]?.response_status, 500);
+ assert.equal(records[0]?.request_url, "https://dispatch.test/agents/example/session");
+ assert.equal(JSON.stringify(records[0]).includes("secret"), false);
+ assert.equal(JSON.stringify(records[0]).includes("password"), false);
});
test("fails the collector invocation when the durable sink rejects a batch", async () => {
diff --git a/cloudflare-workers/log-tail/src/index.ts b/cloudflare-workers/log-tail/src/index.ts
index 5ff30edf..bb5b9344 100644
--- a/cloudflare-workers/log-tail/src/index.ts
+++ b/cloudflare-workers/log-tail/src/index.ts
@@ -54,6 +54,22 @@ function safeStringify(v: unknown): string {
catch { return String(v); }
}
+// Request query strings can carry browser client tokens (`?token=...`). Keep
+// the route useful for diagnostics without copying credentials into Axiom.
+function requestUrlForLogs(value?: string): string | undefined {
+ if (!value) return undefined;
+ try {
+ const url = new URL(value);
+ url.username = "";
+ url.password = "";
+ url.search = "";
+ url.hash = "";
+ return url.toString();
+ } catch {
+ return undefined;
+ }
+}
+
// Map CF console level → Axiom-friendly level string matching what our Go
// slog handler emits ("INFO", "WARN", "ERROR", "DEBUG").
function level(l: TraceLog["level"]): string {
@@ -76,7 +92,7 @@ export default {
cell_id: "cf-edge",
region: "global",
outcome: item.outcome,
- request_url: item.event?.request?.url,
+ request_url: requestUrlForLogs(item.event?.request?.url),
request_method: item.event?.request?.method,
response_status: item.event?.response?.status,
cron: item.event?.cron,
diff --git a/cloudflare-workers/oc-gateway/src/index.ts b/cloudflare-workers/oc-gateway/src/index.ts
index 24afd01e..12259dcf 100644
--- a/cloudflare-workers/oc-gateway/src/index.ts
+++ b/cloudflare-workers/oc-gateway/src/index.ts
@@ -218,6 +218,13 @@ function parseUsdMicro(usd?: string): number | null {
return Math.round(n * 1e6);
}
+function parseAdminBudgetMicro(value: unknown): number | null | undefined {
+ if (value === null) return null;
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0) return undefined;
+ const micro = Math.round(value * 1e6);
+ return Number.isSafeInteger(micro) ? micro : undefined;
+}
+
// ── Control-plane admin routes (guarded by GATEWAY_ADMIN_SECRET) ──
async function admin(req: Request, env: Env, url: URL): Promise<Response> {
if (!env.GATEWAY_ADMIN_SECRET) return json({ error: { type: "not_found" } }, 404);
@@ -233,7 +240,10 @@ async function admin(req: Request, env: Env, url: URL): Promise<Response> {
if (!org || !agt || !ORG_ID.test(org) || !AGENT_ID.test(agt)) {
return json({ error: { type: "bad_request", message: "canonical bare org UUID and agent id required" } }, 400);
}
- const budgetMicro = body.budget_usd === null ? null : parseUsdMicro(String(body.budget_usd));
+ const budgetMicro = parseAdminBudgetMicro(body.budget_usd);
+ if (budgetMicro === undefined) {
+ return json({ error: { type: "bad_request", message: "budget_usd must be a non-negative finite number or null" } }, 400);
+ }
const stub = env.SPEND_COUNTER.get(env.SPEND_COUNTER.idFromName(`agt:${org}:${agt}`));
const r = await stub.fetch("https://do/provision", { method: "POST", body: JSON.stringify({ budget_micro: budgetMicro }) });
return new Response(r.body, { status: r.status, headers: { "content-type": "application/json" } });
diff --git a/cloudflare-workers/oc-gateway/test/integration.test.ts b/cloudflare-workers/oc-gateway/test/integration.test.ts
index 243b13de..5f644a3b 100644
--- a/cloudflare-workers/oc-gateway/test/integration.test.ts
+++ b/cloudflare-workers/oc-gateway/test/integration.test.ts
@@ -262,4 +262,30 @@ describe("gateway on-path flow (resolved seam)", () => {
expect(r1.status).toBe(200);
expect(r2.status).toBe(402);
});
+
+ it("admin: a zero budget is a real cap, while missing or invalid values are rejected", async () => {
+ vi.stubGlobal("fetch", mockFetch(0.01));
+ const { env } = mkEnv({ GATEWAY_ADMIN_SECRET: "adm" });
+ const headers = { authorization: "Bearer adm", "content-type": "application/json" };
+ const endpoint = "https://gw.test/admin/agent/budget";
+
+ for (const budget_usd of [undefined, -1, "1", Number.MAX_VALUE]) {
+ const invalid = await worker.fetch(new Request(endpoint, {
+ method: "POST",
+ headers,
+ body: JSON.stringify({ org: ORG_ID, agt: AGENT_ID, ...(budget_usd === undefined ? {} : { budget_usd }) }),
+ }), env, ctx());
+ expect(invalid.status).toBe(400);
+ }
+
+ const provisioned = await worker.fetch(new Request(endpoint, {
+ method: "POST",
+ headers,
+ body: JSON.stringify({ org: ORG_ID, agt: AGENT_ID, budget_usd: 0 }),
+ }), env, ctx());
+ expect(provisioned.status).toBe(200);
+
+ const blocked = await worker.fetch(post(await mint(), "ses_zero"), env, ctx());
+ expect(blocked.status).toBe(402);
+ });
});