Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
@@ -57,5 +57,5 @@ function isPromiseLike(value: unknown): value is PromiseLike<void> {
|
||||
}
|
||||
|
||||
export { sanitizeErrorReportValue } from "./sanitize.js";
|
||||
export { createSentryErrorReporter, type SentryErrorReporterOptions, type SentryLikeModule, type SentryInitOptions } from "./sentry.js";
|
||||
export { createSentryErrorReporter, sanitizeSentryEvent, type SentryErrorReporterOptions, type SentryLikeModule, type SentryInitOptions } from "./sentry.js";
|
||||
export { initializeTracing, shutdownTracing, type TracingOptions, type NodeSdkLikeModule, type NodeSdkInstance, type OtlpExporterLikeModule } from "./tracing.js";
|
||||
+139
-16
@@ -23,18 +23,14 @@ describe("sanitizeSentryEvent", () => {
|
||||
"X-Csrf-Token": "csrf",
|
||||
"Set-Cookie": "session=abc",
|
||||
Cookie: "session=abc",
|
||||
Referer: "https://example.com",
|
||||
Referer: "https://example.com/private?token=secret",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(result).not.toBeNull();
|
||||
const headers = (result?.request as { headers: Record<string, unknown> }).headers;
|
||||
expect(Object.keys(headers).map((k) => k.toLowerCase()).sort()).toEqual([
|
||||
"content-type",
|
||||
"referer",
|
||||
"user-agent",
|
||||
]);
|
||||
expect(Object.keys(headers).map((k) => k.toLowerCase()).sort()).toEqual(["content-type", "user-agent"]);
|
||||
expect(headers).not.toHaveProperty("Authorization");
|
||||
expect(headers).not.toHaveProperty("X-API-Key");
|
||||
expect(headers).not.toHaveProperty("Cookie");
|
||||
@@ -88,22 +84,102 @@ describe("sanitizeSentryEvent", () => {
|
||||
).not.toBeNull();
|
||||
});
|
||||
|
||||
it("redacts known query-string secret keys without dropping other params", () => {
|
||||
it("drops request query strings and URL fragments wholesale", () => {
|
||||
const result = sanitizeSentryEvent({
|
||||
request: {
|
||||
url: "https://api.example.com/x",
|
||||
url: "https://api.example.com/x?id=42&token=abc#private",
|
||||
query_string: "id=42&token=abc&apiKey=xyz&page=2",
|
||||
headers: {},
|
||||
},
|
||||
});
|
||||
|
||||
const q = (result?.request as { query_string: string }).query_string;
|
||||
expect(q).toContain("id=42");
|
||||
expect(q).toContain("page=2");
|
||||
expect(q).toContain("token=[Redacted]");
|
||||
expect(q).toContain("apiKey=[Redacted]");
|
||||
expect(q).not.toContain("abc");
|
||||
expect(q).not.toContain("xyz");
|
||||
const request = result?.request as { query_string: string; url: string };
|
||||
expect(request.query_string).toBe("[Redacted]");
|
||||
expect(request.url).toBe("https://api.example.com/x");
|
||||
});
|
||||
|
||||
it("redacts bearer tokens embedded in sensitive route paths", () => {
|
||||
const result = sanitizeSentryEvent({
|
||||
request: {
|
||||
url: "https://app.example.com/invitation/raw-owner-token?source=mail#claim",
|
||||
headers: {},
|
||||
},
|
||||
breadcrumbs: [
|
||||
{
|
||||
category: "navigation",
|
||||
data: {
|
||||
from: "/verify/raw-registration-token?request=secret",
|
||||
to: "/app/acme/settings/privacy/delete/confirm/raw-delete-token",
|
||||
},
|
||||
},
|
||||
],
|
||||
spans: [{ description: "GET /sign/raw-signature-token?utm_source=mail" }],
|
||||
});
|
||||
|
||||
expect((result?.request as { url: string }).url).toBe("https://app.example.com/invitation/redacted");
|
||||
expect(result?.breadcrumbs).toEqual([
|
||||
{
|
||||
category: "navigation",
|
||||
data: {
|
||||
from: "/verify/redacted",
|
||||
to: "[Redacted]",
|
||||
},
|
||||
},
|
||||
]);
|
||||
expect(result?.spans).toEqual([{ description: "GET /sign/redacted" }]);
|
||||
expect(JSON.stringify(result)).not.toContain("raw-owner-token");
|
||||
expect(JSON.stringify(result)).not.toContain("raw-registration-token");
|
||||
expect(JSON.stringify(result)).not.toContain("raw-delete-token");
|
||||
expect(JSON.stringify(result)).not.toContain("raw-signature-token");
|
||||
});
|
||||
|
||||
it("redacts public and internal customer-portal capability paths everywhere in an event", () => {
|
||||
const magicToken = "m".repeat(43);
|
||||
const setupToken = "s".repeat(43);
|
||||
const verifyToken = "v".repeat(43);
|
||||
const resetToken = "r".repeat(43);
|
||||
const result = sanitizeSentryEvent({
|
||||
transaction: `pageload /__portal/acme/reset-password/${resetToken}?source=mail`,
|
||||
request: {
|
||||
url: `https://portal.example.test/acme/login/magic/${magicToken}?source=mail#open`,
|
||||
headers: {},
|
||||
},
|
||||
breadcrumbs: [
|
||||
{
|
||||
category: "navigation",
|
||||
message: `opened /acme/setup/${setupToken}`,
|
||||
data: { from: `/__portal/acme/verify-email/${verifyToken}?source=mail` },
|
||||
},
|
||||
],
|
||||
spans: [
|
||||
{
|
||||
name: `navigation /acme/reset-password/${resetToken}`,
|
||||
description: `GET /__portal/acme/verify-email/${verifyToken}?source=mail`,
|
||||
data: { "url.full": `https://portal.example.test/acme/setup/${setupToken}?source=mail` },
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(result).toMatchObject({
|
||||
transaction: "pageload /__portal/acme/reset-password/redacted",
|
||||
request: { url: "https://portal.example.test/acme/login/magic/redacted" },
|
||||
breadcrumbs: [
|
||||
{
|
||||
message: "opened /acme/setup/redacted",
|
||||
data: { from: "/__portal/acme/verify-email/redacted" },
|
||||
},
|
||||
],
|
||||
spans: [
|
||||
{
|
||||
name: "navigation /acme/reset-password/redacted",
|
||||
description: "GET /__portal/acme/verify-email/redacted",
|
||||
data: { "url.full": "https://portal.example.test/acme/setup/redacted" },
|
||||
},
|
||||
],
|
||||
});
|
||||
for (const token of [magicToken, setupToken, verifyToken, resetToken]) {
|
||||
expect(JSON.stringify(result)).not.toContain(token);
|
||||
}
|
||||
});
|
||||
|
||||
it("redacts request.cookies wholesale", () => {
|
||||
@@ -129,9 +205,56 @@ describe("sanitizeSentryEvent", () => {
|
||||
});
|
||||
|
||||
it("exposes the canonical header allowlist", () => {
|
||||
for (const h of ["content-type", "user-agent", "accept-language", "accept-encoding", "x-request-id", "x-forwarded-for", "referer"]) {
|
||||
for (const h of ["content-type", "user-agent", "accept-language", "accept-encoding", "x-request-id"]) {
|
||||
expect(SENTRY_HEADER_ALLOWLIST.has(h)).toBe(true);
|
||||
}
|
||||
expect(SENTRY_HEADER_ALLOWLIST.has("x-forwarded-for")).toBe(false);
|
||||
expect(SENTRY_HEADER_ALLOWLIST.has("referer")).toBe(false);
|
||||
});
|
||||
|
||||
it("redacts exception and message secret text", () => {
|
||||
const result = sanitizeSentryEvent({
|
||||
exception: { values: [{ type: "Error", value: "provider token=raw-secret failed" }] },
|
||||
message: "Bearer raw-bearer-token failed",
|
||||
});
|
||||
expect(JSON.stringify(result)).not.toContain("raw-secret");
|
||||
expect(JSON.stringify(result)).not.toContain("raw-bearer-token");
|
||||
});
|
||||
|
||||
it("scrubs URL fields and descriptions throughout transaction spans", () => {
|
||||
const result = sanitizeSentryEvent({
|
||||
spans: [
|
||||
{
|
||||
description: "GET https://api.example.test/customers?email=alice@example.test#private",
|
||||
data: {
|
||||
"http.url": "https://api.example.test/customers?email=alice@example.test#private",
|
||||
"http.target": "/customers?email=alice@example.test",
|
||||
nested: { "url.full": "https://example.test/reset?token=raw" },
|
||||
},
|
||||
},
|
||||
],
|
||||
measurements: { payload: { password: "raw" } },
|
||||
});
|
||||
|
||||
expect(result?.spans).toEqual([
|
||||
{
|
||||
description: "GET https://api.example.test/customers",
|
||||
data: {
|
||||
"http.url": "https://api.example.test/customers",
|
||||
"http.target": "/customers",
|
||||
nested: { "url.full": "https://example.test/reset" },
|
||||
},
|
||||
},
|
||||
]);
|
||||
expect(result?.measurements).toEqual({ payload: { password: "[Redacted]" } });
|
||||
});
|
||||
|
||||
it("scrubs URL fields inside breadcrumbs", () => {
|
||||
const result = sanitizeSentryEvent({
|
||||
breadcrumbs: [{ category: "navigation", data: { from: "/", url: "/account?invite=secret#member" } }],
|
||||
});
|
||||
|
||||
expect(result?.breadcrumbs).toEqual([{ category: "navigation", data: { from: "/", url: "/account" } }]);
|
||||
});
|
||||
|
||||
it("exposes the canonical exception drop list", () => {
|
||||
|
||||
@@ -50,8 +50,6 @@ export const SENTRY_HEADER_ALLOWLIST = new Set<string>([
|
||||
"accept-language",
|
||||
"accept-encoding",
|
||||
"x-request-id",
|
||||
"x-forwarded-for",
|
||||
"referer",
|
||||
]);
|
||||
|
||||
/**
|
||||
@@ -214,7 +212,15 @@ export function sanitizeSentryEvent(raw: Record<string, unknown>): Record<string
|
||||
return null;
|
||||
}
|
||||
|
||||
const result: Record<string, unknown> = { ...raw };
|
||||
const result = sanitizeUrlFields(sanitizeErrorReportValue(raw)) as Record<string, unknown>;
|
||||
|
||||
if (raw.exception !== undefined) {
|
||||
result.exception = sanitizeErrorReportValue(raw.exception);
|
||||
}
|
||||
|
||||
if (typeof raw.message === "string") {
|
||||
result.message = sanitizeErrorReportValue(raw.message);
|
||||
}
|
||||
|
||||
if (raw.request && typeof raw.request === "object") {
|
||||
result.request = sanitizeRequest(raw.request as Record<string, unknown>);
|
||||
@@ -225,7 +231,7 @@ export function sanitizeSentryEvent(raw: Record<string, unknown>): Record<string
|
||||
}
|
||||
|
||||
if (Array.isArray(raw.breadcrumbs)) {
|
||||
result.breadcrumbs = (raw.breadcrumbs as unknown[]).map((crumb) => sanitizeErrorReportValue(crumb));
|
||||
result.breadcrumbs = (raw.breadcrumbs as unknown[]).map((crumb) => sanitizeUrlFields(sanitizeErrorReportValue(crumb)));
|
||||
}
|
||||
|
||||
if (raw.tags && typeof raw.tags === "object") {
|
||||
@@ -240,7 +246,19 @@ export function sanitizeSentryEvent(raw: Record<string, unknown>): Record<string
|
||||
result.extra = sanitizeErrorReportValue(raw.extra) as Record<string, unknown>;
|
||||
}
|
||||
|
||||
return result;
|
||||
if (Array.isArray(raw.spans)) {
|
||||
result.spans = raw.spans.map(sanitizeSentrySpan);
|
||||
}
|
||||
|
||||
if (typeof raw.transaction === "string") {
|
||||
result.transaction = stripSpanDescriptionQuery(raw.transaction);
|
||||
}
|
||||
|
||||
// Capability URLs can surface outside canonical URL fields (for example in
|
||||
// navigation breadcrumb messages or transaction names). Apply the narrow
|
||||
// portal-route redactor once more across the completed event so those
|
||||
// one-time credentials can never leave the process through Sentry.
|
||||
return redactPortalCapabilityTokensInValue(result) as Record<string, unknown>;
|
||||
}
|
||||
|
||||
function shouldDropEvent(raw: Record<string, unknown>): boolean {
|
||||
@@ -264,7 +282,11 @@ function shouldDropEvent(raw: Record<string, unknown>): boolean {
|
||||
}
|
||||
|
||||
function sanitizeRequest(request: Record<string, unknown>): Record<string, unknown> {
|
||||
const sanitized: Record<string, unknown> = { ...request };
|
||||
const sanitized = sanitizeUrlFields(sanitizeErrorReportValue(request)) as Record<string, unknown>;
|
||||
|
||||
if (typeof request.url === "string") {
|
||||
sanitized.url = stripUrlQueryAndFragment(request.url);
|
||||
}
|
||||
|
||||
if (request.headers && typeof request.headers === "object") {
|
||||
sanitized.headers = filterAllowedHeaders(request.headers as Record<string, unknown>);
|
||||
@@ -279,12 +301,69 @@ function sanitizeRequest(request: Record<string, unknown>): Record<string, unkno
|
||||
}
|
||||
|
||||
if (typeof request.query_string === "string") {
|
||||
sanitized.query_string = sanitizeQueryString(request.query_string);
|
||||
sanitized.query_string = request.query_string.length > 0 ? "[Redacted]" : "";
|
||||
}
|
||||
|
||||
return sanitized;
|
||||
}
|
||||
|
||||
const SENTRY_URL_FIELD_KEYS = new Set([
|
||||
"from",
|
||||
"http.target",
|
||||
"http.url",
|
||||
"originalurl",
|
||||
"request.url",
|
||||
"url",
|
||||
"url.full",
|
||||
"url.path",
|
||||
]);
|
||||
|
||||
const SENSITIVE_ROUTE_TOKEN_PARENTS = new Set(["invitation", "optin", "sign", "unsubscribe", "verify"]);
|
||||
const PORTAL_CAPABILITY_ROUTE_PATTERN =
|
||||
/((?:\/__portal)?\/[a-z0-9][a-z0-9-]{1,62}\/(?:login\/magic|setup|verify-email|reset-password)\/)[A-Za-z0-9_-]+/giu;
|
||||
|
||||
function sanitizeUrlFields(value: unknown, key?: string): unknown {
|
||||
if (typeof value === "string") {
|
||||
return key && SENTRY_URL_FIELD_KEYS.has(key.trim().toLowerCase()) ? stripUrlQueryAndFragment(value) : value;
|
||||
}
|
||||
if (Array.isArray(value)) {
|
||||
return value.map((entry) => sanitizeUrlFields(entry));
|
||||
}
|
||||
if (!value || typeof value !== "object") {
|
||||
return value;
|
||||
}
|
||||
|
||||
return Object.fromEntries(Object.entries(value).map(([entryKey, entryValue]) => [entryKey, sanitizeUrlFields(entryValue, entryKey)]));
|
||||
}
|
||||
|
||||
function sanitizeSentrySpan(value: unknown): unknown {
|
||||
const sanitized = sanitizeUrlFields(sanitizeErrorReportValue(value));
|
||||
if (!sanitized || typeof sanitized !== "object" || Array.isArray(sanitized)) {
|
||||
return sanitized;
|
||||
}
|
||||
|
||||
const result = sanitized as Record<string, unknown>;
|
||||
if (typeof result.description === "string") {
|
||||
result.description = stripSpanDescriptionQuery(result.description);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function stripSpanDescriptionQuery(value: string): string {
|
||||
const methodAndTarget = /^(?<method>[A-Z]{2,10}\s+)(?<target>\S+)$/u.exec(value);
|
||||
if (methodAndTarget?.groups) {
|
||||
return `${methodAndTarget.groups.method}${stripUrlQueryAndFragment(methodAndTarget.groups.target ?? "")}`;
|
||||
}
|
||||
if (value.startsWith("/") || /^[A-Za-z][A-Za-z0-9+.-]*:/u.test(value)) {
|
||||
return stripUrlQueryAndFragment(value);
|
||||
}
|
||||
const labelledTarget = /^(?<label>[^/]*?\s)(?<target>\/\S+)$/u.exec(value);
|
||||
if (labelledTarget?.groups) {
|
||||
return `${labelledTarget.groups.label}${stripUrlQueryAndFragment(labelledTarget.groups.target ?? "")}`;
|
||||
}
|
||||
return redactPortalCapabilityTokensInText(value);
|
||||
}
|
||||
|
||||
function filterAllowedHeaders(headers: Record<string, unknown>): Record<string, unknown> {
|
||||
const allowed: Record<string, unknown> = {};
|
||||
for (const [rawKey, value] of Object.entries(headers)) {
|
||||
@@ -297,14 +376,52 @@ function filterAllowedHeaders(headers: Record<string, unknown>): Record<string,
|
||||
return allowed;
|
||||
}
|
||||
|
||||
const QUERY_REDACT_KEYS = new Set<string>(["token", "accesstoken", "refreshtoken", "apikey", "secret", "password"]);
|
||||
function stripUrlQueryAndFragment(value: string): string {
|
||||
try {
|
||||
const absolute = /^[A-Za-z][A-Za-z0-9+.-]*:/u.test(value);
|
||||
const parsed = new URL(value, "https://redaction.invalid");
|
||||
parsed.search = "";
|
||||
parsed.hash = "";
|
||||
parsed.pathname = redactSensitiveRouteTokens(parsed.pathname);
|
||||
return absolute ? parsed.toString() : parsed.pathname;
|
||||
} catch {
|
||||
return String(sanitizeErrorReportValue(value));
|
||||
}
|
||||
}
|
||||
|
||||
function sanitizeQueryString(value: string): string {
|
||||
return value.replace(/([?&]?)([^=&]+)=([^&]*)/g, (_match, sep: string, key: string, rawValue: string) => {
|
||||
const compact = key.toLowerCase().replace(/[-_]/g, "");
|
||||
if (QUERY_REDACT_KEYS.has(compact)) {
|
||||
return `${sep}${key}=[Redacted]`;
|
||||
function redactSensitiveRouteTokens(pathname: string): string {
|
||||
const segments = pathname.split("/");
|
||||
for (let index = 1; index < segments.length; index += 1) {
|
||||
const parent = segments[index - 1]?.toLowerCase();
|
||||
if (parent && SENSITIVE_ROUTE_TOKEN_PARENTS.has(parent) && segments[index]) {
|
||||
segments[index] = "redacted";
|
||||
}
|
||||
return `${sep}${key}=${rawValue}`;
|
||||
});
|
||||
}
|
||||
|
||||
for (let index = 4; index < segments.length; index += 1) {
|
||||
const prefix = segments.slice(index - 4, index).map((segment) => segment.toLowerCase());
|
||||
if (prefix.join("/") === "settings/privacy/delete/confirm" && segments[index]) {
|
||||
segments[index] = "redacted";
|
||||
}
|
||||
}
|
||||
return redactPortalCapabilityTokensInText(segments.join("/"));
|
||||
}
|
||||
|
||||
function redactPortalCapabilityTokensInText(value: string): string {
|
||||
return value.replace(PORTAL_CAPABILITY_ROUTE_PATTERN, "$1redacted");
|
||||
}
|
||||
|
||||
function redactPortalCapabilityTokensInValue(value: unknown): unknown {
|
||||
if (typeof value === "string") {
|
||||
return redactPortalCapabilityTokensInText(value);
|
||||
}
|
||||
if (Array.isArray(value)) {
|
||||
return value.map(redactPortalCapabilityTokensInValue);
|
||||
}
|
||||
if (!value || typeof value !== "object") {
|
||||
return value;
|
||||
}
|
||||
return Object.fromEntries(
|
||||
Object.entries(value).map(([key, entry]) => [key, redactPortalCapabilityTokensInValue(entry)]),
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user