@debugbundle/sdk-react-native 1.3.0 → 3.0.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.
- package/CHANGELOG.md +22 -2
- package/DebugBundleReactNative.podspec +2 -2
- package/MIGRATION-3.0.md +9 -0
- package/README.md +8 -3
- package/android/build.gradle +3 -3
- package/android/src/main/java/com/debugbundle/reactnative/DebugBundleReactNativeModule.java +2 -2
- package/app.plugin.js +1 -1
- package/dist/before-send.d.ts.map +1 -1
- package/dist/before-send.js +6 -0
- package/dist/client.d.ts +8 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +238 -61
- package/dist/console.d.ts +4 -2
- package/dist/console.d.ts.map +1 -1
- package/dist/console.js +5 -0
- package/dist/privacy-keys.d.ts +3 -0
- package/dist/privacy-keys.d.ts.map +1 -0
- package/dist/privacy-keys.js +35 -0
- package/dist/privacy-telemetry.d.ts +19 -0
- package/dist/privacy-telemetry.d.ts.map +1 -0
- package/dist/privacy-telemetry.js +164 -0
- package/dist/privacy-text.d.ts +3 -0
- package/dist/privacy-text.d.ts.map +1 -0
- package/dist/privacy-text.js +85 -0
- package/dist/redaction.d.ts.map +1 -1
- package/dist/redaction.js +29 -45
- package/ios/DebugBundleReactNative.swift +2 -2
- package/package.json +6 -5
- package/src/before-send.ts +6 -0
- package/src/client.ts +226 -70
- package/src/console.ts +6 -1
- package/src/privacy-keys.ts +39 -0
- package/src/privacy-telemetry.ts +168 -0
- package/src/privacy-text.ts +86 -0
- package/src/redaction.ts +26 -46
- package/android/src/test/java/com/debugbundle/reactnative/DebugBundleReactNativeModuleTest.java +0 -474
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export const DEFAULT_SENSITIVE_KEYS = [
|
|
2
|
+
"password", "secret", "token", "api_key", "apikey", "access_token", "refresh_token",
|
|
3
|
+
"private_key", "authorization", "bearer", "cookie", "session_id", "passwd", "ssn",
|
|
4
|
+
"credit_card", "card_number", "cvv", "cvc", "pin", "expiry", "phone", "otp",
|
|
5
|
+
"verification_code"
|
|
6
|
+
];
|
|
7
|
+
function canonicalizeSensitiveKey(value) {
|
|
8
|
+
return value.toLowerCase().replace(/[^a-z0-9]+/g, "");
|
|
9
|
+
}
|
|
10
|
+
function splitKeyIntoSegments(key) {
|
|
11
|
+
return key
|
|
12
|
+
.trim()
|
|
13
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1_$2")
|
|
14
|
+
.toLowerCase()
|
|
15
|
+
.split(/[^a-z0-9]+/)
|
|
16
|
+
.filter((segment) => segment.length > 0);
|
|
17
|
+
}
|
|
18
|
+
export function isSensitiveKey(key, sensitiveKeys) {
|
|
19
|
+
const normalized = key.trim().toLowerCase();
|
|
20
|
+
if (sensitiveKeys.includes(normalized)) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
const canonicalSensitiveKeys = new Set(sensitiveKeys.map(canonicalizeSensitiveKey));
|
|
24
|
+
const segments = splitKeyIntoSegments(key);
|
|
25
|
+
for (let start = 0; start < segments.length; start += 1) {
|
|
26
|
+
let combined = "";
|
|
27
|
+
for (let end = start; end < segments.length; end += 1) {
|
|
28
|
+
combined += segments[end];
|
|
29
|
+
if (canonicalSensitiveKeys.has(combined)) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
2
|
+
[key: string]: JsonValue;
|
|
3
|
+
};
|
|
4
|
+
export interface TelemetrySanitizationOptions {
|
|
5
|
+
additionalKeys?: readonly string[];
|
|
6
|
+
maxTotalBytes?: number;
|
|
7
|
+
}
|
|
8
|
+
export type TelemetrySanitizationResult = {
|
|
9
|
+
ok: true;
|
|
10
|
+
value: JsonValue;
|
|
11
|
+
redactionCount: number;
|
|
12
|
+
} | {
|
|
13
|
+
ok: false;
|
|
14
|
+
reason: "unsafe_input" | "budget_exceeded";
|
|
15
|
+
};
|
|
16
|
+
/** Mandatory telemetry policy; unlike the legacy `redact` helper, custom keys are additive. */
|
|
17
|
+
export declare function sanitizeTelemetry(value: unknown, options?: TelemetrySanitizationOptions): TelemetrySanitizationResult;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=privacy-telemetry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"privacy-telemetry.d.ts","sourceRoot":"","sources":["../src/privacy-telemetry.ts"],"names":[],"mappings":"AAAA,KAAK,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,EAAE,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAW/F,MAAM,WAAW,4BAA4B;IAC3C,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,MAAM,2BAA2B,GACnC;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,SAAS,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAE,GACtD;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,cAAc,GAAG,iBAAiB,CAAA;CAAE,CAAC;AAyH9D,+FAA+F;AAC/F,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,GAAE,4BAAiC,GAAG,2BAA2B,CA2BzH"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { DEFAULT_SENSITIVE_KEYS, isSensitiveKey } from "./privacy-keys.js";
|
|
2
|
+
import { scrubCredentialText } from "./privacy-text.js";
|
|
3
|
+
const REDACTED = "[REDACTED]";
|
|
4
|
+
const MAX_DEPTH = 16;
|
|
5
|
+
const MAX_NODES = 4096;
|
|
6
|
+
const MAX_ENTRIES = 256;
|
|
7
|
+
const MAX_STRING_BYTES = 16 * 1024;
|
|
8
|
+
const MAX_TOTAL_BYTES = 256 * 1024;
|
|
9
|
+
class BudgetExceeded extends Error {
|
|
10
|
+
}
|
|
11
|
+
function byteLength(value) {
|
|
12
|
+
let bytes = 0;
|
|
13
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
14
|
+
const code = value.charCodeAt(index);
|
|
15
|
+
if (code < 0x80)
|
|
16
|
+
bytes += 1;
|
|
17
|
+
else if (code < 0x800)
|
|
18
|
+
bytes += 2;
|
|
19
|
+
else if (code >= 0xd800 && code <= 0xdbff && index + 1 < value.length &&
|
|
20
|
+
value.charCodeAt(index + 1) >= 0xdc00 && value.charCodeAt(index + 1) <= 0xdfff) {
|
|
21
|
+
bytes += 4;
|
|
22
|
+
index += 1;
|
|
23
|
+
}
|
|
24
|
+
else
|
|
25
|
+
bytes += 3;
|
|
26
|
+
}
|
|
27
|
+
return bytes;
|
|
28
|
+
}
|
|
29
|
+
function mask(state) {
|
|
30
|
+
state.redactionCount += 1;
|
|
31
|
+
return REDACTED;
|
|
32
|
+
}
|
|
33
|
+
function sanitizeString(value, state, allowStructured) {
|
|
34
|
+
if (value.length > MAX_STRING_BYTES)
|
|
35
|
+
return mask(state);
|
|
36
|
+
const length = byteLength(value);
|
|
37
|
+
if (length > MAX_STRING_BYTES)
|
|
38
|
+
return mask(state);
|
|
39
|
+
state.textBytes += length;
|
|
40
|
+
if (state.textBytes > state.maxTotalBytes)
|
|
41
|
+
throw new BudgetExceeded();
|
|
42
|
+
if (allowStructured && (value.startsWith("{") || value.startsWith("["))) {
|
|
43
|
+
try {
|
|
44
|
+
const parsed = JSON.parse(value);
|
|
45
|
+
if (typeof parsed === "object" && parsed !== null) {
|
|
46
|
+
const nested = sanitizeValue(parsed, state, 0, false);
|
|
47
|
+
const encoded = JSON.stringify(nested);
|
|
48
|
+
if (encoded !== value)
|
|
49
|
+
state.redactionCount += 1;
|
|
50
|
+
return encoded;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
if (error instanceof BudgetExceeded)
|
|
55
|
+
throw error;
|
|
56
|
+
// Malformed structured content with a recognizable sensitive label is withheld below.
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const result = scrubCredentialText(value, state.extra);
|
|
60
|
+
if (result !== value)
|
|
61
|
+
state.redactionCount += 1;
|
|
62
|
+
if ((value.startsWith("{") || value.startsWith("[")) && result === value &&
|
|
63
|
+
/(?:password|token|secret|authorization|cookie)["']?\s*[:=]/i.test(value)) {
|
|
64
|
+
return mask(state);
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
function sanitizeValue(value, state, depth, allowStructured) {
|
|
69
|
+
state.nodes += 1;
|
|
70
|
+
if (state.nodes > MAX_NODES)
|
|
71
|
+
throw new BudgetExceeded();
|
|
72
|
+
if (depth > MAX_DEPTH)
|
|
73
|
+
return mask(state);
|
|
74
|
+
if (typeof value === "string")
|
|
75
|
+
return sanitizeString(value, state, allowStructured);
|
|
76
|
+
if (value === null || typeof value === "boolean")
|
|
77
|
+
return value;
|
|
78
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
79
|
+
return value;
|
|
80
|
+
if (typeof value !== "object")
|
|
81
|
+
throw new TypeError("unsafe_input");
|
|
82
|
+
if (state.seen.has(value))
|
|
83
|
+
return "[Circular]";
|
|
84
|
+
state.seen.add(value);
|
|
85
|
+
try {
|
|
86
|
+
if (Array.isArray(value)) {
|
|
87
|
+
if (value.length > MAX_ENTRIES)
|
|
88
|
+
return mask(state);
|
|
89
|
+
return Array.from({ length: value.length }, (_, index) => {
|
|
90
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, String(index));
|
|
91
|
+
if (descriptor === undefined || !("value" in descriptor))
|
|
92
|
+
throw new TypeError("unsafe_input");
|
|
93
|
+
return sanitizeValue(descriptor.value, state, depth + 1, allowStructured);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) {
|
|
97
|
+
throw new TypeError("unsafe_input");
|
|
98
|
+
}
|
|
99
|
+
const keys = Object.keys(value);
|
|
100
|
+
if (keys.length > MAX_ENTRIES)
|
|
101
|
+
return mask(state);
|
|
102
|
+
const result = {};
|
|
103
|
+
for (const key of keys) {
|
|
104
|
+
if (key.length > 128) {
|
|
105
|
+
state.redactionCount += 1;
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
state.textBytes += byteLength(key);
|
|
109
|
+
if (state.textBytes > state.maxTotalBytes)
|
|
110
|
+
throw new BudgetExceeded();
|
|
111
|
+
const safeKey = scrubCredentialText(key, state.extra);
|
|
112
|
+
if (safeKey !== key) {
|
|
113
|
+
state.redactionCount += 1;
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
117
|
+
if (descriptor === undefined || !("value" in descriptor))
|
|
118
|
+
throw new TypeError("unsafe_input");
|
|
119
|
+
const safeValue = isSensitiveKey(key, state.keys)
|
|
120
|
+
? mask(state)
|
|
121
|
+
: sanitizeValue(descriptor.value, state, depth + 1, allowStructured);
|
|
122
|
+
Object.defineProperty(result, key, {
|
|
123
|
+
value: safeValue,
|
|
124
|
+
enumerable: true,
|
|
125
|
+
configurable: true,
|
|
126
|
+
writable: true
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
finally {
|
|
132
|
+
state.seen.delete(value);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/** Mandatory telemetry policy; unlike the legacy `redact` helper, custom keys are additive. */
|
|
136
|
+
export function sanitizeTelemetry(value, options = {}) {
|
|
137
|
+
try {
|
|
138
|
+
const extra = options.additionalKeys ?? [];
|
|
139
|
+
if (extra.length > 128 || extra.some((key) => typeof key !== "string" || key.length > 64 || !key.trim())) {
|
|
140
|
+
return { ok: false, reason: "unsafe_input" };
|
|
141
|
+
}
|
|
142
|
+
const maxTotalBytes = options.maxTotalBytes ?? MAX_TOTAL_BYTES;
|
|
143
|
+
if (!Number.isInteger(maxTotalBytes) || maxTotalBytes < 1 || maxTotalBytes > 512 * 1024) {
|
|
144
|
+
return { ok: false, reason: "unsafe_input" };
|
|
145
|
+
}
|
|
146
|
+
const state = {
|
|
147
|
+
nodes: 0,
|
|
148
|
+
textBytes: 0,
|
|
149
|
+
redactionCount: 0,
|
|
150
|
+
seen: new WeakSet(),
|
|
151
|
+
keys: [...DEFAULT_SENSITIVE_KEYS, ...extra],
|
|
152
|
+
extra,
|
|
153
|
+
maxTotalBytes
|
|
154
|
+
};
|
|
155
|
+
const sanitized = sanitizeValue(value, state, 0, true);
|
|
156
|
+
if (byteLength(JSON.stringify(sanitized)) > maxTotalBytes) {
|
|
157
|
+
return { ok: false, reason: "budget_exceeded" };
|
|
158
|
+
}
|
|
159
|
+
return { ok: true, value: sanitized, redactionCount: state.redactionCount };
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
return { ok: false, reason: error instanceof BudgetExceeded ? "budget_exceeded" : "unsafe_input" };
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"privacy-text.d.ts","sourceRoot":"","sources":["../src/privacy-text.ts"],"names":[],"mappings":"AAyDA,6FAA6F;AAC7F,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,SAAS,MAAM,EAAE,EAAE,QAAQ,UAAO,GAAG,MAAM,CA2B7G"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { DEFAULT_SENSITIVE_KEYS, isSensitiveKey } from "./privacy-keys.js";
|
|
2
|
+
const REDACTED = "[REDACTED]";
|
|
3
|
+
const BUILTIN_LABELS = [...DEFAULT_SENSITIVE_KEYS, "client_secret", "x_api_key",
|
|
4
|
+
"accessToken", "refreshToken", "privateKey", "clientSecret"];
|
|
5
|
+
const ASSIGNMENT = new RegExp(`\\b(${BUILTIN_LABELS.join("|")})\\b(["']?\\s*[:=]\\s*)(?:"[^"]*"|'[^']*'|[^\\s&,;]+)`, "gi");
|
|
6
|
+
const HEADER = /\b(Authorization|Proxy-Authorization|Cookie|Set-Cookie)\s*:\s*[^\r\n]*/gi;
|
|
7
|
+
const PEM = /-----BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY-----[\s\S]*?-----END (?:RSA |EC |OPENSSH )?PRIVATE KEY-----/gi;
|
|
8
|
+
const PEM_COMPLETE = new RegExp(PEM.source, "i");
|
|
9
|
+
const PEM_START = /-----BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY-----/i;
|
|
10
|
+
const DEBUGBUNDLE_TOKEN = /\bdbundle_(?:proj|mem|probe|agent)_[A-Za-z0-9_-]+\b/g;
|
|
11
|
+
const BEARER = /\b(Bearer|Basic)\s+[A-Za-z0-9._~+\/-]{6,}/gi;
|
|
12
|
+
const URL_TEXT = /\bhttps?:\/\/[^\s<>"']+/gi;
|
|
13
|
+
// Do not treat numeric substrings inside UUIDs, hashes, or identifier slugs as cards.
|
|
14
|
+
const CARD = /(?<![A-Za-z0-9_-])(?:\d[ -]?){12,18}\d(?![A-Za-z0-9_-])/g;
|
|
15
|
+
function isValidCard(value) {
|
|
16
|
+
const digits = value.replace(/[^0-9]/g, "");
|
|
17
|
+
if (digits.length < 13 || digits.length > 19 || /^(\d)\1+$/.test(digits)) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
let sum = 0;
|
|
21
|
+
for (let index = digits.length - 1; index >= 0; index -= 1) {
|
|
22
|
+
let digit = Number(digits[index]);
|
|
23
|
+
if ((digits.length - index) % 2 === 0) {
|
|
24
|
+
digit *= 2;
|
|
25
|
+
if (digit > 9)
|
|
26
|
+
digit -= 9;
|
|
27
|
+
}
|
|
28
|
+
sum += digit;
|
|
29
|
+
}
|
|
30
|
+
return sum % 10 === 0;
|
|
31
|
+
}
|
|
32
|
+
function scrubUrl(raw, keys) {
|
|
33
|
+
try {
|
|
34
|
+
const url = new URL(raw);
|
|
35
|
+
if (url.username || url.password) {
|
|
36
|
+
url.username = "REDACTED";
|
|
37
|
+
url.password = "";
|
|
38
|
+
}
|
|
39
|
+
const nextQuery = new URLSearchParams();
|
|
40
|
+
for (const [key, value] of url.searchParams) {
|
|
41
|
+
if (key.length > 128 || scrubCredentialText(key, keys, false) !== key)
|
|
42
|
+
continue;
|
|
43
|
+
nextQuery.append(key, isSensitiveKey(key, keys) || scrubCredentialText(value, keys, false) !== value ? REDACTED : value);
|
|
44
|
+
}
|
|
45
|
+
url.search = nextQuery.toString();
|
|
46
|
+
url.hash = "";
|
|
47
|
+
return url.toString();
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
// A malformed URL with a recognizable credential must not be emitted verbatim.
|
|
51
|
+
return REDACTED;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** Bounded caller input only. Returns stable replacement text, never the matching secret. */
|
|
55
|
+
export function scrubCredentialText(input, additionalKeys, scanUrls = true) {
|
|
56
|
+
const keys = [...DEFAULT_SENSITIVE_KEYS, ...additionalKeys];
|
|
57
|
+
if (PEM_START.test(input) && !PEM_COMPLETE.test(input))
|
|
58
|
+
return REDACTED;
|
|
59
|
+
let output = input;
|
|
60
|
+
if (/(?:password|token|secret|authorization|cookie)%3[ad]/i.test(output)) {
|
|
61
|
+
try {
|
|
62
|
+
output = decodeURIComponent(output);
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return REDACTED;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
output = output.replace(PEM, REDACTED).replace(HEADER, "$1: [REDACTED]");
|
|
69
|
+
output = output.replace(BEARER, "$1 [REDACTED]").replace(DEBUGBUNDLE_TOKEN, REDACTED);
|
|
70
|
+
output = output.replace(ASSIGNMENT, "$1$2[REDACTED]");
|
|
71
|
+
if (additionalKeys.length > 0) {
|
|
72
|
+
for (const key of additionalKeys) {
|
|
73
|
+
const escaped = key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
74
|
+
const named = new RegExp(`\\b(${escaped})\\b(["']?\\s*[:=]\\s*)(?:"[^"]*"|'[^']*'|[^\\s&,;]+)`, "gi");
|
|
75
|
+
output = output.replace(named, "$1$2[REDACTED]");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
output = output.replace(CARD, (candidate) => isValidCard(candidate) ? REDACTED : candidate);
|
|
79
|
+
if (!scanUrls)
|
|
80
|
+
return output;
|
|
81
|
+
return output.replace(URL_TEXT, (matched) => {
|
|
82
|
+
const trailing = matched.match(/[).,;]+$/)?.[0] ?? "";
|
|
83
|
+
return scrubUrl(matched.slice(0, matched.length - trailing.length), keys) + trailing;
|
|
84
|
+
});
|
|
85
|
+
}
|
package/dist/redaction.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redaction.d.ts","sourceRoot":"","sources":["../src/redaction.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"redaction.d.ts","sourceRoot":"","sources":["../src/redaction.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,wBAAwB,UAQpC,CAAC;AAEF,MAAM,WAAW,eAAe;IAC9B,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,wBAAgB,mBAAmB,IAAI,MAAM,EAAE,CAE9C;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,GAAE,eAAoB,GAAG,OAAO,CAUpF;AAED,wBAAgB,eAAe,CAC7B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,EAC3C,SAAS,GAAE,MAAM,EAA6B,EAC9C,OAAO,GAAE,eAAoB,GAC5B,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAaxB"}
|
package/dist/redaction.js
CHANGED
|
@@ -1,26 +1,7 @@
|
|
|
1
|
+
import { DEFAULT_SENSITIVE_KEYS, isSensitiveKey as privacySensitiveKey } from "./privacy-keys.js";
|
|
2
|
+
import { sanitizeTelemetry } from "./privacy-telemetry.js";
|
|
1
3
|
const DEFAULT_REDACT_FIELDS = [
|
|
2
|
-
|
|
3
|
-
"secret",
|
|
4
|
-
"token",
|
|
5
|
-
"api_key",
|
|
6
|
-
"apikey",
|
|
7
|
-
"access_token",
|
|
8
|
-
"refresh_token",
|
|
9
|
-
"private_key",
|
|
10
|
-
"passwd",
|
|
11
|
-
"card_number",
|
|
12
|
-
"cvv",
|
|
13
|
-
"cvc",
|
|
14
|
-
"pin",
|
|
15
|
-
"expiry",
|
|
16
|
-
"phone",
|
|
17
|
-
"bearer",
|
|
18
|
-
"session_id",
|
|
19
|
-
"otp",
|
|
20
|
-
"verification_code",
|
|
21
|
-
"authorization",
|
|
22
|
-
"cookie",
|
|
23
|
-
"ssn"
|
|
4
|
+
...DEFAULT_SENSITIVE_KEYS
|
|
24
5
|
];
|
|
25
6
|
export const DEFAULT_HEADER_ALLOWLIST = [
|
|
26
7
|
"user-agent",
|
|
@@ -35,8 +16,16 @@ export function defaultRedactFields() {
|
|
|
35
16
|
return [...DEFAULT_REDACT_FIELDS];
|
|
36
17
|
}
|
|
37
18
|
export function sanitizeValue(value, options = {}) {
|
|
38
|
-
|
|
39
|
-
|
|
19
|
+
try {
|
|
20
|
+
const normalized = normalizeOptions(options);
|
|
21
|
+
const visited = new WeakSet();
|
|
22
|
+
const prepared = sanitize(value, normalized, 0, visited, undefined);
|
|
23
|
+
const protectedValue = sanitizeTelemetry(prepared, { additionalKeys: options.redactFields ?? [] });
|
|
24
|
+
return protectedValue.ok ? protectedValue.value : "[REDACTED]";
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return "[REDACTED]";
|
|
28
|
+
}
|
|
40
29
|
}
|
|
41
30
|
export function sanitizeHeaders(headers, allowlist = DEFAULT_HEADER_ALLOWLIST, options = {}) {
|
|
42
31
|
if (!headers) {
|
|
@@ -54,7 +43,7 @@ export function sanitizeHeaders(headers, allowlist = DEFAULT_HEADER_ALLOWLIST, o
|
|
|
54
43
|
}
|
|
55
44
|
function normalizeOptions(options) {
|
|
56
45
|
return {
|
|
57
|
-
redactFields: options.redactFields ??
|
|
46
|
+
redactFields: [...DEFAULT_REDACT_FIELDS, ...(options.redactFields ?? [])],
|
|
58
47
|
maxDepth: options.maxDepth ?? 8,
|
|
59
48
|
maxStringLength: options.maxStringLength ?? 2048,
|
|
60
49
|
maxArrayLength: options.maxArrayLength ?? 50,
|
|
@@ -63,13 +52,13 @@ function normalizeOptions(options) {
|
|
|
63
52
|
}
|
|
64
53
|
function sanitize(value, options, depth, visited, key) {
|
|
65
54
|
if (key && isSensitiveKey(key, options.redactFields)) {
|
|
66
|
-
return "[
|
|
55
|
+
return "[REDACTED]";
|
|
67
56
|
}
|
|
68
57
|
if (value === null || value === undefined) {
|
|
69
58
|
return value ?? null;
|
|
70
59
|
}
|
|
71
60
|
if (typeof value === "string") {
|
|
72
|
-
return truncate(value, options.maxStringLength);
|
|
61
|
+
return truncate(value, options.maxStringLength, options.redactFields);
|
|
73
62
|
}
|
|
74
63
|
if (typeof value === "number" || typeof value === "boolean") {
|
|
75
64
|
return value;
|
|
@@ -106,27 +95,22 @@ function sanitize(value, options, depth, visited, key) {
|
|
|
106
95
|
}
|
|
107
96
|
function sanitizeError(error, options, depth, visited) {
|
|
108
97
|
return {
|
|
109
|
-
name: truncate(error.name || "Error", options.maxStringLength),
|
|
110
|
-
message: truncate(error.message || "", options.maxStringLength),
|
|
111
|
-
stack: typeof error.stack === "string" ? truncate(error.stack, options.maxStringLength * 4) : null,
|
|
98
|
+
name: truncate(error.name || "Error", options.maxStringLength, options.redactFields),
|
|
99
|
+
message: truncate(error.message || "", options.maxStringLength, options.redactFields),
|
|
100
|
+
stack: typeof error.stack === "string" ? truncate(error.stack, options.maxStringLength * 4, options.redactFields) : null,
|
|
112
101
|
cause: "cause" in error ? sanitize(error.cause, options, depth + 1, visited, "cause") : null
|
|
113
102
|
};
|
|
114
103
|
}
|
|
115
|
-
function truncate(value, maxLength) {
|
|
116
|
-
if (value.length
|
|
117
|
-
return
|
|
118
|
-
}
|
|
119
|
-
|
|
104
|
+
function truncate(value, maxLength, fields) {
|
|
105
|
+
if (value.length > 16 * 1024)
|
|
106
|
+
return "[REDACTED]";
|
|
107
|
+
const safe = sanitizeTelemetry(value, { additionalKeys: fields });
|
|
108
|
+
if (!safe.ok || typeof safe.value !== "string")
|
|
109
|
+
return "[REDACTED]";
|
|
110
|
+
if (safe.value.length <= maxLength)
|
|
111
|
+
return safe.value;
|
|
112
|
+
return `${safe.value.slice(0, maxLength)}...[Truncated]`;
|
|
120
113
|
}
|
|
121
114
|
function isSensitiveKey(key, sensitiveFields) {
|
|
122
|
-
|
|
123
|
-
const sensitive = new Set(sensitiveFields.flatMap(splitKey));
|
|
124
|
-
return segments.some((segment) => sensitive.has(segment));
|
|
125
|
-
}
|
|
126
|
-
function splitKey(key) {
|
|
127
|
-
return key
|
|
128
|
-
.replace(/([a-z0-9])([A-Z])/g, "$1_$2")
|
|
129
|
-
.split(/[^a-zA-Z0-9]+/)
|
|
130
|
-
.map((segment) => segment.toLowerCase())
|
|
131
|
-
.filter(Boolean);
|
|
115
|
+
return privacySensitiveKey(key, [...DEFAULT_SENSITIVE_KEYS, ...sensitiveFields]);
|
|
132
116
|
}
|
|
@@ -4,7 +4,7 @@ import DebugBundle
|
|
|
4
4
|
|
|
5
5
|
@objc(DebugBundleReactNative)
|
|
6
6
|
final class DebugBundleReactNative: NSObject {
|
|
7
|
-
private var currentSDKVersion = "
|
|
7
|
+
private var currentSDKVersion = "3.0.0"
|
|
8
8
|
private var currentService = "react-native-app"
|
|
9
9
|
private var currentEnvironment = "production"
|
|
10
10
|
|
|
@@ -14,7 +14,7 @@ final class DebugBundleReactNative: NSObject {
|
|
|
14
14
|
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
15
15
|
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
16
16
|
) {
|
|
17
|
-
currentSDKVersion = config["sdkVersion"] as? String ?? "
|
|
17
|
+
currentSDKVersion = config["sdkVersion"] as? String ?? "3.0.0"
|
|
18
18
|
currentService = config["service"] as? String ?? "react-native-app"
|
|
19
19
|
currentEnvironment = config["environment"] as? String ?? "production"
|
|
20
20
|
let sdkConfig = DebugBundleConfig(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@debugbundle/sdk-react-native",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "React Native SDK for DebugBundle mobile event capture.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -41,14 +41,15 @@
|
|
|
41
41
|
},
|
|
42
42
|
"files": [
|
|
43
43
|
"android/build.gradle",
|
|
44
|
-
"android/src",
|
|
44
|
+
"android/src/main",
|
|
45
45
|
"ios",
|
|
46
46
|
"src",
|
|
47
47
|
"dist",
|
|
48
48
|
"app.plugin.js",
|
|
49
49
|
"DebugBundleReactNative.podspec",
|
|
50
50
|
"CHANGELOG.md",
|
|
51
|
-
"README.md"
|
|
51
|
+
"README.md",
|
|
52
|
+
"MIGRATION-3.0.md"
|
|
52
53
|
],
|
|
53
54
|
"exports": {
|
|
54
55
|
"./package.json": "./package.json",
|
|
@@ -104,9 +105,9 @@
|
|
|
104
105
|
},
|
|
105
106
|
"devDependencies": {
|
|
106
107
|
"@types/react": "^19.1.2",
|
|
107
|
-
"@vitest/coverage-v8": "^4.1.
|
|
108
|
+
"@vitest/coverage-v8": "^4.1.11",
|
|
108
109
|
"react": "^19.2.4",
|
|
109
110
|
"typescript": "^6.0.2",
|
|
110
|
-
"vitest": "^4.1.
|
|
111
|
+
"vitest": "^4.1.11"
|
|
111
112
|
}
|
|
112
113
|
}
|
package/src/before-send.ts
CHANGED
|
@@ -50,6 +50,12 @@ export function applyBeforeSend(
|
|
|
50
50
|
}
|
|
51
51
|
try {
|
|
52
52
|
const result = hook(cloneEvent(event));
|
|
53
|
+
// Hooks have synchronous return contracts. Contain mistaken async failures
|
|
54
|
+
// before treating their Promise as invalid and keeping the protected original.
|
|
55
|
+
if (result instanceof Promise) {
|
|
56
|
+
void result.catch(() => undefined);
|
|
57
|
+
return event;
|
|
58
|
+
}
|
|
53
59
|
if (result === null) {
|
|
54
60
|
return null;
|
|
55
61
|
}
|