Skip to content

Commit 272793c

Browse files
committed
fix(parallel): layer configured redactPatterns over header-shape redaction
1 parent b468c09 commit 272793c

2 files changed

Lines changed: 25 additions & 14 deletions

File tree

‎extensions/parallel/src/parallel-web-search-provider.runtime.ts‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
withTrustedWebSearchEndpoint,
2020
writeCachedSearchPayload,
2121
} from "openclaw/plugin-sdk/provider-web-search";
22+
import { redactSensitiveText } from "openclaw/plugin-sdk/security-runtime";
2223
import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
2324
import {
2425
buildParallelCacheKey,
@@ -163,13 +164,14 @@ async function runParallelSearch(params: {
163164
);
164165
// Provider/proxy error pages can reflect request headers (including the
165166
// x-api-key), and the empty-body statusText fallback is server-controlled
166-
// too. Run the composed detail through the canonical tool-payload
167-
// redactor before it lands in user-facing error text: tools mode keeps
168-
// redaction on regardless of log config, and configured
169-
// logging.redactPatterns are merged with the built-in credential
170-
// patterns so organization-specific secrets are stripped as well.
167+
// too. Redact in two passes before the detail lands in user-facing error
168+
// text: the tools-mode pass masks header-shaped reflections while the
169+
// header name is intact (a configured pattern like api[_-]?key would
170+
// otherwise rewrite the name first and hide the shape from the
171+
// structured matcher), then the canonical tool-payload redactor applies
172+
// the operator's logging.redactPatterns on top of the built-in defaults.
171173
throw new Error(
172-
`Parallel API error (${res.status}): ${redactToolPayloadText(detail || res.statusText)}`,
174+
`Parallel API error (${res.status}): ${redactToolPayloadText(redactSensitiveText(detail || res.statusText, { mode: "tools" }))}`,
173175
);
174176
}
175177
return await readProviderJsonResponse<ParallelSearchResponse>(res, "Parallel API", {

‎extensions/parallel/src/parallel-web-search-provider.test.ts‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -503,24 +503,32 @@ describe("parallel web search provider", () => {
503503
expect((error as Error).message).not.toContain(apiKey);
504504
});
505505
it("applies configured logging.redactPatterns to reflected Parallel error bodies", async () => {
506-
// Organization-specific secret shape that no built-in pattern covers.
506+
// Organization-specific secret shape that no built-in pattern covers, plus a
507+
// configured field-name pattern that would rewrite the x-api-key header name
508+
// before the structured matcher can see it — the key value must stay masked.
507509
const orgSecret = "acme-internal-bluefin-042";
510+
const apiKey = "par-live-4c9d2e7ab1f0c9d2e7ab1f0c9d2e7";
508511
const configDir = fs.mkdtempSync(path.join(os.tmpdir(), "parallel-redact-config-"));
509512
const configPath = path.join(configDir, "openclaw.json");
510513
fs.writeFileSync(
511514
configPath,
512-
JSON.stringify({ logging: { redactPatterns: ["acme-internal-[a-z0-9-]+"] } }),
515+
JSON.stringify({
516+
logging: { redactPatterns: ["acme-internal-[a-z0-9-]+", "api[_-]?key"] },
517+
}),
513518
);
514519
vi.stubEnv("OPENCLAW_CONFIG_PATH", configPath);
515520
try {
516521
endpointMockState.responses.push(
517-
new Response(`<html><body>edge failure for ${orgSecret}</body></html>`, {
518-
status: 502,
519-
statusText: "Bad Gateway",
520-
headers: { "Content-Type": "text/html" },
521-
}),
522+
new Response(
523+
`<html><body>edge failure for ${orgSecret} on request with x-api-key: ${apiKey}</body></html>`,
524+
{
525+
status: 502,
526+
statusText: "Bad Gateway",
527+
headers: { "Content-Type": "text/html" },
528+
},
529+
),
522530
);
523-
const error = await paidTool()
531+
const error = await paidTool({ parallel: { apiKey } })
524532
.execute({
525533
objective: `parallel-error-redact-config-${Date.now()}`,
526534
search_queries: ["openclaw"],
@@ -529,6 +537,7 @@ describe("parallel web search provider", () => {
529537
expect(error).toBeInstanceOf(Error);
530538
expect((error as Error).message).toContain("Parallel API error (502)");
531539
expect((error as Error).message).not.toContain(orgSecret);
540+
expect((error as Error).message).not.toContain(apiKey);
532541
} finally {
533542
vi.unstubAllEnvs();
534543
fs.rmSync(configDir, { force: true, recursive: true });

0 commit comments

Comments
 (0)