MCPcopy
hub / github.com/chartbrew/chartbrew / sanitizePayload

Function sanitizePayload

server/modules/updateAudit.js:77–115  ·  view source on GitHub ↗
(value, depth = 0)

Source from the content-addressed store, hash-verified

75}
76
77function sanitizePayload(value, depth = 0) {
78 if (value === undefined) {
79 return undefined;
80 }
81
82 if (value === null || typeof value === "number" || typeof value === "boolean") {
83 return value;
84 }
85
86 if (typeof value === "string") {
87 return truncateString(redactScalar(value));
88 }
89
90 if (value instanceof Date) {
91 return value.toISOString();
92 }
93
94 if (depth >= 5) {
95 return "[MaxDepth]";
96 }
97
98 if (Array.isArray(value)) {
99 return value
100 .slice(0, DEFAULT_ARRAY_PREVIEW)
101 .map((item) => sanitizePayload(item, depth + 1));
102 }
103
104 const sanitized = {};
105 Object.keys(value).forEach((key) => {
106 if (SENSITIVE_KEY_PATTERN.test(key)) {
107 sanitized[key] = "[REDACTED]";
108 return;
109 }
110
111 sanitized[key] = sanitizePayload(value[key], depth + 1);
112 });
113
114 return sanitized;
115}
116
117function sanitizeSnippet(value, maxLength = DEFAULT_MAX_STRING_LENGTH) {
118 if (value === undefined || value === null || value === "") {

Callers 7

sanitizeSnippetFunction · 0.85
startRunFunction · 0.85
updateRunContextFunction · 0.85
startEventFunction · 0.85
finishEventFunction · 0.85
completeRunFunction · 0.85
failRunFunction · 0.85

Calls 2

truncateStringFunction · 0.85
redactScalarFunction · 0.85

Tested by

no test coverage detected