Skip to content

Commit 5c58e02

Browse files
steipetehartmark
andcommitted
fix(comfy): redact reflected request credentials across generation failures
Reuse the Ollama exact-header redactor through the provider HTTP SDK, scrub structured and truncated diagnostics before retaining them, and cover decoded Basic credentials observed in real ComfyUI proxy failures. Preserve optional header and seed behavior while consolidating tests and documenting the shared boundary. Co-authored-by: Markus Hartung <[email protected]>
1 parent f488c2a commit 5c58e02

14 files changed

Lines changed: 393 additions & 345 deletions

‎config/assertion-safety-baseline.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ extensions/codex/src/web-search-provider.runtime.ts 1
270270
extensions/codex/src/web-search-provider.ts 1
271271
extensions/cohere/provider-catalog.ts 3
272272
extensions/cohere/stream.ts 2
273-
extensions/comfy/workflow-runtime.ts 3
273+
extensions/comfy/workflow-runtime.ts 2
274274
extensions/copilot-proxy/index.ts 1
275275
extensions/copilot/harness.ts 8
276276
extensions/copilot/src/attempt-config.ts 16

‎docs/plugins/sdk-provider-plugins.md‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,14 @@ catalog, API-key auth, and dynamic model resolution.
801801

802802
Use `assertOkOrThrowProviderError(...)` for provider HTTP failures so
803803
plugins share capped error-body reads, JSON error parsing, and
804-
request-id suffixes.
804+
request-id suffixes. Pass `{ requestHeaders: headers }` as its third
805+
argument when requests carry credentials: this redacts reflected header
806+
values before error details and metadata are retained. Pass the same
807+
option to `readProviderJsonResponse(...)` to omit unsafe parser excerpts.
808+
For provider-specific failure payloads, use
809+
`redactProviderResponseErrorText(text, headers)` or the bounded
810+
`readProviderResponseErrorText(response, limitBytes, headers)` helper
811+
from the same SDK entrypoint.
805812
</Tab>
806813
<Tab title="Realtime transcription">
807814
Prefer `createRealtimeTranscriptionWebSocketSession(...)` - the shared

‎docs/providers/comfy.md‎

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ The plugin is entirely workflow-driven: OpenClaw does not map generic `size`,
1818
`aspectRatio`, `resolution`, `durationSeconds`, or TTS-style controls onto
1919
your graph.
2020

21-
| Property | Detail |
22-
| ------------ | -------------------------------------------------------------------------------- |
23-
| Provider | `comfy` |
24-
| Model | `comfy/workflow` |
25-
| Shared tools | `image_generate`, `video_generate`, `music_generate` |
26-
| Auth | None for local ComfyUI; `COMFY_API_KEY` or `COMFY_CLOUD_API_KEY` for Comfy Cloud |
27-
| API | ComfyUI `/prompt` / `/history` / `/view`; Comfy Cloud `/api/*` |
21+
| Property | Detail |
22+
| ------------ | ------------------------------------------------------------------------------------------ |
23+
| Provider | `comfy` |
24+
| Model | `comfy/workflow` |
25+
| Shared tools | `image_generate`, `video_generate`, `music_generate` |
26+
| Auth | Optional `headers` for local HTTP auth; `COMFY_API_KEY` or `COMFY_CLOUD_API_KEY` for cloud |
27+
| API | ComfyUI `/prompt` / `/history` / `/view`; Comfy Cloud `/api/*` |
2828

2929
## What it supports
3030

@@ -211,13 +211,21 @@ Comfy supports shared top-level connection settings plus per-capability workflow
211211

212212
### Shared keys
213213

