fix: integrate 24 reviewed browser/native/semantics corrections (#815)

* fix(reference): resolve emitted extensions to TypeScript source

Signed-off-by: Rudy Celekli <rudy@gradiahq.com>

* test(reference): retain legitimate declaration import counterparts

Signed-off-by: Rudy Celekli <rudy@gradiahq.com>

* fix(mcp): recognize implicit form elicitation capability

Signed-off-by: RudyCelekli <47457359+rudycelekli@users.noreply.github.com>

* fix(ghidra): reject contradictory NativeAOT reports

* fix(native): preserve thin architectures across echoed filename lines

Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>

* fix(native): preserve app bundle executable filename whitespace

Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>

* fix(doctor): validate Node-wrapped client policy

Signed-off-by: RudyCelekli <47457359+rudycelekli@users.noreply.github.com>

* fix(reference): preserve observed entry failure reasons

Signed-off-by: Rudy Celekli <rudy@gradiahq.com>

* fix(artifacts): verify opaque bytes before reusing inventory identities

Signed-off-by: Rudy Celekli <rudy@gradiahq.com>

* fix(browser): resolve DOM destinations against document base URL

Signed-off-by: Rudy Celekli <rudy@gradiahq.com>

* fix: recover serialized native NIB view hierarchy

Signed-off-by: RudyCelekli <47457359+rudycelekli@users.noreply.github.com>

* ci: exercise native compiled NIB hierarchy regressions

Signed-off-by: RudyCelekli <47457359+rudycelekli@users.noreply.github.com>

* fix(deps): remediate reachable archive-parsing advisories

Two high-severity advisories are reachable from untrusted target content:

- @xmldom/xmldom 0.9.10 (via plist) parses XML plist bytes from analyzed
  app bundles in the keyed-archive reader. Refreshed to 0.9.12.
- brace-expansion 5.0.7 (via @electron/asar -> minimatch) is reached while
  analyzing untrusted ASAR archives. Refreshed to 5.0.12.

Both are in-range patch updates (plist declares ^0.9.10, minimatch declares
^5.0.5), so no source or API change is required and no direct dependency
declaration moves. Lockfile-only change.

The remaining smol-toml advisory is not included: it parses operator-owned
client configuration rather than untrusted target content, and its fix moves
outside the declared range and changes leading-BOM handling.

* fix(semantics): link wrapped arrow Promise returns

* fix(reconstruction): preserve unknown graph limitations

* fix(native): preserve exact code signing identifiers

Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>

* fix(native): recognize only whole otool command headers

Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>

* fix(native): retain nm-proven literal export names

Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>

* fix(javascript): project decoded file URL paths

Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>

* fix: preserve explicit source-relative URL observation spelling

Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>

* fix(native): project Mach-O evidence into container file offsets

Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>

* fix(browser): normalize referrer policy fallback lists

Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>

---------

Signed-off-by: Rudy Celekli <rudy@gradiahq.com>
Signed-off-by: RudyCelekli <47457359+rudycelekli@users.noreply.github.com>
Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>
Co-authored-by: Rudy Celekli <rudy@gradiahq.com>
Co-authored-by: RudyCelekli <47457359+rudycelekli@users.noreply.github.com>
Co-authored-by: Kaoru0822 <aisakamimaki@gmail.com>
Co-authored-by: DeryFerd <deryferdikao125@gmail.com>
This commit is contained in:
morluto
2026-10-07 10:33:10 +08:00
committed by GitHub
co-authored by Rudy Celekli RudyCelekli Kaoru0822 DeryFerd
parent 2572e1eb2f
commit 3af3811ab0
43 changed files with 2032 additions and 82 deletions
@@ -0,0 +1,115 @@
import { describe, expect, it } from "vitest";
import { inspectWebPageInputSchema } from "../domain/browserObservation.js";
import { captureDom } from "./CdpCaptureDocuments.js";
const origin = "https://app.example.test";
const documentUrl = `${origin}/screens/app`;
const input = inspectWebPageInputSchema.parse({
cdp_endpoint: "http://127.0.0.1:9222",
allowed_origins: [origin],
target_id: "page-1",
});
const snapshot = (
baseUrl?: string,
baseHref = "assets/",
pageUrl = documentUrl,
linkHref = "guide",
) => ({
strings: [
pageUrl,
baseUrl ?? "",
"#document",
"BASE",
"A",
"LINK",
"FORM",
"",
"href",
baseHref,
linkHref,
"rel",
"mcp",
"agent",
"action",
"submit",
],
documents: [
{
documentURL: 0,
...(baseUrl === undefined ? {} : { baseURL: 1 }),
nodes: {
nodeType: [9, 1, 1, 1, 1],
nodeName: [2, 3, 4, 5, 6],
nodeValue: [7, 7, 7, 7, 7],
parentIndex: [-1, 0, 0, 0, 0],
attributes: [[], [8, 9], [8, 10], [8, 13, 11, 12], [14, 15]],
},
},
],
});
const capture = (value: ReturnType<typeof snapshot>) =>
captureDom(value, new Set([origin]), input);
describe("DOM metadata document base URLs", () => {
it("resolves links, actions and agent hints against the captured document base", () => {
const result = capture(snapshot(`${origin}/screens/assets/`));
expect(result.urls.map(({ url }) => url)).toEqual([
`${origin}/screens/assets/`,
`${origin}/screens/assets/guide`,
`${origin}/screens/assets/agent`,
`${origin}/screens/assets/submit`,
]);
expect(result.agentHints[0]?.url).toBe(`${origin}/screens/assets/agent`);
});
it("uses the document URL as fallback when no baseURL was supplied", () => {
const result = capture(snapshot());
expect(result.urls.map(({ url }) => url)).toEqual([
`${origin}/screens/assets/`,
`${origin}/screens/guide`,
`${origin}/screens/agent`,
`${origin}/screens/submit`,
]);
});
it("applies destination policy after resolving an ordinary foreign base", () => {
const foreign = "https://cdn.example.test/assets/";
const result = capture(snapshot(foreign, foreign));
expect(result.nodes).toHaveLength(5);
expect(result.urls).toHaveLength(4);
expect(
result.urls.every(
({ url, destination_scope }) =>
url === null && destination_scope === "outside_policy",
),
).toBe(true);
expect(result.agentHints[0]?.url).toBeNull();
});
it("keeps an absolute approved link independent of a foreign base", () => {
const foreign = "https://cdn.example.test/assets/";
const result = capture(
snapshot(foreign, foreign, documentUrl, `${origin}/guide`),
);
expect(result.urls[1]).toMatchObject({
url: `${origin}/guide`,
destination_scope: "approved",
});
});
it("does not authorize a foreign document using its approved base URL", () => {
const result = capture(
snapshot(
`${origin}/assets/`,
"assets/",
"https://outside.example.test/app",
),
);
expect(result.nodes).toEqual([]);
expect(result.urls).toEqual([]);
expect(result.agentHints).toEqual([]);
});
});
+9 -13
View File
@@ -162,6 +162,7 @@ export const captureDom = (
completeness?.exclude("dom", exclusionReasonForUrl(documentUrl));
continue;
}
const baseUrl = indexedString(strings, document.baseURL) || documentUrl;
const documentNodes = recordValue(document.nodes);
if (documentNodes === undefined) continue;
const nodeTypes = numberArray(documentNodes.nodeType);
@@ -191,7 +192,8 @@ export const captureDom = (
const metadata = domMetadata({
strings,
attributes: attributeIndexes,
documentUrl,
// The BASE element itself resolves against the document fallback URL.
baseUrl: nodeName.toLowerCase() === "base" ? documentUrl : baseUrl,
nodeIndex,
nodeName,
allowedOrigins,
@@ -360,7 +362,7 @@ const numberArray = (value: unknown): readonly number[] =>
interface DomMetadataOptions {
readonly strings: readonly string[];
readonly attributes: readonly number[];
readonly documentUrl: string;
readonly baseUrl: string;
readonly nodeIndex: number;
readonly nodeName: string;
readonly allowedOrigins: ReadonlySet<string>;
@@ -372,14 +374,8 @@ const domMetadata = (
readonly urls: WebPageInspection["metadata"]["dom_urls"];
readonly agentHints: WebPageInspection["metadata"]["agent_hints"];
} => {
const {
strings,
attributes,
documentUrl,
nodeIndex,
nodeName,
allowedOrigins,
} = options;
const { strings, attributes, baseUrl, 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();
@@ -390,7 +386,7 @@ const domMetadata = (
for (const attribute of domUrlAttributes) {
const value = pairs.get(attribute);
if (value === undefined) continue;
const destination = domDestination(value, documentUrl, allowedOrigins);
const destination = domDestination(value, baseUrl, allowedOrigins);
urls.push({
node_index: nodeIndex,
attribute,
@@ -417,14 +413,14 @@ const domMetadata = (
const domDestination = (
value: string,
documentUrl: string,
baseUrl: string,
allowedOrigins: ReadonlySet<string>,
): {
readonly url: string | null;
readonly scope: "approved" | "outside_policy" | "unsupported";
} => {
try {
const parsed = new URL(value, documentUrl);
const parsed = new URL(value, baseUrl);
if (parsed.protocol !== "http:" && parsed.protocol !== "https:")
return { url: null, scope: "unsupported" };
if (!allowedOrigins.has(parsed.origin))
+22 -1
View File
@@ -51,7 +51,7 @@ export const safeResponseMetadata = (
coop: policyToken(headers.get("cross-origin-opener-policy")),
coep: policyToken(headers.get("cross-origin-embedder-policy")),
corp: policyToken(headers.get("cross-origin-resource-policy")),
referrer_policy: policyToken(headers.get("referrer-policy")),
referrer_policy: referrerPolicy(headers.get("referrer-policy")),
x_content_type_options: policyToken(
headers.get("x-content-type-options"),
),
@@ -316,6 +316,27 @@ const agentHint = (
const isAgentRel = (value: string): boolean =>
["mcp", "model-context", "ai-plugin", "service-desc"].includes(value);
const referrerPolicies = new Set([
"no-referrer",
"no-referrer-when-downgrade",
"same-origin",
"origin",
"strict-origin",
"origin-when-cross-origin",
"strict-origin-when-cross-origin",
"unsafe-url",
]);
const referrerPolicy = (value: string | undefined): string | null => {
let policy: string | null = null;
for (const raw of (value ?? "").split(",")) {
const token = raw.trim().toLowerCase();
if (!/^[a-z-]*$/u.test(token)) return null;
if (referrerPolicies.has(token)) policy = token;
}
return policy;
};
const policyToken = (value: string | undefined): string | null => {
const token = (value ?? "").trim().toLowerCase();
return /^[a-z][a-z0-9_.-]*$/u.test(token) ? token : null;