From dbe708f85a24ad3772695fc0222a52e6133d0ea4 Mon Sep 17 00:00:00 2001 From: Effect Bot Date: Sun, 22 Nov 2026 21:31:18 +0000 Subject: [PATCH] fix(http-api): mask every client path substitution when param wire keys are unknown --- packages/effect/src/http-api/HttpApiClient.ts | 15 ++++++++++----- .../effect/test/httpapi/HttpApiClient.test.ts | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/packages/effect/src/http-api/HttpApiClient.ts b/packages/effect/src/http-api/HttpApiClient.ts index a62f550f0c..402d01e41a 100644 --- a/packages/effect/src/http-api/HttpApiClient.ts +++ b/packages/effect/src/http-api/HttpApiClient.ts @@ -46,6 +46,7 @@ import type * as HttpApiGroup from "./HttpApiGroup.ts" import type * as HttpApiMiddleware from "./HttpApiMiddleware.ts" import * as HttpApiSchema from "./HttpApiSchema.ts" import * as HttpApiPath from "./internal/path.ts" +import { getRedactedKeys } from "./internal/redactedKeys.ts" /** * The type-safe client shape generated from HTTP API groups, with non-top-level @@ -514,7 +515,9 @@ export const makeClient = `${tag.key}/Client`) const redactedNames = HttpApi.getEndpointRedactedNames(api, group, endpoint) - const redactedParams = HttpApi.getEndpointRedactedParams(api, group, endpoint) + const redactedParams: ReadonlyArray | "*" = getRedactedKeys(endpoint.params) === undefined + ? "*" + : HttpApi.getEndpointRedactedParams(api, group, endpoint) const endpointFn = Effect.fnUntraced(function*( request: { @@ -535,7 +538,7 @@ export const makeClient = const sent = makeUrl(params) httpRequest = HttpClientRequest.setUrl(httpRequest, sent) - if (redactedParams.length > 0) { + if (redactedParams === "*" || redactedParams.length > 0) { redactedPath = { sent: fullPath(sent), redacted: fullPath(makeUrl(params, redactedParams)) } } } @@ -987,17 +990,19 @@ export const urlBuilder = (api: Api, options?: { const compilePath = (path: string, schema: Schema.Top | undefined) => { if (schema === undefined || !path.includes(":")) { - return (_: any, _redacted?: ReadonlyArray) => path + return (_: any, _redacted?: ReadonlyArray | "*") => path } const paramNames = HttpApiPath.getParamNames(schema) - return (params: Record, redacted?: ReadonlyArray) => + return (params: Record, redacted?: ReadonlyArray | "*") => HttpApiPath.replaceParams(path, paramNames, (key, optional) => { const value = params[key] if (value === "." || value === "..") { // dot segments survive encoding and would be resolved by URL normalization throw new Error(`Invalid path parameter: ${key}`) } - if (value !== undefined) return redacted?.includes(key) ? "REDACTED" : encodeURIComponent(value) + if (value !== undefined) { + return redacted === "*" || redacted?.includes(key) ? "REDACTED" : encodeURIComponent(value) + } if (optional) return undefined throw new Error(`Missing path parameter: ${key}`) }) diff --git a/packages/effect/test/httpapi/HttpApiClient.test.ts b/packages/effect/test/httpapi/HttpApiClient.test.ts index cc88794cbc..9734d7eca9 100644 --- a/packages/effect/test/httpapi/HttpApiClient.test.ts +++ b/packages/effect/test/httpapi/HttpApiClient.test.ts @@ -1352,6 +1352,9 @@ describe("HttpApiClient", () => { params: Schema.Struct({ token: Schema.RedactedFromValue(Schema.String), id: Schema.String }).pipe( Schema.encodeKeys({ token: "tok" }) ) + }), + HttpApiEndpoint.get("recordParam", "/record/:tok$1", { + params: Schema.Record(Schema.String, Schema.RedactedFromValue(Schema.String)) }) ) ) @@ -1369,6 +1372,21 @@ describe("HttpApiClient", () => { strictEqual(capture.span.attributes.get("url.path"), "/api/v1/p/REDACTED/REDACTED") strictEqual(capture.sent.url, "http://test/api/v1/p/s3cret/visible") + yield* capture.trace(client.test.recordParam({ params: { tok: Redacted.make("s3cret") } })) + strictEqual(capture.span.attributes.get("url.full"), "http://test/api/v1/record/REDACTED$1") + strictEqual(capture.span.attributes.get("url.path"), "/api/v1/record/REDACTED$1") + strictEqual(capture.sent.url, "http://test/api/v1/record/s3cret$1") + + const errorClient = yield* HttpApiClient.makeWith(Api, { + baseUrl: "http://test/api/v1", + httpClient: clientFromResponse(() => new Response("boom", { status: 500 })) + }) + const recordError = yield* Effect.flip( + errorClient.test.recordParam({ params: { tok: Redacted.make("s3cret") } }) + ) + assert.include(recordError.message, "GET http://test/api/v1/record/REDACTED$1") + assert.notInclude(JSON.stringify(recordError), "s3cret") + const rewrittenClient = yield* HttpApiClient.makeWith(Api, { baseUrl: "http://test/api/v1", httpClient: capture.httpClient.pipe(