214-
| Key | Type | Description |
215-
| --------------------- | ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
216-
| `mode` | `"local"` or `"cloud"` | Connection mode. Defaults to `"local"`. |
217-
| `baseUrl` | string | Defaults to `http://127.0.0.1:8188` for local or `https://cloud.comfy.org` for cloud. |
218-
| `apiKey` | string | Optional inline key, alternative to `COMFY_API_KEY` / `COMFY_CLOUD_API_KEY` env vars. |
219-
| `allowPrivateNetwork` | boolean | Allow a private/LAN `baseUrl` in cloud mode or a local private-DNS FQDN. |
220-
| `headers` | object (string → string or [secret reference](/gateway/configuration-reference#secrets)) | Extra headers sent with every request, e.g. `Authorization` for a ComfyUI instance behind HTTP auth. Each value accepts a literal string or a SecretRef, same as `apiKey`. Merged over the plugin's own headers; a key set here always wins, except a configured `Content-Type` is ignored on image-upload requests specifically, since the multipart form boundary there must come from the runtime. A header pointed at an unresolvable SecretRef fails the request rather than sending it unauthenticated. |
214+
| Key | Type | Description |
215+
| --------------------- | ---------------------- | ------------------------------------------------------------------------------------- |
216+
| `mode` | `"local"` or `"cloud"` | Connection mode. Defaults to `"local"`. |
217+
| `baseUrl` | string | Defaults to `http://127.0.0.1:8188` for local or `https://cloud.comfy.org` for cloud. |
218+
| `apiKey` | string or SecretRef | Optional cloud key, alternative to `COMFY_API_KEY` / `COMFY_CLOUD_API_KEY` env vars. |
219+
| `allowPrivateNetwork` | boolean | Allow a private/LAN `baseUrl` in cloud mode or a local private-DNS FQDN. |
220+
| `headers` | object | Extra request headers; each value accepts a string or SecretRef. |
221+
222+
Use `headers.Authorization` for a ComfyUI instance behind HTTP authentication.
223+
Prefer a [secret reference](/gateway/configuration-reference#secrets) for credentials.
224+
Headers apply to uploads, workflow submissions, polling, and downloads in both
225+
modes. They override default headers case-insensitively, except `Content-Type`
226+
on image uploads: the runtime sets the multipart boundary. An unavailable
227+
header SecretRef fails before any request is sent. Reflected header values are
228+
redacted from response errors.
221229

222230
<Note>
223231
In `local` mode, loopback/private IP literals and single-label service names such as `http://comfyui:8188` work without `allowPrivateNetwork`. Public-looking private-DNS FQDNs such as `https://comfy.local.example.com` require `allowPrivateNetwork: true`. Private-origin trust stays scoped to the configured scheme, hostname, and port; local redirects cannot leave the configured hostname, while cloud redirects to public CDNs are checked with the default SSRF policy.

‎extensions/comfy/image-generation-provider.test.ts‎

Lines changed: 51 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
// Comfy tests cover image generation provider plugin behavior.
22
import type { LookupAddress } from "node:dns";
3-
import fs from "node:fs/promises";
4-
import { tmpdir } from "node:os";
5-
import { join } from "node:path";
63
import { MAX_TIMER_TIMEOUT_MS } from "openclaw/plugin-sdk/number-runtime";
74
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
85
import { buildComfyImageGenerationProvider } from "./image-generation-provider.js";
@@ -15,6 +12,13 @@ import {
1512
} from "./test-helpers.js";
1613
import { isComfyCapabilityConfigured } from "./workflow-runtime.js";
1714

15+
const randomIntMock = vi.hoisted(() => vi.fn<(max: number) => number>());
16+
17+
vi.mock("node:crypto", async (importOriginal) => {
18+
const actual = await importOriginal<typeof import("node:crypto")>();
19+
return { ...actual, randomInt: randomIntMock.mockImplementation(actual.randomInt) };
20+
});
21+
1822
type FetchWithSsrFGuard = (typeof import("openclaw/plugin-sdk/ssrf-runtime"))["fetchWithSsrFGuard"];
1923

2024
const { fetchWithSsrFGuardMock, ssrfGuardState } = vi.hoisted(() => ({
@@ -70,13 +74,13 @@ function parseJsonBody(call: number): Record<string, unknown> {
7074
return parseComfyJsonBody(fetchWithSsrFGuardMock, call);
7175
}
7276

73-
function seedFromBody(body: Record<string, unknown>, nodeId: string): number {
74-
const prompt = body.prompt as Record<string, { inputs: { seed: number } }>;
77+
function seedFromBody(body: Record<string, unknown>, nodeId: string, inputName = "seed") {
78+
const prompt = body.prompt as Record<string, { inputs: Record<string, number> }>;
7579
const node = prompt[nodeId];
7680
if (!node) {
7781
throw new Error(`expected seed node "${nodeId}" in submitted workflow`);
7882
}
79-
return node.inputs.seed;
83+
return node.inputs[inputName];
8084
}
8185

8286
function mockLocalImageResponses(promptId = "local-prompt-1") {
@@ -467,177 +471,57 @@ describe("comfy image-generation provider", () => {
467471
});
468472
});
469473

470-
it("sends configured headers to a local workflow, e.g. Basic auth for a gated instance", async () => {
471-
mockLocalImageResponses("auth-prompt-1");
472-
473-
const provider = buildComfyImageGenerationProvider();
474-
await provider.generateImage({
475-
provider: "comfy",
476-
model: "workflow",
477-
prompt: "draw a lobster",
478-
cfg: buildComfyConfig({
479-
...testWorkflowConfig(),
480-
headers: { Authorization: "Basic cGluZzpzZWNyZXQ=" },
481-
}),
482-
});
483-
484-
const submitRequest = fetchRequest(1);
485-
const submitHeaders = new Headers(submitRequest.init?.headers);
486-
expect(submitHeaders.get("authorization")).toBe("Basic cGluZzpzZWNyZXQ=");
487-
expect(submitHeaders.get("content-type")).toBe("application/json");
488-
});
489-
490-
it("ignores a non-object headers config value instead of throwing", async () => {
491-
mockLocalImageResponses("headers-ignore-1");
492-
493-
const provider = buildComfyImageGenerationProvider();
494-
await provider.generateImage({
495-
provider: "comfy",
496-
model: "workflow",
497-
prompt: "draw a lobster",
498-
cfg: buildComfyConfig({
499-
...testWorkflowConfig(),
500-
headers: "not-an-object",
501-
}),
502-
});
503-
504-
const submitHeaders = new Headers(fetchRequest(1).init?.headers);
505-
expect(submitHeaders.get("content-type")).toBe("application/json");
506-
});
507-
508-
it("resolves an env-backed SecretRef header value, same path as apiKey", async () => {
509-
mockLocalImageResponses("auth-secretref-1");
510-
vi.stubEnv("COMFY_TEST_AUTH_HEADER", "Basic ZW52LXNlY3JldA==");
511-
512-
const provider = buildComfyImageGenerationProvider();
513-
await provider.generateImage({
514-
provider: "comfy",
515-
model: "workflow",
516-
prompt: "draw a lobster",
517-
cfg: buildComfyConfig({
518-
...testWorkflowConfig(),
519-
headers: {
520-
Authorization: { source: "env", provider: "default", id: "COMFY_TEST_AUTH_HEADER" },
521-
},
522-
}),
523-
});
524-
525-
const submitHeaders = new Headers(fetchRequest(1).init?.headers);
526-
expect(submitHeaders.get("authorization")).toBe("Basic ZW52LXNlY3JldA==");
527-
});
528-
529-
it("throws instead of silently dropping a header pointed at an unresolvable secret", async () => {
530-
const provider = buildComfyImageGenerationProvider();
531-
await expect(
532-
provider.generateImage({
533-
provider: "comfy",
534-
model: "workflow",
535-
prompt: "draw a lobster",
536-
cfg: buildComfyConfig({
537-
...testWorkflowConfig(),
538-
headers: {
539-
Authorization: { source: "env", provider: "default", id: "COMFY_TEST_MISSING_ENV" },
540-
},
541-
}),
542-
}),
543-
).rejects.toThrow(/unavailable secret/);
544-
expect(fetchWithSsrFGuardMock).not.toHaveBeenCalled();
545-
});
546-
547-
it("resolves a non-env (file-backed) SecretRef header value, not just env", async () => {
548-
mockLocalImageResponses("auth-file-secretref-1");
549-
// A dedicated mkdtemp dir gets restrictive (0700) permissions by
550-
// default; writing straight into the shared, world-writable tmpdir()
551-
// root fails readSecureFile's containing-directory security check.
552-
const tmpDir = await fs.mkdtemp(join(tmpdir(), "comfy-header-secret-"));
553-
const tmpFile = join(tmpDir, "token.txt");
554-
await fs.writeFile(tmpFile, "Basic ZmlsZS1zZWNyZXQ=");
555-
await fs.chmod(tmpFile, 0o600);
556-
try {
557-
const provider = buildComfyImageGenerationProvider();
558-
await provider.generateImage({
559-
provider: "comfy",
560-
model: "workflow",
561-
prompt: "draw a lobster",
562-
cfg: {
563-
...buildComfyConfig({
564-
...testWorkflowConfig(),
565-
headers: {
566-
Authorization: { source: "file", provider: "comfyheaderfile", id: "value" },
567-
},
568-
}),
569-
secrets: {
570-
providers: {
571-
comfyheaderfile: { source: "file", path: tmpFile, mode: "singleValue" },
572-
},
573-
},
574-
} as never,
474+
it.each([
475+
["literal", "Basic fixture", true],
476+
["available env", { source: "env", provider: "default", id: "COMFY_HEADER_AVAILABLE" }, true],
477+
["missing env", { source: "env", provider: "default", id: "COMFY_HEADER_MISSING" }, false],
478+
["file ref", { source: "file", provider: "comfyfile", id: "value" }, true],
479+
])("checks %s header availability for every capability", (_label, header, configured) => {
480+
vi.stubEnv("COMFY_HEADER_AVAILABLE", "Basic fixture");
481+
vi.stubEnv("COMFY_HEADER_MISSING", undefined);
482+
for (const capability of ["image", "video", "music"] as const) {
483+
const cfg = buildComfyConfig({
484+
[capability]: testWorkflowConfig(),
485+
headers: { Authorization: header },
575486
});
576-
577-
const submitHeaders = new Headers(fetchRequest(1).init?.headers);
578-
expect(submitHeaders.get("authorization")).toBe("Basic ZmlsZS1zZWNyZXQ=");
579-
} finally {
580-
await fs.rm(tmpDir, { recursive: true, force: true });
487+
expect(isComfyCapabilityConfigured({ cfg, capability })).toBe(configured);
581488
}
582489
});
583490

584-
it("hides a local capability whose header SecretRef cannot be confirmed available", () => {
585-
const cfg = buildComfyConfig({
586-
...testWorkflowConfig(),
587-
headers: {
588-
Authorization: { source: "env", provider: "default", id: "COMFY_TEST_VETO_MISSING_ENV" },
589-
},
590-
});
591-
592-
expect(isComfyCapabilityConfigured({ cfg, capability: "image" })).toBe(false);
593-
});
594-
595-
it("keeps a local capability configured when a header is a literal string", () => {
596-
const cfg = buildComfyConfig({
597-
...testWorkflowConfig(),
598-
headers: { Authorization: "Basic literal" },
599-
});
600-
601-
expect(isComfyCapabilityConfigured({ cfg, capability: "image" })).toBe(true);
602-
});
603-
604-
it("keeps a local capability configured for a non-env SecretRef header, since the async resolver can still resolve it", () => {
605-
const cfg = buildComfyConfig({
606-
...testWorkflowConfig(),
607-
headers: {
608-
Authorization: { source: "file", provider: "comfyheaderfile", id: "value" },
609-
},
610-
});
491+
it.each(["seed", "noise_seed"])(
492+
"injects a new %s without mutating the workflow",
493+
async (seedInputName) => {
494+
randomIntMock.mockReturnValueOnce(0).mockReturnValueOnce(2 ** 48 - 2);
495+
mockLocalImageResponses("seed-prompt-1");
496+
mockLocalImageResponses("seed-prompt-2");
611497

612-
expect(isComfyCapabilityConfigured({ cfg, capability: "image" })).toBe(true);
613-
});
498+
const provider = buildComfyImageGenerationProvider();
499+
const cfg = buildComfyConfig({
500+
workflow: {
501+
"4": { inputs: { seed: 0 } },
502+
"6": { inputs: { text: "" } },
503+
"9": { inputs: {} },
504+
},
505+
promptNodeId: "6",
506+
outputNodeId: "9",
507+
seedNodeId: "4",
508+
seedInputName,
509+
});
614510

615-
it("injects a fresh random seed per submission when seedNodeId is configured", async () => {
616-
mockLocalImageResponses("seed-prompt-1");
617-
mockLocalImageResponses("seed-prompt-2");
511+
await provider.generateImage({ provider: "comfy", model: "workflow", prompt: "first", cfg });
512+
await provider.generateImage({ provider: "comfy", model: "workflow", prompt: "second", cfg });
618513

619-
const provider = buildComfyImageGenerationProvider();
620-
const cfg = buildComfyConfig({
621-
workflow: {
514+
const firstSeed = seedFromBody(parseJsonBody(1), "4", seedInputName);
515+
const secondSeed = seedFromBody(parseJsonBody(4), "4", seedInputName);
516+
expect(firstSeed).toBe(0);
517+
expect(secondSeed).toBe(2 ** 48 - 2);
518+
expect(cfg.plugins?.entries?.comfy?.config?.workflow).toEqual({
622519
"4": { inputs: { seed: 0 } },
623520
"6": { inputs: { text: "" } },
624521
"9": { inputs: {} },
625-
},
626-
promptNodeId: "6",
627-
outputNodeId: "9",
628-
seedNodeId: "4",
629-
});
630-
631-
await provider.generateImage({ provider: "comfy", model: "workflow", prompt: "first", cfg });
632-
await provider.generateImage({ provider: "comfy", model: "workflow", prompt: "second", cfg });
633-
634-
const firstSeed = seedFromBody(parseJsonBody(1), "4");
635-
const secondSeed = seedFromBody(parseJsonBody(4), "4");
636-
expect(Number.isInteger(firstSeed)).toBe(true);
637-
expect(firstSeed).toBeGreaterThanOrEqual(0);
638-
expect(Number.isSafeInteger(firstSeed)).toBe(true);
639-
expect(secondSeed).not.toBe(firstSeed);
640-
});
522+
});
523+
},
524+
);
641525

642526
it("leaves the workflow's baked-in seed untouched when seedNodeId is not configured", async () => {
643527
mockLocalImageResponses("no-seed-prompt-1");

0 commit comments

Comments
 (0)