MCPcopy
hub / github.com/redis/node-redis / sanitizeArgs

Function sanitizeArgs

packages/client/lib/client/tracing.ts:49–76  ·  view source on GitHub ↗
(args: ReadonlyArray<unknown>)

Source from the content-addressed store, hash-verified

47 * Sanitizes the arguments of a command to remove sensitive information.
48 */
49export function sanitizeArgs(args: ReadonlyArray<unknown>): ReadonlyArray<string> {
50 if (args.length === 0) return [];
51
52 const commandName = String(args[0]);
53 let allowedArgCount = 0; // default: command name only for unlisted commands
54
55 for (const subset of SERIALIZATION_SUBSETS) {
56 if (subset.regex.test(commandName)) {
57 allowedArgCount = subset.args;
58 break;
59 }
60 }
61
62 // All args are safe (structural/read commands)
63 if (allowedArgCount === -1) {
64 return args.map(a => String(a));
65 }
66
67 const result: string[] = [commandName];
68 for (let i = 1; i < args.length; i++) {
69 if (i <= allowedArgCount) {
70 result.push(String(args[i]));
71 } else {
72 result.push('?');
73 }
74 }
75 return result;
76}
77
78export interface CommandTraceContext {
79 command: string;

Callers 3

_executeCommandMethod · 0.90
#commandTraceContextMethod · 0.90
tracing.spec.tsFile · 0.90

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected