mirror of
https://github.com/morluto/rea.git
synced 2026-11-23 06:55:55 +00:00
perf(browser): eliminate duplicate CaptureRedaction scans, per-event Buffer allocs, and QLOG flatMap churn (#13581)
* perf(browser): eliminate duplicate CaptureRedaction scans, per-event Buffer allocs, and QLOG flatMap churn * fix(browser): preserve own __proto__ property in QlogCapture object projection * fix(browser): preserve capture extension and redaction semantics
This commit is contained in:
1 parent
0558c24924
commit
550289154e
4 files changed
+49
-21
No files matched your search
@@ -67,8 +67,10 @@ export class CaptureRedaction {
|
||||
}
|
||||
}
|
||||
if (
|
||||
explicitValuesOccurIn(value, this.sensitiveValues) ||
|
||||
explicitValuesOccurIn(result, this.sensitiveValues)
|
||||
this.sensitiveValues.length > 0 &&
|
||||
(explicitValuesOccurIn(value, this.sensitiveValues) ||
|
||||
(result !== value &&
|
||||
explicitValuesOccurIn(result, this.sensitiveValues)))
|
||||
) {
|
||||
this.redactions.push({ pointer, reason: "explicit-sensitive-value" });
|
||||
return null;
|
||||
|
||||
@@ -56,6 +56,10 @@ it("derives interval unions per trace/direction while retaining event source ord
|
||||
enumerable: true,
|
||||
value: { ordinary: true },
|
||||
});
|
||||
Object.defineProperty(original.traces[0].events[0].data, "__proto__", {
|
||||
enumerable: true,
|
||||
value: { eventExtension: "kept" },
|
||||
});
|
||||
original.extra = "https://example.test/path?token=ordinary";
|
||||
const { decoded, traces } = facts(JSON.stringify(original));
|
||||
expect(traces[0]?.streams[0]).toMatchObject({
|
||||
@@ -88,6 +92,11 @@ it("derives interval unions per trace/direction while retaining event source ord
|
||||
extra: original.extra,
|
||||
["__proto__"]: { ordinary: true },
|
||||
});
|
||||
const container = decoded.container.reported;
|
||||
expect(Object.hasOwn(Object(container), "__proto__")).toBe(true);
|
||||
expect(decoded.records[0]?.reported).toMatchObject({
|
||||
data: { ["__proto__"]: { eventExtension: "kept" } },
|
||||
});
|
||||
expect(Reflect.get(Object.prototype, "ordinary")).toBeUndefined();
|
||||
});
|
||||
|
||||
|
||||
@@ -411,6 +411,9 @@ const unsigned = (value: unknown, pointer: string): bigint | null => {
|
||||
return result;
|
||||
};
|
||||
|
||||
const QLOG_HTTP_HEADER_VALUE_RE = /^\/data\/frame\/headers\/\d+\/value$/u;
|
||||
const QLOG_TRANSPORT_URL_HEADERS = new Set(["location", "referer", "origin"]);
|
||||
|
||||
/** Preserve JSON values/lexemes and structurally exclude only transport credentials and declared values. */
|
||||
const project = (
|
||||
value: unknown,
|
||||
@@ -419,6 +422,7 @@ const project = (
|
||||
const redactor = new CaptureRedaction(sensitiveValues);
|
||||
const numeric_literals: Projection["numeric_literals"] = [];
|
||||
const eventName = object(value) ? value.name : null;
|
||||
const hasSensitiveValues = sensitiveValues.length > 0;
|
||||
const visit = (
|
||||
item: unknown,
|
||||
pointer: string,
|
||||
@@ -427,7 +431,7 @@ const project = (
|
||||
const header =
|
||||
(eventName === "http:frame_created" ||
|
||||
eventName === "http:frame_parsed") &&
|
||||
/^\/data\/frame\/headers\/\d+\/value$/u.test(pointer) &&
|
||||
QLOG_HTTP_HEADER_VALUE_RE.test(pointer) &&
|
||||
typeof parent?.name === "string";
|
||||
if (
|
||||
(header && isTransportCredentialHeader(String(parent?.name))) ||
|
||||
@@ -449,9 +453,7 @@ const project = (
|
||||
item,
|
||||
pointer,
|
||||
header &&
|
||||
["location", "referer", "origin"].includes(
|
||||
String(parent?.name).toLowerCase(),
|
||||
)
|
||||
QLOG_TRANSPORT_URL_HEADERS.has(String(parent?.name).toLowerCase())
|
||||
? {}
|
||||
: undefined,
|
||||
);
|
||||
@@ -460,20 +462,32 @@ const project = (
|
||||
return item.map((child, index) =>
|
||||
visit(child, capturePointer(pointer, String(index))),
|
||||
);
|
||||
if (object(item))
|
||||
return Object.fromEntries(
|
||||
Object.entries(item).flatMap(([key, child]) => {
|
||||
if (sensitiveValues.some((literal) => key.includes(literal))) {
|
||||
redactor.redactions.push({
|
||||
pointer,
|
||||
reason: "explicit-sensitive-value",
|
||||
scope: "property-name",
|
||||
});
|
||||
return [];
|
||||
}
|
||||
return [[key, visit(child, capturePointer(pointer, key), item)]];
|
||||
}),
|
||||
);
|
||||
if (object(item)) {
|
||||
const projected: Record<string, JsonValue> = {};
|
||||
for (const [key, child] of Object.entries(item)) {
|
||||
if (
|
||||
hasSensitiveValues &&
|
||||
sensitiveValues.some((literal) => key.includes(literal))
|
||||
) {
|
||||
redactor.redactions.push({
|
||||
pointer,
|
||||
reason: "explicit-sensitive-value",
|
||||
scope: "property-name",
|
||||
});
|
||||
continue;
|
||||
}
|
||||
const projectedValue = visit(child, capturePointer(pointer, key), item);
|
||||
if (key === "__proto__")
|
||||
Object.defineProperty(projected, key, {
|
||||
value: projectedValue,
|
||||
enumerable: true,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
});
|
||||
else projected[key] = projectedValue;
|
||||
}
|
||||
return projected;
|
||||
}
|
||||
return invalid("qlog parser returned a non-JSON value.", pointer);
|
||||
};
|
||||
return {
|
||||
|
||||
@@ -12,6 +12,8 @@ export type SazValue =
|
||||
| { readonly [key: string]: SazValue }
|
||||
| readonly SazValue[];
|
||||
|
||||
const SAZ_HTTP_FIELD_POINTER_RE = /^\/(request|response)\//;
|
||||
|
||||
/** Project native byte fields with the same credential and explicit-literal exclusions as HAR. */
|
||||
export const projectSazRecord = (
|
||||
source: SazValue,
|
||||
@@ -73,7 +75,8 @@ export const projectSazRecord = (
|
||||
// HTTP fields are Latin-1 views of bytes. A UTF-8 declaration must also
|
||||
// exclude its byte spelling, even when its display is mojibake.
|
||||
if (
|
||||
/^\/(request|response)\//.test(pointer) &&
|
||||
sensitiveValues.length > 0 &&
|
||||
SAZ_HTTP_FIELD_POINTER_RE.test(pointer) &&
|
||||
!pointer.endsWith("/member") &&
|
||||
redactor.sensitiveBytes(Buffer.from(value, "latin1"))
|
||||
) {
|
||||
|
||||
Reference in new issue
Block a user