Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

fix(javascript): never read window or document open as XHR

Iwakurakaoru0822ae849a728118
diff --git a/src/domain/javascriptStaticAnalysisHelpers.ts b/src/domain/javascriptStaticAnalysisHelpers.ts
index 8400862a1..d13d2a7ac 100644
--- a/src/domain/javascriptStaticAnalysisHelpers.ts
+++ b/src/domain/javascriptStaticAnalysisHelpers.ts
@@ -383,6 +383,13 @@ const xhrOpenUrl = (
: undefined;
};
+/**
+ * Browsing-context and document `open` take a URL or type first and a target
+ * name second, never an XHR method and request URL.
+ */
+const WINDOW_OPEN_CALL =
+ /(?:^|\.)(?:window|self|globalThis|top|parent|opener|frames|document)\.open$/u;
+
/** Select the literal URL argument for recognized network callees. */
export const endpointArgument = (
name: string,
@@ -395,7 +402,8 @@ export const endpointArgument = (
): string | undefined => {
if (name === "fetch" || name.endsWith(".fetch") || name === "WebSocket")
return stringValue(args[0]);
- if (name.endsWith(".open")) return xhrOpenUrl(args[0], args[1]);
+ if (name.endsWith(".open") && !WINDOW_OPEN_CALL.test(name))
+ return xhrOpenUrl(args[0], args[1]);
if (
["get", "post", "put", "patch", "delete", "request"].some(
(method) => name === method || name.endsWith(`.${method}`),
diff --git a/src/domain/webBundleAnalyzer.test.ts b/src/domain/webBundleAnalyzer.test.ts
index 77c5df458..d4f5440be 100644
--- a/src/domain/webBundleAnalyzer.test.ts
+++ b/src/domain/webBundleAnalyzer.test.ts
@@ -185,6 +185,9 @@ describe("web bundle static-analysis parity", () => {
xhr.open(method, "/dynamic-method");
fs.open(path, "r", done);
window.open(url, "_blank");
+ window.open(url, "/preview");
+ globalThis.open(url, "./frame");
+ document.open("text/html", "/replace");
`),
);
expect(