Files
openclaw/src/logging/redact-identifier.ts
Yida-Dev 4216449405 fix: guard resolveUserPath against undefined input (#10176)
* fix: guard resolveUserPath against undefined input

When subagent spawner omits workspaceDir, resolveUserPath receives
undefined and crashes on .trim().  Add a falsy guard that falls back
to process.cwd(), matching the behavior callers already expect.

Closes #10089

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: harden runner workspace fallback (#10176) (thanks @Yida-Dev)

* fix: harden workspace fallback scoping (#10176) (thanks @Yida-Dev)

* refactor: centralize workspace fallback classification and redaction (#10176) (thanks @Yida-Dev)

* test: remove explicit any from utils mock (#10176) (thanks @Yida-Dev)

* security: reject malformed agent session keys for workspace resolution (#10176) (thanks @Yida-Dev)

---------

Co-authored-by: Yida-Dev <reyifeijun@gmail.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Gustavo Madeira Santana <gumadeiras@gmail.com>
2026-02-06 13:16:58 -05:00

15 lines
497 B
TypeScript

import crypto from "node:crypto";
export function sha256HexPrefix(value: string, len = 12): string {
const safeLen = Number.isFinite(len) ? Math.max(1, Math.floor(len)) : 12;
return crypto.createHash("sha256").update(value).digest("hex").slice(0, safeLen);
}
export function redactIdentifier(value: string | undefined, opts?: { len?: number }): string {
const trimmed = value?.trim();
if (!trimmed) {
return "-";
}
return `sha256:${sha256HexPrefix(trimmed, opts?.len ?? 12)}`;
}