Skip to content

Commit f5e0640

Browse files
ScottN-PVclaude
andcommitted
fix(server): accept only a short Node error code in a hub failure
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 86ee4b5 commit f5e0640

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎apps/server/src/usage/cliproxyApi.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,22 @@ describe("CLIProxyAPI hub failures", () => {
152152
}),
153153
);
154154

155+
it.effect("ignores a transport code that is not a short Node error code", () =>
156+
Effect.gen(function* () {
157+
const api = yield* unreachableHub(
158+
(request) =>
159+
new HttpClientError.HttpClientError({
160+
reason: new HttpClientError.TransportError({
161+
request,
162+
cause: Object.assign(new Error("odd"), { code: "X".repeat(200) }),
163+
}),
164+
}),
165+
);
166+
const error = yield* Effect.flip(api.readAccounts(config));
167+
expect(error.detail).toBe("The hub management request failed.");
168+
}),
169+
);
170+
155171
it.effect("names the status, not the body, when the hub rejects the request", () =>
156172
Effect.gen(function* () {
157173
const test = HttpClient.make((request) =>

‎apps/server/src/usage/cliproxyApi.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ const UNTRUSTED_CERTIFICATE_CODES = new Set([
103103
const nodeErrorCode = (cause: unknown) => {
104104
for (let error = cause, depth = 0; error instanceof Error && depth < 3; depth += 1) {
105105
const code = (error as { readonly code?: unknown }).code;
106-
if (typeof code === "string" && /^[A-Z0-9_]+$/.test(code)) return code;
106+
if (typeof code === "string" && /^[A-Z0-9_]{1,64}$/.test(code)) return code;
107107
error = error.cause;
108108
}
109109
return undefined;

0 commit comments

Comments
 (0)