* feat(mcp): derive an API surface view from retained web network captures * fix(mcp): fail closed on sensitive parents and budget api-surface path expansion * fix(mcp): keep recorded api-surface paths and budget only templated segments * fix(mcp): read api-surface paths only from canonical URLs and charge new values once * fix(mcp): reject authority-less api-surface URLs and key groups by rule positions * fix(mcp): label api-surface confidence from all groups and cap transient path memory * fix(mcp): budget api-surface dedup sets and narrow detail outputs Charge retained deduplication sets before allocation, advertise only each analysis operation's summary from its detail output, and document that any templated group makes every API-surface page inferred. * fix(mcp): bound api-surface path text and record limitations Charge retained literal path copies before allocation, publish only valid media-type essences, and deduplicate examined record limitations onto the view. * fix(mcp): keep api-surface refusals and path splits inside the reply budget Sensitive-parent refusals now use the token sensitive_values_unretained so declared literals are not echoed. A later path split is charged against bytes already retained, and the published example includes the HAR record limitation with its matching digest. * fix(mcp): budget api-surface method text before group keys Charge method and origin text against the reply budget before the group key is serialized. Document that samples merge only when method, origin, and exact segment rules match. * fix(mcp): bound api-surface copies and control-character authorities Reject authorities containing a tab or newline so WHATWG cannot move userinfo into the recorded path. Charge four path copies, two method and origin copies, and each distinct content type against bytes already retained. * fix(mcp): preflight combined api-surface group charges Total path, method, origin, and segment charges before retaining a new group. Track content types in a set so distinct MIME essences are not compared quadratically. * fix(mcp): charge api-surface content-type sets on first use Create the per-group content-type set when the first essence is retained, and charge it before allocation. Groups with no content type no longer keep an empty set. * refactor(analysis): centralize API-surface ownership and admission Own grouping, deduplication, and combined retained/temporary resource admission in one accumulator. Charge fixed group storage before allocation and materialize only the requested page. Share recorded URL parsing between capture redaction and projection, preserving source paths and excluding ambiguous credential fields. Cover resource admission invariants and the compiled HAR-to-view workflow. * fix(analysis): admit capture schema clone before parsing * fix(javascript): share Electron mutation proof with wrapped calls * test(mcp): align graph and catalog checks with current contracts * fix(analysis): admit and validate portable capture views --------- Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
108 lines
3.8 KiB
TypeScript
108 lines
3.8 KiB
TypeScript
import { expect, it } from "vitest";
|
|
import { CaptureRedaction } from "./CaptureRedaction.js";
|
|
|
|
it.each([
|
|
{
|
|
value: " https://user:password@example.test/path ",
|
|
expected: " https://example.test/path ",
|
|
},
|
|
{
|
|
value: "\tHTTPS://user:password@example.test/path\t",
|
|
expected: "\tHTTPS://example.test/path\t",
|
|
},
|
|
{
|
|
value: " \t//user:password@example.test/path?token=ordinary#fragment\t ",
|
|
expected: " \t//example.test/path?token=ordinary#fragment\t ",
|
|
},
|
|
{
|
|
value: "\r\n \v\fhttps://user:password@example.test/path",
|
|
expected: "\r\n \v\fhttps://example.test/path",
|
|
},
|
|
{
|
|
value: "\u0000\u001f//user:password@example.test/path",
|
|
expected: "\u0000\u001f//example.test/path",
|
|
},
|
|
])(
|
|
"excludes URL userinfo after optional whitespace while preserving the original header text: $value",
|
|
({ value, expected }) => {
|
|
const redactor = new CaptureRedaction([]);
|
|
expect(redactor.text(value, "/response/headers/0/value", true)).toBe(
|
|
expected,
|
|
);
|
|
expect(redactor.redactions).toEqual([
|
|
{ pointer: "/response/headers/0/value", reason: "transport-credential" },
|
|
]);
|
|
},
|
|
);
|
|
|
|
it("preserves the same URL-looking text in an ordinary extension", () => {
|
|
const redactor = new CaptureRedaction([]);
|
|
const value = " \thttps://user:password@example.test/path\t ";
|
|
expect(redactor.text(value, "/_extension")).toBe(value);
|
|
expect(redactor.redactions).toEqual([]);
|
|
});
|
|
|
|
it.each([
|
|
"https:user:password@example.test/path",
|
|
"https:///user:password@example.test/path",
|
|
"https://\\user:password@example.test/path",
|
|
"https://\t/user:password@example.test/path",
|
|
"https://\n/user:password@example.test/path",
|
|
"https://\r/user:password@example.test/path",
|
|
"ht\ttps://user:password@example.test/path",
|
|
"\\\\user:password@example.test/path",
|
|
"/\\user:password@example.test/path",
|
|
"\\/user:password@example.test/path",
|
|
"/\t/user:password@example.test/path",
|
|
])("excludes credentials whose raw URL span is ambiguous: %s", (value) => {
|
|
const redactor = new CaptureRedaction([]);
|
|
expect(redactor.text(value, "/request/url", true)).toBeNull();
|
|
expect(redactor.redactions).toEqual([
|
|
{ pointer: "/request/url", reason: "transport-credential" },
|
|
]);
|
|
expect(new CaptureRedaction([]).text(value, "/_extension")).toBe(value);
|
|
});
|
|
|
|
it("uses non-special URL authority rules to remove the complete userinfo span", () => {
|
|
const value = "custom://user:secret@part\\more:password@host/path";
|
|
const redactor = new CaptureRedaction([]);
|
|
expect(redactor.text(value, "/response/redirectURL", true)).toBe(
|
|
"custom://host/path",
|
|
);
|
|
expect(redactor.redactions).toEqual([
|
|
{ pointer: "/response/redirectURL", reason: "transport-credential" },
|
|
]);
|
|
});
|
|
|
|
it("preserves noncanonical URLs and path/query userinfo lookalikes without parsed credentials", () => {
|
|
for (const value of [
|
|
"https:example.test/path?token=ordinary",
|
|
"https://example.test/a/%2e%2e/user:password@literal?url=user:password@literal",
|
|
"https://example.test\\user:password@literal",
|
|
"https://invalid host\\user:password@literal",
|
|
"//invalid host\\user:password@literal",
|
|
]) {
|
|
const redactor = new CaptureRedaction([]);
|
|
expect(redactor.text(value, "/request/url", true)).toBe(value);
|
|
expect(redactor.redactions).toEqual([]);
|
|
}
|
|
});
|
|
|
|
it.each(["\ud800", "\udfff"])(
|
|
"does not invent replacement UTF-8 bytes for a non-scalar declaration",
|
|
(literal) => {
|
|
const redactor = new CaptureRedaction([literal]);
|
|
expect(redactor.sensitiveBytes(Buffer.from("\ufffd"))).toBe(false);
|
|
expect(redactor.text(literal, "/reported")).toBe(null);
|
|
},
|
|
);
|
|
|
|
it("matches scalar UTF-8 declarations and complete surrogate pairs exactly", () => {
|
|
expect(
|
|
new CaptureRedaction(["\ufffd"]).sensitiveBytes(Buffer.from("\ufffd")),
|
|
).toBe(true);
|
|
expect(
|
|
new CaptureRedaction(["\ud83d\ude00"]).sensitiveBytes(Buffer.from("😀")),
|
|
).toBe(true);
|
|
});
|