Repository navigation
fix(javascript): read the target of method-first request(method, url) calls - #9509
Conversation
… 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 <[email protected]>
[Medium impact] The PR appears safe to merge; no actionable defect was found in the changed behavior. SummaryUpdates the shared
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["request(first, second)"] --> B{"First is a standard method<br/>and second is an exact string?"}
B -->|Yes| C["Select second"]
B -->|No| D["Keep first"]
C --> E["Shared endpoint candidate"]
D --> E
E --> F["Static application analyzer"]
E --> G["Web bundle analyzer"]
F --> H["Remove URL credentials; retain candidate status"]
G --> H
Reviews (4) · Last reviewed commit: "fix(javascript): read the target of meth..." · Reviewed by Greptile |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Reopening to get CI against current main: the earlier runs were created when this branch was pushed, so they tested an older main. The failures in them ( |
gensokyo-dev
left a comment
There was a problem hiding this comment.
Verified: method-first request(method, url) calls read the target from the second argument only for a standard method token. The web bundle and renderer endpoint suites pass on current main (96), and fresh CI is green. Thanks.
Summary
analyze_javascript_applicationandanalyze_web_bundletake the firstliteral argument of a
request(...)call as its network endpoint candidate.Method-first clients put the HTTP method there: superagent's
request(method, url), needle'sneedle.request(method, url, data)andAngular's
HttpClient.request(method, url, options). On this client, bothanalyzers report the candidates
get,POSTanddelete, and neither/api/v1/profilenor/api/v1/itemsis reported as an endpoint or endpointcandidate:
With this change, when a
requestcall's first argument is a standard HTTPmethod token and its second argument is an exact string, the second argument is
the candidate. Every other call keeps its current result, including a method
token followed by a computed target (
removeabove still reportsdelete).No issue is linked: the trigger is self-contained, and the failure and the fix
are both shown below. Related: #2806 (closed); its fix made the arguments of
unverified receivers low-confidence candidates. #3539 (open) asks for path
literals passed to project-specific request wrappers, a different call shape
that this PR does not address.
Problem and expected behavior
Smallest trigger:
analyzeJavaScriptStaticSource('Api.request("get", "/api/v1/profile");')returns one endpoint,
{ value: "get", mechanism: "call:Api.request", interpretation: "candidate" }, andanalyze_web_bundlerecords the same valueas an
endpoint_candidateinference.Violated invariant: an HTTP method token is not a request target.
xhrOpenUrlalready applies this to
open(method, url): a standard method (XHR_METHODS,compared after
toUpperCase()) makes the second argument the URL. Therequestbranch ofendpointArgumenthad no such rule, so the method tokenbecame the endpoint value.
Expected:
Api.request("get", "/api/v1/profile")yields the candidate/api/v1/profile. It remains a low-confidence candidate, because the receiveris still unproven.
Change and scope
endpointArgumentinsrc/domain/javascript/javascriptStaticAnalysisHelpers.tsis the one owner both analyzers use for method-named calls. For a
requestcallee whose first literal is in
XHR_METHODS(compared asxhrOpenUrlcompares it), an exact second string is now the candidate value. "Exact"
means
stringValue: a string literal or a template without substitutions.existing expectations for
request("POST", target)stay as they are(
JavaScriptAnalysisWorkerSchemas.test.tsand two cases inwebBundleAnalyzer.test.ts).value: an RPC name (
rpc.request("initialize", "/session")), an Octokitroute string (
"GET /repos/{owner}/{repo}") or a URL-first call(
request("https://example.test/health", "GET")).superagent), extension methods such asPROPFIND, configuration-objectcalls such as
axios.request({ url }), and wrapper parameters ([Feature] analyze_web_bundle: surface path- and URL-shaped literals passed to project request wrappers #3539).docs/guides/javascript/javascript-artifact-reconstruction.md, after theoverloaded
.openrule.Open question for maintainers: should a method token with a computed target be
dropped instead of kept? Angular's own
HttpClientmethods callthis.request('GET', url, options)with a computedurl, and #2806 listedsuch method names (
call:request) among its Juice Shop results. Dropping themwould remove that noise, but it would change the three existing expectations
above, so this PR keeps the current behavior. The alternative is a small change
to the same branch plus those three expectations.
Follow the contribution scope.
Unresolved scope, authority, side effects, or required verification block
integration. Link the required maintainer scope decision for new providers or
capabilities involving target execution, injection, mutation, or protection
recovery; ordinary fixes within existing boundaries may state "not applicable".
Draft PRs may leave the scope decision pending and the readiness and merge checklists
unchecked. Maintainers can help resolve open questions.
Scope decision: not applicable; this is a fix within the existing static
analysis boundary.
Contract and boundary impact
endpointArgument, whichinterprets the literal arguments of method-named calls. Its consumers are
inspectLiteralEndpointCallinjavascriptStaticAnalysisCalls.ts(staticendpoint facts and the application graph's
endpointnodes) andinspectCallin
webBundleAnalyzerInspection.ts(endpoint_candidateinferences). Thesemantic request operations in
javascriptSemanticDataEffects.tsreadrequestonly on proven Nodehttp/httpsbindings, which take the URLfirst, and are unchanged. No superseded path remains.
shape, the
valueof an existing endpoint candidate changes from the methodtoken to the target string.
keep
interpretation: "candidate",inferredstate,lowconfidence, theirmechanism and their source location. Both analyzers still pass the value
through
sanitizeEndpointCandidate.docs/public/product-catalog.json), package, or installation impact: none.Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.
Evidence and regression coverage
Evidence is executed unless marked source-derived.
Tests added or updated:
src/domain/webBundleAnalyzer.test.ts, newweb bundle method-first request candidatescase: one source analyzed byboth
analyzeWebBundleFixtureandanalyzeJavaScriptStaticSource, whichmust report the same candidate set and no endpoint observations. Rows:
lowercase, uppercase and mixed-case method tokens, a template without
substitutions, a bare
request, and absolute and relative targets.Controls: two computed targets that keep the token, an RPC name followed by
a path, an Octokit route string and a URL-first call.
tests/boundary/cli/javascriptRendererEndpoints.test.ts: acliTest.for(["CLI", "stdio MCP"])case analyzes a variant of thesummary's
Apiclient through the publicanalyze-javascript-applicationcommand and
analyze_javascript_applicationMCP tool. Itscall:Api.requestendpoint observations must be/api/v1/items,/api/v1/profileanddelete, each withinterpretation: "candidate",inferredstate andlowconfidence.Base reproduction or other evidence: with the new tests and the base source
(
88cf49803,origin/mainwhen this branch was cut), all three new casesfail. The module case stops at its web-bundle assertion; the CLI and stdio
MCP cases go through the static analyzer:
User-visible CLI/MCP output (if applicable): the fixture below, analyzed
with
rea analyze-javascript-application <dir> --format json. Rows are thegraph's
endpointobservations, selected with the jq filter below and sortedby line. "Before" is a build of
88cf49803, "after" a build of this branch,each made with
npm run build:cached.The published
rea-agents6.8.0 CLI reports the same threecall:Api.requestrows as88cf49803(get,POST,delete).analyze_web_bundle's script analysis, run on the sameapi.jsthroughanalyzeWebBundleFixture, gives thecall:Api.requestcandidatesget,POST,deleteat base and/api/v1/profile,/api/v1/items,deleteonthis branch; its two other candidates (
https://example.test/health,initialize) are the same on both.Fixture and jq filter
package.json:{ "name": "fx-endpoints", "version": "1.0.0", "main": "api.js" }Remaining proof gaps:
analyze_web_bundleran through its module fixture(
analyzeWebBundleFixture), not a live browser capture.request(method, url)signatures are source-derived, from each project'sdocumentation and source.
the open question above).
For boundary fixes, identify the applicable boundary regressions
and lifecycle regressions
covered by the evidence above, and explain relevant gaps.
Boundary regressions covered: raw identity and normalization (lowercase,
uppercase and mixed-case method tokens select the same rule, and the target
keeps its source spelling) and missing, empty, and unknown values (a computed
target leaves the existing candidate rather than dropping the row). No resource
ownership or lifecycle stage changes, so no lifecycle regression applies.
For evidence-bearing changes:
Validation performed
Run on macOS arm64 with Node 24.22.2 (
.nvmrcpins 24.22.1) and dependenciesinstalled from the unchanged lockfile. "Base" means
javascriptStaticAnalysisHelpers.tsat88cf49803with this branch's tests.npx tsxprobe callinganalyzeJavaScriptStaticSource('Api.request("get", "/api/v1/profile");')— base:
[{"kind":"network","value":"get","mechanism":"call:Api.request","interpretation":"candidate"}];this branch: the same row with
"value":"/api/v1/profile".npx tsxprobe runninganalyzeWebBundleFixtureon the fixture'sapi.js— base and branch candidates as listed above.
npx vitest run src/domain/webBundleAnalyzer.test.ts -t "method-first request candidates"— base:
Tests 1 failed | 78 skipped(output above).npx vitest runon 19 source suites that exercise endpoint extraction:webBundleAnalyzer,webBundleAnalyzerAst,JavaScriptAnalysisWorkerSchemas,webBundleView,staticObservedEndpoints,javascriptRpcEndpoints,javascriptApplicationEndpointCorrespondence,javascriptReturnedReferenceCoverage,javascriptSemanticProvenanceAssignments,javascriptRouteScan,javascriptStaticAnalysisCallableReceivers,javascriptStaticAnalysisCalleeBoundary, and thejavascriptStaticAnalysis.suites
mapEndpoints,mapOpaqueEffects,partialEndpoints,event_source,send_beacon,routePropertiesandsqliteStorage— thisbranch:
Test Files 19 passed (19),Tests 794 passed (794).npm run test:focused -- tests/boundary/cli/javascriptRendererEndpoints.test.ts— this branch:
Tests 5 passed (5). Base, rebuilt:Tests 2 failed | 3 passed (5);the two failures are the new CLI and stdio MCP cases.
npm run test:focused --onjavascriptRendererEndpointstogether withtests/boundary/mcp/javascriptEndpointCandidate.test.ts,tests/acceptance/applications/javascriptEndpointCandidateCli.test.ts,tests/boundary/filesystem/javascript-applications/javascriptArtifactGraphEndpoints.test.tsand
tests/boundary/mcp/webBundleViewsMcp.test.ts— 13 of 14 passed. Theacceptance case "reports a candidate endpoint through the worker boundary in
the public CLI" hit its 20 s test timeout while the five files ran in
parallel at background priority. Run alone, that file passed
(
Tests 2 passed (2), the case in 5.6 s).analyze-javascript-applicationon the fixture with the base build, thisbranch's build and the published
rea-agents6.8.0 CLI — output above.npm run check:fast(typecheck and lint) — passed. Its first run failed withmax-lines-per-function(157 > 150) on thedescribethat first held the newmodule case; the case moved to its own
describe, and the rerun passed with0 errors.
oxlintonjavascriptStaticAnalysisHelpers.tsreports the samethree warnings at base and on this branch; the existing
complexitywarningon
endpointArgumentrises from 23 to 26.npx oxfmt --checkon the four touched files — formatted.npm run verify:test-discovery— "Discovered all 3196 test files exactly once."npm run docs:check— passed, includingcheck-doc-factsandreadmeConsistency(9 passed).npm run build:cached— passed (used by the CLI runs and boundary tests).lint-staged(oxlint --fix,oxfmt) passed with nochanges; pre-push
check:fastpassed (Turbo cache of the run above).npm run check(repository-wideformat:check,knip,metadata:check, architecture guards,knip:productionand typed lint),npm run check:pr, the full test suite, andanalyze_web_bundleagainst alive browser.
Compatibility, safety, and release
request(<method>, "<string>")calls, the candidate value changes from the method token to the string; a
consumer that matched those token values now sees the target instead.
JavaScript analysis only.
analyze_web_bundlewas covered through its modulefixture, not a live browser.
executed. The new candidate value is a source literal, and both analyzers
pass it through
sanitizeEndpointCandidate, as they do for a first-argumentURL.
Author readiness
Human owner: @pedrocormann
Before merge
type(scope): outcome.🤖 Generated with Claude Code