fix(browser): preserve form destinations and satisfies mutation uncertainty (#825)
Resolve empty form destinations from the captured document URL while preserving base-relative links and Chrome's form/control whitespace distinction. Follow satisfies wrappers when propagating explicit member mutation paths. Add fail-before regressions and real-browser CLI/MCP verification. Fixes #820 Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis) Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing)
This commit is contained in:
@@ -113,3 +113,81 @@ describe("DOM metadata document base URLs", () => {
|
||||
expect(result.agentHints).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("empty form destinations with a document base URL", () => {
|
||||
it.each([
|
||||
{ nodeName: "FORM", attribute: "action" },
|
||||
{ nodeName: "BUTTON", attribute: "formaction" },
|
||||
{ nodeName: "INPUT", attribute: "formaction" },
|
||||
])(
|
||||
"resolves an empty $nodeName $attribute to the document",
|
||||
({ nodeName, attribute }) => {
|
||||
const pageUrl = `${documentUrl}?selected=fixture#section`;
|
||||
const baseUrl = `${origin}/assets/`;
|
||||
const value = snapshot(baseUrl, "/assets/", pageUrl, "");
|
||||
value.strings[6] = nodeName;
|
||||
value.strings[14] = attribute;
|
||||
value.strings[15] = "";
|
||||
const result = capture(value);
|
||||
expect(result.urls[3]).toMatchObject({
|
||||
attribute,
|
||||
url: pageUrl,
|
||||
destination_scope: "approved",
|
||||
});
|
||||
expect(result.urls[1]?.url).toBe(baseUrl);
|
||||
},
|
||||
);
|
||||
|
||||
it("keeps an empty form action approved when the document base is foreign", () => {
|
||||
const foreign = "https://cdn.example.test/assets/";
|
||||
const value = snapshot(foreign, foreign);
|
||||
value.strings[15] = "";
|
||||
expect(capture(value).urls[3]).toMatchObject({
|
||||
url: documentUrl,
|
||||
destination_scope: "approved",
|
||||
});
|
||||
});
|
||||
|
||||
it.each([" ", "\t\r\n\f"])(
|
||||
"resolves an HTML-whitespace-only form action to the document: %j",
|
||||
(action) => {
|
||||
const baseUrl = `${origin}/assets/`;
|
||||
const value = snapshot(baseUrl);
|
||||
value.strings[15] = action;
|
||||
expect(capture(value).urls[3]?.url).toBe(documentUrl);
|
||||
},
|
||||
);
|
||||
|
||||
it.each(["BUTTON", "INPUT"])(
|
||||
"retains document-base resolution for a whitespace-only %s formaction",
|
||||
(nodeName) => {
|
||||
const baseUrl = `${origin}/assets/`;
|
||||
const value = snapshot(baseUrl);
|
||||
value.strings[6] = nodeName;
|
||||
value.strings[14] = "formaction";
|
||||
value.strings[15] = " ";
|
||||
expect(capture(value).urls[3]?.url).toBe(baseUrl);
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
{ value: "\u000b", suffix: "" },
|
||||
{ value: "\u00a0", suffix: "%C2%A0" },
|
||||
])(
|
||||
"does not treat non-HTML whitespace as an empty form action: $value",
|
||||
({ value: action, suffix }) => {
|
||||
const baseUrl = `${origin}/assets/`;
|
||||
const value = snapshot(baseUrl);
|
||||
value.strings[15] = action;
|
||||
expect(capture(value).urls[3]?.url).toBe(`${baseUrl}${suffix}`);
|
||||
},
|
||||
);
|
||||
|
||||
it("does not apply form semantics to an action attribute on another element", () => {
|
||||
const baseUrl = `${origin}/assets/`;
|
||||
const value = snapshot(baseUrl);
|
||||
value.strings[6] = "DIV";
|
||||
value.strings[15] = "";
|
||||
expect(capture(value).urls[3]?.url).toBe(baseUrl);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -194,6 +194,7 @@ export const captureDom = (
|
||||
attributes: attributeIndexes,
|
||||
// The BASE element itself resolves against the document fallback URL.
|
||||
baseUrl: nodeName.toLowerCase() === "base" ? documentUrl : baseUrl,
|
||||
documentUrl,
|
||||
nodeIndex,
|
||||
nodeName,
|
||||
allowedOrigins,
|
||||
@@ -363,6 +364,7 @@ interface DomMetadataOptions {
|
||||
readonly strings: readonly string[];
|
||||
readonly attributes: readonly number[];
|
||||
readonly baseUrl: string;
|
||||
readonly documentUrl: string;
|
||||
readonly nodeIndex: number;
|
||||
readonly nodeName: string;
|
||||
readonly allowedOrigins: ReadonlySet<string>;
|
||||
@@ -374,8 +376,15 @@ const domMetadata = (
|
||||
readonly urls: WebPageInspection["metadata"]["dom_urls"];
|
||||
readonly agentHints: WebPageInspection["metadata"]["agent_hints"];
|
||||
} => {
|
||||
const { strings, attributes, baseUrl, nodeIndex, nodeName, allowedOrigins } =
|
||||
options;
|
||||
const {
|
||||
strings,
|
||||
attributes,
|
||||
baseUrl,
|
||||
documentUrl,
|
||||
nodeIndex,
|
||||
nodeName,
|
||||
allowedOrigins,
|
||||
} = options;
|
||||
const pairs = new Map<string, string>();
|
||||
for (let index = 0; index + 1 < attributes.length; index += 2) {
|
||||
const name = indexedString(strings, attributes[index]).toLowerCase();
|
||||
@@ -386,7 +395,21 @@ const domMetadata = (
|
||||
for (const attribute of domUrlAttributes) {
|
||||
const value = pairs.get(attribute);
|
||||
if (value === undefined) continue;
|
||||
const destination = domDestination(value, baseUrl, allowedOrigins);
|
||||
const tagName = nodeName.toLowerCase();
|
||||
// Chrome strips HTML whitespace for FORM.action, while submit controls
|
||||
// use the document URL only for an exactly empty formaction attribute.
|
||||
const usesDocumentUrl =
|
||||
(tagName === "form" &&
|
||||
attribute === "action" &&
|
||||
/^[\t\n\f\r ]*$/u.test(value)) ||
|
||||
((tagName === "button" || tagName === "input") &&
|
||||
attribute === "formaction" &&
|
||||
value === "");
|
||||
const destination = domDestination(
|
||||
usesDocumentUrl ? documentUrl : value,
|
||||
baseUrl,
|
||||
allowedOrigins,
|
||||
);
|
||||
urls.push({
|
||||
node_index: nodeIndex,
|
||||
attribute,
|
||||
|
||||
Reference in New Issue
Block a user