mirror of
https://github.com/morluto/rea.git
synced 2026-11-23 15:05:51 +00:00
fix(javascript): read the target of method-first request(method, url) calls
endpointArgument takes the first literal of a get/post/put/patch/delete/request
call as its endpoint candidate. Method-first clients (superagent's
request(method, url), needle.request, Angular HttpClient.request) put the HTTP
method there, so Api.request("get", "/api/v1/profile") reported the candidate
"get" in both analyze_javascript_application and analyze_web_bundle, and the
path was lost.
For a request callee whose first literal is a standard HTTP method (the
XHR_METHODS set that xhrOpenUrl uses, compared after toUpperCase), an exact
second string is now the candidate. A computed target keeps the method token,
so request("POST", target) is unchanged, as are RPC names, Octokit route
strings and URL-first calls.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fe8e571f78
commit
73bc6f48c7
4 files changed
+100
-1
No files matched your search
@@ -696,7 +696,15 @@ export const endpointArgument = (
|
||||
receiverFact === "extension-state")))
|
||||
)
|
||||
return undefined;
|
||||
return { kind: "candidate", value };
|
||||
// Method-first clients such as superagent, needle, and Angular
|
||||
// `HttpClient` call `request(method, url)`. When a standard method token
|
||||
// precedes an exact string, that string is the candidate target. With a
|
||||
// computed target, the token itself remains the candidate.
|
||||
const target =
|
||||
method === "request" && XHR_METHODS.has(value.toUpperCase())
|
||||
? stringValue(args[1])
|
||||
: undefined;
|
||||
return { kind: "candidate", value: target ?? value };
|
||||
}
|
||||
if (name === "sendBeacon" || name.endsWith(".sendBeacon"))
|
||||
return candidate(stringValue(args[0]));
|
||||
|
||||
@@ -1063,6 +1063,58 @@ describe("web bundle endpoint candidate classification", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("web bundle method-first request candidates", () => {
|
||||
it("reads the exact target after an HTTP method token in both analyzers", () => {
|
||||
const source = `
|
||||
Api.request("get", "/api/v1/profile");
|
||||
Api.request("POST", "/api/v1/items", item);
|
||||
client.request("Patch", \`/api/v1/items/1\`);
|
||||
http.request("DELETE", "https://api.example.test/items/1");
|
||||
request("options", "users");
|
||||
Api.request("delete", \`/api/v1/items/\${id}\`);
|
||||
http.request("POST", target);
|
||||
rpc.request("initialize", "/session");
|
||||
octokit.request("GET /repos/{owner}/{repo}");
|
||||
request("https://example.test/health", "GET");
|
||||
`;
|
||||
const expectedCandidates = [
|
||||
// An exact string after a standard method token, in any case.
|
||||
"/api/v1/profile",
|
||||
"/api/v1/items",
|
||||
"/api/v1/items/1",
|
||||
"https://api.example.test/items/1",
|
||||
"users",
|
||||
// A computed target leaves the method token as the candidate.
|
||||
"delete",
|
||||
"POST",
|
||||
// Any other first argument is still the candidate.
|
||||
"initialize",
|
||||
"GET /repos/{owner}/{repo}",
|
||||
"https://example.test/health",
|
||||
].sort();
|
||||
const result = analyzeWebBundleFixture(inspection(source));
|
||||
expect(result.observations.endpoints).toEqual([]);
|
||||
expect(
|
||||
result.inferences
|
||||
.filter(({ kind }) => kind === "endpoint_candidate")
|
||||
.map(({ value }) => value)
|
||||
.sort(),
|
||||
).toEqual(expectedCandidates);
|
||||
const staticEndpoints = analyzeJavaScriptStaticSource(source).endpoints;
|
||||
expect(
|
||||
staticEndpoints
|
||||
.filter(({ interpretation }) => interpretation === "candidate")
|
||||
.map(({ value }) => value)
|
||||
.sort(),
|
||||
).toEqual(expectedCandidates);
|
||||
expect(
|
||||
staticEndpoints.filter(
|
||||
({ interpretation }) => interpretation === undefined,
|
||||
),
|
||||
).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("web bundle configuration and navigation parity", () => {
|
||||
it("keeps configuration setting reads out of endpoints in both analyzers", () => {
|
||||
const source = `
|
||||
|
||||
Reference in new issue
Block a user