fix: address Codex PR review findings
This commit is contained in:
1 parent
0f164b6de5
commit
a7974abb08
44 files changed
+3317
-667
No files matched your search
+27
-1
@@ -13,13 +13,39 @@ export function writeStdoutChunk(chunk: string): Promise<void> {
|
||||
});
|
||||
}
|
||||
|
||||
export function redactSensitiveText(value: string): string {
|
||||
function redactTextFragments(value: string): string {
|
||||
return value
|
||||
.replace(/([?&](?:accessToken|token|returnToken|security-token|x-amz-security-token|signature|x-amz-signature|ossaccesskeyid|x-amz-credential)=)[^&\s"']+/gi, "$1<redacted>")
|
||||
.replace(/(Bearer\s+)[A-Za-z0-9._~+/=-]+/gi, "$1<redacted>")
|
||||
.replace(/((?:password|passwd|secret|appSecurity)["']?\s*[:=]\s*["']?)[^"',\s}]+/gi, "$1<redacted>");
|
||||
}
|
||||
|
||||
export function redactSensitiveText(value: string): string {
|
||||
try {
|
||||
const parsed: unknown = JSON.parse(value);
|
||||
const redactValue = (item: unknown, key = ""): unknown => {
|
||||
// Boolean/null flags such as keepItSecret are business metadata, not credentials.
|
||||
if (item === null || typeof item === "boolean") return item;
|
||||
if (/(?:password|passwd|secret|appSecurity)$/i.test(key)) return "<redacted>";
|
||||
if (typeof item === "string") return redactTextFragments(item);
|
||||
if (Array.isArray(item)) return item.map((child) => redactValue(child));
|
||||
if (typeof item === "object") {
|
||||
return Object.fromEntries(Object.entries(item).map(([name, child]) => [name, redactValue(child, name)]));
|
||||
}
|
||||
return item;
|
||||
};
|
||||
const leading = value.match(/^\s*/)?.[0] || "";
|
||||
const trailing = value.match(/\s*$/)?.[0] || "";
|
||||
// Keep compact NDJSON records on one line and ordinary CLI JSON readable.
|
||||
const multiline = value.trim().includes("\n");
|
||||
let json = JSON.stringify(redactValue(parsed), null, multiline || value.includes(": ") ? 2 : undefined);
|
||||
if (!multiline) json = json.replace(/\n\s*/g, " ");
|
||||
return leading + json + trailing;
|
||||
} catch {
|
||||
return redactTextFragments(value);
|
||||
}
|
||||
}
|
||||
|
||||
export function protectLargeOutput(result: unknown, options: OutputOptions = {}) {
|
||||
if (options.allowFull || options.outputFile) return;
|
||||
const bodyBytes = Buffer.byteLength(JSON.stringify(result), "utf-8");
|
||||
|
||||
Reference in new issue
Block a user