diff --git a/CHANGELOG.md b/CHANGELOG.md index 21b7c4fd..613d2b91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/). ## [Unreleased] +### Removed +- **`Redacted` wrapper (`src/utils/redacted.ts`), added in 1.15.0.** Removed as dead code — it was never threaded through any secret-bearing path, so it protected nothing in practice (a false sense of security). Concrete leak prevention lives where the values actually flow: `redactSecrets` / `safeErrorMessage` at the log/error boundaries (e.g. the `kit secrets sync` error-leak fix) and the opt-in `KIT_MEMORY_REDACT` redaction-at-capture. Re-introduce only if it is genuinely wired through the resolve→write→sync chain (exposing via `.expose()` only at the exec/stdin boundary). (#46) + ## [1.22.0] - 2026-06-23 ### Added diff --git a/src/utils/redacted.test.ts b/src/utils/redacted.test.ts deleted file mode 100644 index 3d1f5017..00000000 --- a/src/utils/redacted.test.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { describe, it } from "node:test"; -import assert from "node:assert/strict"; -import { inspect } from "node:util"; -import { Redacted, redacted, isRedacted } from "./redacted.js"; - -describe("Redacted", () => { - const secret = redacted("sk_live_supersecret"); - - it("exposes the real value only via .expose()", () => { - assert.equal(secret.expose(), "sk_live_supersecret"); - }); - - it("masks on String() / template / toString", () => { - assert.equal(String(secret), ""); - assert.equal(`${secret}`, ""); - }); - - it("masks in JSON.stringify, including when nested in an object", () => { - assert.equal(JSON.stringify(secret), '""'); - assert.equal(JSON.stringify({ apiKey: secret }), '{"apiKey":""}'); - }); - - it("masks under util.inspect / console.log", () => { - assert.match(inspect(secret), //); - assert.doesNotMatch(inspect(secret), /supersecret/); - }); - - it("does not expose the value via own keys / Object spread", () => { - assert.deepEqual(Object.keys(secret), []); - assert.doesNotMatch(JSON.stringify({ ...secret }), /supersecret/); - }); - - it("isRedacted narrows correctly", () => { - assert.equal(isRedacted(secret), true); - assert.equal(isRedacted("plain"), false); - assert.equal(isRedacted(new Redacted(123)), true); - }); - - it("works for non-string payloads", () => { - const r = redacted({ token: "abc", n: 1 }); - assert.deepEqual(r.expose(), { token: "abc", n: 1 }); - assert.equal(String(r), ""); - }); -}); diff --git a/src/utils/redacted.ts b/src/utils/redacted.ts deleted file mode 100644 index d1590b48..00000000 --- a/src/utils/redacted.ts +++ /dev/null @@ -1,45 +0,0 @@ -/** - * `Redacted` — a secret wrapper whose value never leaks through string - * coercion, `JSON.stringify`, `console.log`/`util.inspect`, or object-key - * enumeration. The only way to read the real value is the explicit `.expose()`. - * - * Borrowed from Effect's `Redacted` pattern — the *pattern*, not the framework - * (see issue: borrow the wrapper, don't adopt Effect). The value is held in a - * module-private WeakMap, so it is not an instance property and cannot be - * reached by reflection/serialization. - */ -const store = new WeakMap, unknown>(); - -const MASK = ""; - -export class Redacted { - constructor(value: T) { - store.set(this, value); - } - - /** The only path to the underlying value. Call sites become grep-able. */ - expose(): T { - return store.get(this) as T; - } - - toString(): string { - return MASK; - } - - toJSON(): string { - return MASK; - } - - // console.log / util.inspect - [Symbol.for("nodejs.util.inspect.custom")](): string { - return MASK; - } -} - -export function redacted(value: T): Redacted { - return new Redacted(value); -} - -export function isRedacted(x: unknown): x is Redacted { - return x instanceof Redacted; -}