Repository navigation
Conversation
…artial endpoints analyze-javascript-application reported no endpoint observation at all when a fetch, WebSocket, EventSource or sendBeacon request target was not an exact string literal (morluto#3451), so an application whose requests were all template-literal, variable-base or URL-object shaped read as having no first-party backend. Resolve unambiguous network call targets through the existing constant lattice: object-property and alias bindings that evaluate to a string resolve completely, and a once-assigned new URL("literal") binding resolves when forwarded directly or through .toString(). Anything else is retained as a partial endpoint whose value is the exact unresolved source expression, following the specifier/expression pattern already used for references. HTTP-method-named calls (get, post, request, ...) are excluded: their first argument is often a collection or setting key rather than a request target. The semantic graph already reports these call sites as partial requests; aligning its requestEndpoint reader is left to a follow-up.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
[Medium impact] Changes how network endpoints are classified and reported. The PR is not ready to merge because it can report stale backends, omit browser requests, and retain URL passwords. Findings
Fix with agent prompt### Issue 1
src/domain/javascript/javascriptStaticAnalysisCalls.ts:521-523
`resolvedRequestTarget` reports stale config values as complete endpoints. For `const cfg = { url: 'https://old.example' }; cfg.url = 'https://new.example'; fetch(cfg.url);`, the evaluator reads the initializer and returns `https://old.example`. Users see the old backend as known, even though the application requests a different one.
The static pass does not collect property changes, and this early return skips the new write check. Populate the evaluator's mutation facts before resolving object properties, or keep these targets partial.
### Issue 2
src/domain/javascript/javascriptStaticAnalysisCalls.ts:576-586
`binding.mutable` covers changes to the binding, not changes to the URL object. For `const u = new URL('https://old.example/socket'); u.hostname = 'new.example'; fetch(u);`, this helper still reports the old URL as complete. Users see the wrong backend without warning.
Check the existing `memberWrites` and `escapedPaths` before reading the raw initializer. Keep the target partial when the object may have changed.
### Issue 3
src/domain/javascript/javascriptStaticAnalysisCalls.ts:undefined-496
For ``fetch(`https://alice:[email protected]/items/${id}`)``, the new partial value retains the backticks and credentials. The backticks make URL parsing fail, so `sanitizeEndpointCandidate` returns the password unchanged. Sharing or retaining endpoint results can now expose credentials that an equivalent literal URL would have removed.
Remove URL userinfo inside retained expressions before storing them, while preserving the unresolved parts.
**How this was verified:** The retained template fails URL parsing, the sanitizer returns unparseable values unchanged, and the graph copies that value into its endpoint properties.
### Issue 4
src/domain/javascript/javascriptStaticAnalysisCalls.ts:465-467
Removing all member `.fetch` calls also drops real browser requests such as `window.fetch(endpointUrl)`, `globalThis.fetch(endpointUrl)`, and `self.fetch(endpointUrl)`. `endpointArgument` accepts only literal targets, so these calls now produce no endpoint. Applications using these calls can still appear to have no backend.
Keep known global receivers eligible while excluding local methods such as `cache.fetch`.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
### Issue 5
src/domain/javascript/javascriptStaticAnalysisCalls.ts:499-500
The fallback treats locally defined functions as network APIs based only on their names. For `function fetch(key) { return records[key]; } fetch(key);`, it now adds an observed network endpoint even though the function only reads local data. Users must sort these false backends out of the results; marking the target partial does not explain that the call itself may not make a request.
Check the callee's binding before treating it as a known browser API. Keep unproven receivers as candidates rather than observed requests.
### Issue 6
src/domain/javascript/javascriptStaticAnalysisCalls.ts:474-475
`stripExpressionCredentials` can delete part of an interpolation rather than credentials. Given ``fetch(`https://${hosts['a@b']}/items`)``, the regex consumes `https://${hosts['a@` and leaves the broken text `` `https://b']}/items` ``. Users can no longer recover the original dynamic host from the reported value.
Read the template structure before removing userinfo so an `@` inside JavaScript does not damage the retained expression.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.SummaryThe PR keeps unresolved request targets visible as partial endpoints and resolves some constant targets.
The full PR diff was used because the current and previous heads have different merge bases with the supplied target commit. Whether another PR supersedes this one could not be checked because GitHub access was unavailable. No runtime verification was performed. Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Request call] --> B{Literal target?}
B -->|Yes| C[Complete endpoint]
B -->|No| D{Eligible API name?}
D -->|No| E[No new endpoint]
D -->|Yes| F{Constant or URL binding resolves?}
F -->|Yes| C
F -->|No| G[Retained expression with partial resolution]
C --> H[Worker handoff]
G --> H
H --> I[Graph endpoint with separate partial identity]
Reviews (3) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile |
| const binding = resolveSemanticBindingState(bindings, target, target.name); | ||
| if (binding === undefined || binding.mutable) return undefined; | ||
| const [initializer, ...rest] = binding.initializers; | ||
| if (initializer === undefined || rest.length > 0) return undefined; |
There was a problem hiding this comment.
binding.mutable covers changes to the binding, not changes to the URL object. For const u = new URL('https://old.example/socket'); u.hostname = 'new.example'; fetch(u);, this helper still reports the old URL as complete. Users see the wrong backend without warning.
Check the existing memberWrites and escapedPaths before reading the raw initializer. Keep the target partial when the object may have changed.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/javascript/javascriptStaticAnalysisCalls.ts
Line: 535-538
Comment:
**Changed URLs look unchanged**
`binding.mutable` covers changes to the binding, not changes to the URL object. For `const u = new URL('https://old.example/socket'); u.hostname = 'new.example'; fetch(u);`, this helper still reports the old URL as complete. Users see the wrong backend without warning.
Check the existing `memberWrites` and `escapedPaths` before reading the raw initializer. Keep the target partial when the object may have changed.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| ); | ||
| return { | ||
| kind: "endpoint", | ||
| value: resolved ?? sourceSlice(context.source, argument), |
There was a problem hiding this comment.
For fetch(`https://alice:[email protected]/items/${id}`), the new partial value retains the backticks and credentials. The backticks make URL parsing fail, so sanitizeEndpointCandidate returns the password unchanged. Sharing or retaining endpoint results can now expose credentials that an equivalent literal URL would have removed.
Remove URL userinfo inside retained expressions before storing them, while preserving the unresolved parts.
How this was verified: The retained template fails URL parsing, the sanitizer returns unparseable values unchanged, and the graph copies that value into its endpoint properties.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/javascript/javascriptStaticAnalysisCalls.ts
Line: 496
Comment:
**URL passwords reach results**
For ``fetch(`https://alice:[email protected]/items/${id}`)``, the new partial value retains the backticks and credentials. The backticks make URL parsing fail, so `sanitizeEndpointCandidate` returns the password unchanged. Sharing or retaining endpoint results can now expose credentials that an equivalent literal URL would have removed.
Remove URL userinfo inside retained expressions before storing them, while preserving the unresolved parts.
**How this was verified:** The retained template fails URL parsing, the sanitizer returns unparseable values unchanged, and the graph copies that value into its endpoint properties.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Resolve URL objects against a literal base with the platform URL constructor, keep targets partial when the base is not literal or the object's members are written anywhere in the program (the static pass does not collect member mutations), strip URL userinfo from retained expression text, keep partial and complete endpoint identities disjoint when their text matches, and exclude member .fetch methods from the partial fallback.
|
All five findings addressed in 8b97278.
Validation: 11 domain partial-endpoint tests (6 new), the identity boundary test, the full javascript domain + boundary + acceptance surface (74 files, 1674 tests) all pass; |
| const isUnambiguousNetworkCall = (name: string): boolean => | ||
| name === "fetch" || | ||
| name === "WebSocket" || |
There was a problem hiding this comment.
Browser request targets disappear
Removing all member .fetch calls also drops real browser requests such as window.fetch(endpointUrl), globalThis.fetch(endpointUrl), and self.fetch(endpointUrl). endpointArgument accepts only literal targets, so these calls now produce no endpoint. Applications using these calls can still appear to have no backend.
Keep known global receivers eligible while excluding local methods such as cache.fetch.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/javascript/javascriptStaticAnalysisCalls.ts
Line: 459-461
Comment:
**Browser request targets disappear**
Removing all member `.fetch` calls also drops real browser requests such as `window.fetch(endpointUrl)`, `globalThis.fetch(endpointUrl)`, and `self.fetch(endpointUrl)`. `endpointArgument` accepts only literal targets, so these calls now produce no endpoint. Applications using these calls can still appear to have no backend.
Keep known global receivers eligible while excluding local methods such as `cache.fetch`.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| const stripExpressionCredentials = (expression: string): string => | ||
| expression.replace(/\b([a-z][a-z0-9+.-]*:\/\/)[^/@\s]+@/giu, "$1"); |
There was a problem hiding this comment.
Endpoint expressions lose source text
stripExpressionCredentials can delete part of an interpolation rather than credentials. Given fetch(`https://${hosts['a@b']}/items`), the regex consumes https://${hosts['a@ and leaves the broken text `https://b']}/items`. Users can no longer recover the original dynamic host from the reported value.
Read the template structure before removing userinfo so an @ inside JavaScript does not damage the retained expression.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/javascript/javascriptStaticAnalysisCalls.ts
Line: 468-469
Comment:
**Endpoint expressions lose source text**
`stripExpressionCredentials` can delete part of an interpolation rather than credentials. Given ``fetch(`https://${hosts['a@b']}/items`)``, the regex consumes `https://${hosts['a@` and leaves the broken text `` `https://b']}/items` ``. Users can no longer recover the original dynamic host from the reported value.
Read the template structure before removing userinfo so an `@` inside JavaScript does not damage the retained expression.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.# Conflicts: # src/domain/javascript/javascriptStaticAnalysisCalls.ts
|
Merged latest |
| const evaluated = evaluateSemanticExpression(node, bindings); | ||
| if (evaluated.status === "literal" && typeof evaluated.value === "string") | ||
| return evaluated.value; |
There was a problem hiding this comment.
Changed config reports old backend
resolvedRequestTarget reports stale config values as complete endpoints. For const cfg = { url: 'https://old.example' }; cfg.url = 'https://new.example'; fetch(cfg.url);, the evaluator reads the initializer and returns https://old.example. Users see the old backend as known, even though the application requests a different one.
The static pass does not collect property changes, and this early return skips the new write check. Populate the evaluator's mutation facts before resolving object properties, or keep these targets partial.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/javascript/javascriptStaticAnalysisCalls.ts
Line: 521-523
Comment:
**Changed config reports old backend**
`resolvedRequestTarget` reports stale config values as complete endpoints. For `const cfg = { url: 'https://old.example' }; cfg.url = 'https://new.example'; fetch(cfg.url);`, the evaluator reads the initializer and returns `https://old.example`. Users see the old backend as known, even though the application requests a different one.
The static pass does not collect property changes, and this early return skips the new write check. Populate the evaluator's mutation facts before resolving object properties, or keep these targets partial.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| if (receiverFact === "window" || !isUnambiguousNetworkCall(name)) | ||
| return undefined; |
There was a problem hiding this comment.
The fallback treats locally defined functions as network APIs based only on their names. For function fetch(key) { return records[key]; } fetch(key);, it now adds an observed network endpoint even though the function only reads local data. Users must sort these false backends out of the results; marking the target partial does not explain that the call itself may not make a request.
Check the callee's binding before treating it as a known browser API. Keep unproven receivers as candidates rather than observed requests.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/javascript/javascriptStaticAnalysisCalls.ts
Line: 499-500
Comment:
**Local lookups become backends**
The fallback treats locally defined functions as network APIs based only on their names. For `function fetch(key) { return records[key]; } fetch(key);`, it now adds an observed network endpoint even though the function only reads local data. Users must sort these false backends out of the results; marking the target partial does not explain that the call itself may not make a request.
Check the callee's binding before treating it as a known browser API. Keep unproven receivers as candidates rather than observed requests.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.|
TL;DR: Fixed: a network call with a target that is not plain text now keeps a partial endpoint. On current main, 14 of 25 test cases fail. With the PR merged in, all 25 pass on Node 22, 24 and 26. I also ran 78 older JavaScript analysis test files, and all passed. Thanks, Hemang Varshney, for the careful fix and the many small test cases. This checks the fix for #3451. ResultsBefore: main 62bf098 (#4169) plus only this PR's test files. After: main plus this PR's files, merged with The six test files are the five the PR adds or changes, plus
Before the fix, 9 cases fail in the new The 78 older files are every Not run
No test made a network call. Words such as Commandsexport PATH=~/.local/opt/node24/bin:$PATH
npm ci
npm run test:focused -- src/domain/javascript/javascriptStaticAnalysis.partialEndpoints.test.ts src/domain/javascript/javascriptStaticAnalysis.event_source.test.ts src/domain/javascript/javascriptStaticAnalysis.send_beacon.test.ts src/javascript/analysis/JavaScriptAnalysisWorkerSchemas.test.ts tests/boundary/filesystem/javascript-applications/javascriptArtifactGraphEndpoints.test.ts src/domain/javascript/childProcessOptionsRegression.test.ts
npm run typecheckThe same test command ran on Node 22.23.1 and 26.11.1 by putting that Node first on PATH. The 78-file run used the same command with every Test setup🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊 |
|
Thanks for the cross-version verification — Node 22/24/26 all 25/25, 2,007 older JavaScript analysis tests green, typecheck clean. The 14-fail/11-pass pre-change split you measured matches the intent: the 11 that pass before are controls (local methods that must not count as network targets), and the 14 failures are exactly the partial-endpoint, EventSource, send-beacon, worker-schema and artifact-graph assertions this PR fixes. Noted on your "Not run" list: no full suite, lint or other platforms on your box — real CI on the PR head has 17 checks passing with 15 path-gated skips (the full 5-shard suite ran when the PR first opened; the skips are the Classify-changes job limiting to touched paths on later commits). |
Resolve stable lexical and URL targets using shared effects, and preserve unresolved request expressions as partial facts. Carry their uncertainty through workers, artifact graphs, and the CLI. Scope partial endpoint identity to the source site. Refs: #3451, #3534 Co-authored-by: Hemang Varshney <[email protected]>
|
Conflict check from the CI/conflict track. I did not push anything.
|
|
Closing as superseded, per @kaoru0822-kitauji's conflict check: main carries this change landed as Thanks to kaoru for the merge attempt and the conflict audit, and to CassieFox23 for the cross-version verification (Node 22/24/26, 25/25 with the change, 14/25 without it). |
Fixes #3451
Summary
analyze-javascript-applicationreports anetworkendpoint observation only when a recognized request call's target is an exact string literal. Any other construction (template literal, variable base, URL object, config property) produced no endpoint observation at all, so an application whose requests are all dynamically shaped read as having no first-party backend. Non-literal request targets of unambiguous network APIs are now retained as partial endpoints carrying the unresolved source expression, and targets that resolve through the existing constant lattice (config properties,new URL(...)bindings) resolve to complete endpoints.Problem and expected behavior
Smallest trigger (from the issue):
Observed before: no endpoint observation; the application graph contained no
networkendpoint node for the call site. Violated invariant: a recognized request call site must remain visible even when its target is not statically exact.Expected: the call site produces a
networkendpoint observation with the unresolved part explicit. Constant shapes resolve fully:Change and scope
One fallback at the single static-analysis choke point
inspectEndpointCall(src/domain/javascript/javascriptStaticAnalysisCalls.ts), reusing existing machinery:evaluateSemanticExpression— the bounded constant lattice the semantic analysis already uses. Targets that evaluate to string literals resolve to complete endpoints.new URL(...), forwarded directly or through zero-argument.toString(), following thenew URLunwrapping precedent inworkerUrlSpecifierin the same file. A single literal argument matches the literal path's exact text; a two-argumentnew URL(input, base)with literal arguments resolves through the platform URL constructor; a non-literal base, a member write anywhere in the program (u.hostname = ...; the static pass does not collect member mutations, so writes are detected syntactically once per parse), or any other irregularity keeps the target partial rather than reporting a possibly wrong complete URL.sourceSlice— the same specifier/expression retention pattern asJavaScriptStaticReferenceandElectronStaticValue. URL userinfo is stripped from retained expression text before storage; interpolations stay untouched.Applied to unambiguous network APIs: bare
fetch,WebSocket,EventSource, memberEventSource,sendBeacon, membersendBeacon. Member.fetchis excluded from the partial fallback — local cache and service-worker style methods share the name without making a request, and the literal path's pre-existing behavior is unchanged. HTTP-method-named calls (get,post,request, ...) are excluded on purpose: their first argument is frequently a collection or setting key (map.get(key), configuration reads), and emitting partial endpoints there would flood results with false endpoints.Partial endpoints carry a disjoint
"partial"segment in their artifact-local identity, so a partial expression and a complete literal with the same text (fetch(target)vsfetch("target")) never collapse into one node; complete endpoint identities are unchanged.Intentionally not included:
requestEndpointreader (javascriptSemanticDataEffects.ts) remains literal-only. That surface already reports these call sites as request operations withresolution: "partial"and an explicit unknown endpoint; carrying the partial text there touches the semantic IR with a wider blast radius and belongs in a follow-up.analyze_web_bundlehas a separate endpoint-candidate path and is unchanged.Contribution scope: ordinary bug fix within existing static-analysis boundaries. Maintainer scope decision: not applicable.
Contract and boundary impact
javascriptStaticAnalysisCalls.ts), consumed by the application-graph projection and the worker schema.ast-static-analysis/observed/exactevidence for the call site itself, with an added limitation that the value is an unresolved source expression. Node identity is unchanged: partial values are source expressions and complete values are resolved URLs, so they cannot collide.Expected effects:
Evidence and regression coverage
src/domain/javascript/javascriptStaticAnalysis.partialEndpoints.test.ts(11 tests) — all four shapes from the issue (interpolated template, variable base, URL object direct and through.toString(), config property), two-argument URL bases with literal and non-literal bases, mutated URL objects, credential stripping in retained expressions, member.fetchexclusion, and a negative for collection reads.javascriptStaticAnalysis.event_source.test.tsandjavascriptStaticAnalysis.send_beacon.test.ts— the two tests that pinned "dynamic URL unreported" now assert the partial observation; they pinned the reported bug.javascriptArtifactGraphEndpoints.test.ts— partial node/edge properties with evidence and limitation throughbuildJavaScriptArtifactGraph, and distinct node identities forfetch(target)vsfetch("target").JavaScriptAnalysisWorkerSchemas.test.ts—resolution: "partial"survives the strictObject worker handoff.origin/mainat3b79af2), the partial cases produce no endpoint observation at all (the dynamic EventSource and beacon tests asserted[]), which is exactly the reported omission; the complete-resolution shapes (config property, URL object) also produced nothing on base.analyze_javascript_applicationgraph output gains endpoint nodes withproperties.resolution: "partial"and the limitation text; no CLI flag or schema change.For evidence-bearing changes:
Validation performed
npx vitest run src/domain/javascript/ src/javascript/analysis/JavaScriptAnalysisWorkerSchemas.test.ts tests/boundary/filesystem/javascript-applications/javascriptArtifactGraphEndpoints.test.ts tests/boundary/filesystem/javascript-applications/javascriptApplicationEmptyLiterals.test.ts tests/acceptance/applications/javascriptEndpointCandidateCli.test.ts tests/acceptance/applications/javascriptEndpointPayload.test.ts— 74 files, 1674 tests passed.npm run check:fast— typecheck + lint successful.npx tsc --noEmit— clean.npx oxfmt --checkon changed files — clean.npm run verify:test-discovery— 1276 test files discovered exactly once.Compatibility, safety, and release
sanitizeEndpointCandidatecontinues to pass unparseable expressions through verbatim.Author readiness
Human owner: @hemv-857
Before merge
type(scope): outcome.