fix(ui): filter IPv6 Lighthouse context values

This commit is contained in:
alejandrobailo
2026-07-21 18:30:32 +02:00
parent 12ab8b3437
commit 400dc65ffb
3 changed files with 28 additions and 1 deletions
@@ -156,6 +156,7 @@ describe("Lighthouse page contributions", () => {
query: "MATCH (n) RETURN n",
ownerEmail: "security@example.com",
sourceIp: "10.0.0.1",
sourceIpv6: "2001:db8::1",
authHeader: "Bearer sensitive-value",
},
nodeCount: 12,
+6 -1
View File
@@ -131,13 +131,18 @@ describe("buildLighthousePageContext", () => {
const searchParams = new URLSearchParams();
searchParams.append("filter[search]", "security@example.com");
searchParams.append("filter[search]", "10.0.0.1");
searchParams.append("filter[search]", "2001:db8::1");
searchParams.append("filter[search]", "Bearer sensitive-value");
searchParams.append("filter[search]", "arn:aws:s3:::example");
searchParams.append("filter[search]", "12:30:00");
searchParams.append("filter[search]", "public bucket");
// When
const context = buildLighthousePageContext("/findings", searchParams);
// Then
expect(context.filters).toEqual({ search: ["public bucket"] });
expect(context.filters).toEqual({
search: ["arn:aws:s3:::example", "12:30:00", "public bucket"],
});
});
});
+21
View File
@@ -342,12 +342,33 @@ export function containsSensitiveLighthouseContextValue(
return (
/\b[^\s@]+@[^\s@]+\.[^\s@]+\b/.test(value) ||
/\b(?:\d{1,3}\.){3}\d{1,3}\b/.test(value) ||
containsIpv6Address(value) ||
/\bAKIA[A-Z0-9]{16}\b/.test(value) ||
/\bbearer\s+\S+/i.test(value) ||
/\b(?:password|secret|token|credential)\s*[:=]/i.test(value)
);
}
function containsIpv6Address(value: string): boolean {
return value
.split(/[^0-9A-Fa-f:]+/)
.some((candidate) => isIpv6AddressCandidate(candidate));
}
function isIpv6AddressCandidate(candidate: string): boolean {
if (!candidate.includes(":") || candidate.includes(":::")) return false;
const compressedParts = candidate.split("::");
if (compressedParts.length > 2) return false;
const segments = candidate.split(":").filter(Boolean);
if (segments.some((segment) => segment.length > 4)) return false;
return compressedParts.length === 2
? segments.length < 8
: segments.length === 8;
}
function toTitleCase(value: string): string {
if (!value) return "Current page";
return value