Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Record redacted cause when Composio authorization fails (#2014)

Regan Bell9c11991a33db
diff --git a/src/api/routes/composio.ts b/src/api/routes/composio.ts
index 97e690dcf..897ff85cf 100644
--- a/src/api/routes/composio.ts
+++ b/src/api/routes/composio.ts
@@ -9,6 +9,9 @@ import { parseRef } from "../../acl/resource-ref.ts";
import { orgId } from "../../config.ts";
import { principalEntitledToScope } from "../../resolution/context-filter.ts";
import { sendJson } from "../http.ts";
+import { redactSecrets } from "../../harness/redact-secrets.ts";
+import { createExactSecretValueMasker } from "../../security/secret-masking.ts";
+import { errMessage, httpFailure, reportFailure } from "../../util/errors.ts";
import { activePrincipal, audit } from "./shared.ts";
import type { ApiCtx, Route } from "./route.ts";
@@ -135,7 +138,7 @@ async function request(ctx: ApiCtx, key: string, path: string, body?: unknown):
redirect: "error",
signal: AbortSignal.timeout(20_000),
});
- if (!response.ok) throw new Error("Composio request failed");
+ if (!response.ok) throw new Error(`Composio request failed: ${await httpFailure(response)}`);
return (await response.json()) as Record<string, unknown>;
}
@@ -260,7 +263,10 @@ async function authorize(ctx: ApiCtx, linkSlack = false): Promise<void> {
accountId: link.connected_account_id,
...(ticket ? { ticket } : {}),
});
- } catch {
+ } catch (error) {
+ // Keep the cause for operators (secret-redacted); the user only sees a generic message.
+ const mask = createExactSecretValueMasker([access.key]);
+ reportFailure("composio: authorize", new Error(mask(redactSecrets(errMessage(error)))), `toolkit=${toolkit}`);
return sendJson(ctx.res, 502, {
error: "composio_authorization_failed",
message: "Could not start authorization. Please try again.",
diff --git a/test/composio-route.test.ts b/test/composio-route.test.ts
index 2cf202ca3..cdb250307 100644
--- a/test/composio-route.test.ts
+++ b/test/composio-route.test.ts
@@ -41,6 +41,7 @@ function fixture() {
calls.push({ url: String(input), init });
const result = replies.shift();
if (result instanceof Error) throw result;
+ if (result instanceof Response) return result;
return Response.json(result);
}) as typeof fetch,
};
@@ -814,3 +815,27 @@ test("linked identities retain provider accounts and Slack status until unlinked
installPrincipalLinks(null);
}
});
+
+test("authorization failures keep a redacted upstream cause for operators", async (t) => {
+ const f = fixture();
+ await f.own();
+ const logged: string[] = [];
+ t.mock.method(console, "error", (...args: unknown[]) => logged.push(args.map(String).join(" ")));
+ f.replies.push(
+ new Response(JSON.stringify({ error: "toolkit not enabled", echoed: "private-key", api_key: "sk-other" }), {
+ status: 400,
+ headers: { "x-request-id": "req_123" },
+ }),
+ );
+ const r = await f.invoke("/v1/composio/authorize", { toolkit: "gmail" });
+ assert.equal(r.status, 502);
+ assert.equal(r.data.error, "composio_authorization_failed");
+ assert.doesNotMatch(r.text, /toolkit not enabled|private-key|req_123/);
+ const report = logged.find((line) => line.includes("composio: authorize"));
+ assert.ok(report, "authorization failure is reported");
+ assert.match(report, /toolkit=gmail/);
+ assert.match(report, /http 400/);
+ assert.match(report, /toolkit not enabled/);
+ assert.match(report, /req_123/);
+ assert.doesNotMatch(report, /private-key|sk-other/);
+});