codeaura-embedded-runtime-agent 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,85 @@
1
+ function sanitizeInputs(value, depth = 0, seen = new WeakSet()) {
2
+ if (depth > 3) {
3
+ return "[MaxDepth]";
4
+ }
5
+
6
+ if (value === null || value === undefined) {
7
+ return null;
8
+ }
9
+
10
+ if (
11
+ typeof value === "string" ||
12
+ typeof value === "number" ||
13
+ typeof value === "boolean"
14
+ ) {
15
+ return value;
16
+ }
17
+
18
+ if (Array.isArray(value)) {
19
+ return value.slice(0, 10).map(v => sanitizeInputs(v, depth + 1, seen));
20
+ }
21
+
22
+ if (typeof value === "object") {
23
+ const ctor = value.constructor?.name,
24
+ clean = {},
25
+ keys = Object.keys(value);
26
+
27
+ if (
28
+ ctor === "Socket" ||
29
+ ctor === "IncomingMessage" ||
30
+ ctor === "ServerResponse" ||
31
+ ctor === "HTTPParser" ||
32
+ ctor === "Server"
33
+ ) {
34
+ return `[${ctor}]`;
35
+ } else if (typeof value.allParams === "function" && typeof value.method === "string") {
36
+ try {
37
+ return sanitizeInputs(value.allParams(), depth + 1, seen);
38
+ } catch (unusedErr) {
39
+ return "[Request]";
40
+ }
41
+ } else if (typeof value._handleExec === "function") {
42
+ return "[Deferred]";
43
+ } else if (seen.has(value)) {
44
+ return "[Circular]";
45
+ } else {
46
+
47
+ }
48
+
49
+ seen.add(value);
50
+
51
+ for (const key of keys.slice(0, 50)) {
52
+ if (key === "password" || key === "token" || key === "secret" || key === "apiKey" || key === "cookie_string" || key === "cookieString" || key === "cookie" || key === "authorization" || key === "Authorization") {
53
+ clean[key] = "[REDACTED]";
54
+ } else if (key === "_events" || key === "_eventsCount" || key === "domain") {
55
+ continue;
56
+ } else if (key === "req" || key === "res") {
57
+ const childValue = value[key];
58
+
59
+ if (typeof childValue?.allParams === "function") {
60
+ try {
61
+ clean[key] = sanitizeInputs(childValue.allParams(), depth + 1, seen);
62
+ } catch (unusedErr) {
63
+ clean[key] = "[Request]";
64
+ }
65
+ } else if (childValue?.constructor?.name === "ServerResponse") {
66
+ clean[key] = "[ServerResponse]";
67
+ } else {
68
+ clean[key] = sanitizeInputs(childValue, depth + 1, seen);
69
+ }
70
+ } else {
71
+ clean[key] = sanitizeInputs(value[key], depth + 1, seen);
72
+ }
73
+ }
74
+
75
+ return clean;
76
+ }
77
+
78
+ if (typeof value === "function") {
79
+ return "[Function]";
80
+ }
81
+
82
+ return `[${typeof value}]`;
83
+ }
84
+
85
+ module.exports = sanitizeInputs;