diff --git a/src/domain/javascript/javascriptStaticAnalysisHelpers.ts b/src/domain/javascript/javascriptStaticAnalysisHelpers.ts index b25b0f926..382feff61 100644 --- a/src/domain/javascript/javascriptStaticAnalysisHelpers.ts +++ b/src/domain/javascript/javascriptStaticAnalysisHelpers.ts @@ -410,7 +410,7 @@ const BROWSING_CONTEXT_KEYWORDS = new Set([ * `window.open(url, "_blank")` share the callee name. A literal method must * be an HTTP method; with a computed method, the second literal is a URL * unless it is provably an fs flag or a browsing-context keyword, or the - * receiver is spelled as a browsing context. XHR normalizes the standard + * receiver is spelled as a browsing context or storage. XHR normalizes the standard * methods' case; extension methods such as WebDAV `PROPFIND` are * conventionally uppercase tokens. */ @@ -422,13 +422,18 @@ const xhrOpenUrl = ( const url = stringValue(urlNode); if (url === undefined) return undefined; const method = stringValue(methodNode); + // IndexedDB and Cache Storage `open` take a name and a version, so a + // receiver spelled as storage needs a standard HTTP method literal. + const storage = storageKind(name) !== undefined; if (method === undefined) - return WINDOW_OPEN_CALL.test(name) || + return storage || + WINDOW_OPEN_CALL.test(name) || FS_OPEN_FLAGS.has(url) || BROWSING_CONTEXT_KEYWORDS.has(url.toLowerCase()) ? undefined : url; - return XHR_METHODS.has(method.toUpperCase()) || /^[A-Z][A-Z-]*$/u.test(method) + return XHR_METHODS.has(method.toUpperCase()) || + (!storage && /^[A-Z][A-Z-]*$/u.test(method)) ? url : undefined; }; diff --git a/src/domain/webBundleAnalyzer.test.ts b/src/domain/webBundleAnalyzer.test.ts index 86e6bec90..a217d45d9 100644 --- a/src/domain/webBundleAnalyzer.test.ts +++ b/src/domain/webBundleAnalyzer.test.ts @@ -1,6 +1,7 @@ import { describe, expect, it } from "vitest"; import { webPageInspectionSchema } from "./browserObservation.js"; +import { analyzeJavaScriptStaticSource } from "./javascript/javascriptStaticAnalysis.js"; import { analyzeCapturedWebBundle } from "./webBundleAnalyzer.js"; import { webBundleAnalysisSchema } from "./webBundleAnalysis.js"; import { createWebTextArtifact } from "./webContentArtifact.js"; @@ -208,6 +209,30 @@ describe("web bundle static-analysis parity", () => { ]); }); + it("reads storage open versions as storage rather than endpoints in both analyzers", () => { + const source = ` + indexedDB.open(databaseName, "2"); + window.indexedDB.open(databaseName, "/v3"); + indexedDB.open("APP", "4"); + indexedDB.open("GET", "/storage-named-xhr"); + `; + expect( + analyzeCapturedWebBundle(inspection(source)).observations.endpoints.map( + ({ value }) => value, + ), + ).toEqual(["/storage-named-xhr"]); + const analysis = analyzeJavaScriptStaticSource(source); + expect(analysis.endpoints.map(({ value }) => value)).toEqual([ + "/storage-named-xhr", + ]); + expect(analysis.storage.map(({ kind }) => kind)).toEqual([ + "indexed-db", + "indexed-db", + "indexed-db", + "indexed-db", + ]); + }); + it("keeps HTTP-method-named reads of provable keyed collections out of endpoints", () => { const result = analyzeCapturedWebBundle( inspection(`