Skip to content

fix(javascript): decide a socket host member by its string type - #9380

Closed
XiaoBinGan wants to merge 4 commits into
morluto:mainfrom
XiaoBinGan:fix/socket-host-literal
Closed

XiaoBinGan wants to merge 4 commits into
morluto:mainfrom
XiaoBinGan:fix/socket-host-literal

Conversation

@XiaoBinGan

@XiaoBinGan XiaoBinGan commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #10002.

net/tls read options.host and throw ERR_INVALID_ARG_TYPE from the call itself when the member is truthy and not a string, so no socket exists afterwards. The acquisition filter decided only the port, so a call that throws produced a complete built-in acquisition plus its linked release.

Measured on Node 24.22.1

host outcome
undefined, null, "", 0, -0, false, 0n, NaN, void 0, !1 socket created
"localhost", "0.0.0.0", `x`, String("127.0.0.1"), a resolved helper socket created
1, 1.5, true, 1n, {}, [], /x/, Symbol(), () => {}, Infinity, !0, -1, +1, !!1 THREW ERR_INVALID_ARG_TYPE
new String("x"), new Number(1) THREW ERR_INVALID_ARG_TYPE

Four rules follow, and the first version of this check got each of them wrong:

  • The judgement is a type check, not a truthiness check. Every falsy value falls through to the default, including NaN and 0n; a boxed string is an object, so new String("x") is refused.
  • A call is not a type. String(...) and any resolved helper returning a string produce a socket; only an unmodified global Symbol(), Number() or Boolean() has a settled non-string type.
  • The last assignment wins. {host: 1, host: "localhost"}, {host: 1, ["host"]: "…"} and {host: 1, ...{host: "…"}} all connect, so the member is read in write order and a later spread or computed key leaves it undecided.
  • A Unix path bypasses the check. net.connect({path: "/tmp/s.sock", host: 1}) connects, and tls's {socket} behaves the same.

The positional second argument is a different slot Node does not validate — net.connect(0, 5) connects — so only the member is decided.

Contract and boundary impact

  • Semantic owner and earliest changed stage: socket acquisition filtering in the JavaScript semantic domain.
  • CLI and MCP/tool-catalog contract: none.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: a rejected call no longer reports an acquisition or its release; an accepted call keeps both.
  • Generated metadata, package, or installation impact: none.

Expected effects:

  • Analysis facts only; no target interaction.

Validation performed

  • 43 cases over both branches, 13 failing before this commit.
  • src/domain/javascript — 5083 passed.
  • npx tsc --noEmit -p . — exit 0
  • npm run build — exit 0
  • npm run format:check — exit 0
  • npm run lint — 0 errors
  • npm run knip — exit 0

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

Author readiness

Human owner: @XiaoBinGan

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T07:59:25.707098Z 63aca79 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The reviewed changes appear safe to merge.

Summary

The PR filters socket facts when options.host is known to make Node throw. The latest change checks inherited options at call time, after all arguments have run.

  • Socket analysis skips calls with a known invalid host.

Reviews (6) · Last reviewed commit: "fix(javascript): compare the prototype e..." · Reviewed by Greptile

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f49bc04281

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

All nine fixed in 8727f30a2, each measured on Node 24.22.1 first. You were right on every one: the first version was too aggressive in four independent ways and each erased a real socket.

A call is not a type. String("127.0.0.1") and any resolved helper returning a string produce a socket; only an unmodified global Symbol(), Number() or Boolean() has a settled non-string type. Every other call now stays undecided.

The last assignment wins. {host: 1, host: "localhost"}, {host: 1, ["host"]: "…"} and {host: 1, ...{host: "…"}} all connect, because the literal is built in write order. The member is now read in that order, and a later spread or computed key leaves it undecided instead of trusting the first explicit key.

A Unix path bypasses the host check. net.connect({path: "/tmp/s.sock", host: 1}) returns a socket because path selects the Unix overload; tls's {socket} does the same. Both are detected before the member is read.

Constant expressions fold. !0, -1, +1 and !!1 are truthy non-strings and throw, while -0 and !1 are falsy and connect. A small folder now handles literals, void, !, unary +/-/~, typeof and the unmodified numeric globals.

Shadowed Infinity. The global is now confirmed with isUnmodifiedGlobalReference instead of matching the name, so a binding named Infinity holding a string keeps its socket.

43 cases, 13 failing before this commit. src/domain/javascript: 5040 → 5083 passing. tsc 0; build 0; format:check 0; lint 0 errors; knip 0.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8727f30a2a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

All six fixed in e75e21fc1, each measured on Node 24.22.1 first. You were right that the overload test trusted presence where Node reads the value.

A falsy path or socket does not select the overload. net.connect({port: 0, path: undefined, host: 1}), {path: "", host: 1}, {path: 0, host: "localhost"} and tls.connect({port: 0, socket: null, host: 1}) all reach the host read and throw on a numeric host. Both members are now folded, and the TCP path runs when the value is falsy.

A later write replaces the path. {path: "/tmp/x.sock", ...{path: undefined}, host: 1} and the duplicate-key form both throw. Member reads now walk writes in order and inline a spread of an object literal, so the last assignment is the one decided; a spread of anything else leaves the member unknown.

A non-literal path leaves the overload open. const p = "/tmp/a.sock"; net.connect({port: 0, path: p, host: 1}) returns a socket. An unreadable path now returns undefined from the overload test, and undefined no longer means "check the host" — only false does.

A shadowed undefined is not the global. const undefined = "x" makes !undefined falsy; the undefined arm now goes through isUnmodifiedGlobalReference like NaN and Infinity already did.

Number()/Boolean() results fold. Number(0), Number("x") and Boolean(0) are falsy, so Node skips the host read and connects; only Number(1)/Boolean(1) throw. Both now fold over a foldable argument instead of being rejected on type.

55 cases, 10 failing before this commit. src/domain/javascript: 5083 → 5095 passing. tsc 0; build 0; format:check 0; lint 0 errors; knip 0.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e75e21fc1d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

All three in 878221ead, measured on Node 24.22.1. All three come from the same mistake on my side: reading a literal whose own keys are not the whole story.

A spread can run a getter that rewrites another key. {port: 0, ...{get x() { this.host = "localhost"; return 0 }, host: 1}} reaches host === "localhost", because the getter ran while the spread was copied into the object being built. Reading host: 1 from the inner literal is wrong.

__proto__ supplies an inherited key. net.connect({__proto__: {path: "/tmp/a.sock"}, host: 1}) connects, because the inherited path selects the Unix overload. An own-keys-only reader reports path missing.

An empty path still lets tls wrap a real socket. tls.connect({path: "", socket: base, host: 1}) with a real stream returns a TLSSocket: the empty path does not select the Unix overload, but it does not block the socket wrap either, so the socket check has to run next instead of the function returning early.

finalMemberNode now refuses a literal with any spread, computed key, accessor or __proto__ — every member becomes unknown and no caller decides from it — and an empty path falls through to the socket check. I also dropped the spread-inlining it did before: inlining is what produced all three of these findings.

57 cases, 3 failing before this commit; removing the plain-literal guard fails two of them, so it is load-bearing. src/domain/javascript: 5095 → 5097 passing. tsc 0; build 0; format:check 0; lint 0 errors; knip 0.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 878221eade

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

Fixed in f6058bd7a. Confirmed on Node 24.22.1: after Object.prototype.path = "/tmp/a.sock", net.connect({port: 0, host: 1}) returns a Unix socket because the inherited path wins — Object.prototype is in the literal's chain. The own-key read reported path missing and the host filter then rejected a real acquisition.

finalMemberNode now returns unknown for a member the literal does not write while an earlier Object.prototype mutation site exists, using the same semanticEffectTiming rule the other prototype guards use. An own key still beats the inherited one, so {path: "", host: 1} keeps its decided rejection.

Also moved the __proto__ exclusion onto isObjectPrototypeSetter, the shared owner of that check, so a shorthand or computed spelling is covered by the same predicate instead of a second string comparison.

One detail worth recording: this only fires when the prototype-mutation collector actually runs, which needs a function, array or loop somewhere in the source. A file with none of those does not collect prototype facts at all, so the finding is not reachable there either way.

59 cases; the inherited-path case fails with the guard reverted. src/domain/javascript: 5097 → 5099 passing. tsc 0; build 0; format:check 0; lint 0 errors; knip 0.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f6058bd7a7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

The invocation-timing one is fixed in 6c0d48f3d. A later argument is evaluated before the call runs, so net.connect({port: 0, host: 1}, Object.prototype.path = "/tmp/a.sock") already carries the inherited path when Node reads the options — measured on Node 24.22.1 it returns a Unix socket. The guard compared the mutation with the options literal, which is source-earlier, so the effect classified as "after". It now compares against the whole call expression. Case added at module scope, because the collector only runs for a source containing a function/array/loop and the shared table helper wraps its body in a function — inside one the earlier timing already held, so a wrapped case would not have exercised this.

The intrinsic-alias one I am not fixing here, and I want to be direct about why. const p = Object.getPrototypeOf({}); p.path = "…" and const p = ({}).__proto__; p.path = "…" both connect on Node 24.22.1 — confirmed. Neither is in prototypeMutationSites, because indexPrototypeUncertaintySteps has no case that ties an intrinsic-produced prototype reference back to its owner. That is the producer, and it is the same producer behind the two threads I left open earlier. Each round here has closed one consumer-side variant and the next round has found another spelling of the same missing owner fact; adding a third consumer check would not end that.

What would: teach the collector that Object.getPrototypeOf(<object>) and <object>.__proto__ yield owner Object, and that a write through such a binding is a write to that owner. I do not want to guess at the intended shape of that in a file I do not own, and a wrong version would silently widen every prototype guard in the repo.

5219 → 5221 + 5100 in src/domain/javascript; tsc 0; build 0; format:check 0; lint 0 errors; knip 0.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6c0d48f3d2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@XiaoBinGan
XiaoBinGan force-pushed the fix/socket-host-literal branch 2 times, most recently from 9657322 to 6ccba4e Compare November 9, 2026 07:29

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6ccba4e976

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

You were right, and this is the producer-side fix rather than another consumer check — 471df9a08.

needsPrototypeFacts was set only by with, for-in, for-of, an array literal or a function node, so a module with none of those never ran indexPrototypeUncertaintySteps and prototypeMutationSites stayed empty. That is exactly your diagnosis, including the observation that the existing tests all introduce function g, f or seed and therefore mask it.

Measured on Node 24.22.1, Object.prototype.path = "/tmp/a.sock"; net.connect({port: 0, host: 1}) connects over the inherited path:

where the write is before after
inside function g() { ... } 1 acquisition 1
at module top level 0 1

Two things worth naming in the fix:

  • It only inspects a node that is itself a write (assignment target, update target, delete operand), and looks exactly two levels in (Object.prototype) instead of walking to the root. My first version walked the member chain for every node and pushed the 12,000-member fixture past its timeout; the O(1) form keeps the suite at the same 30s.
  • delete Object.prototype.path counts as a write too, because whether the delete succeeds is not settled by the syntax.

4 cases added; reverting the trigger fails 2. src/domain/javascript: 5184 → 5188 passing. tsc 0; build 0; format:check 0; lint 0 errors.

The other three open threads on this PR are the intrinsic-alias and opaque-eval cases, which need changes inside indexPrototypeUncertaintySteps itself. I have not touched those.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 471df9a08f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@XiaoBinGan
XiaoBinGan force-pushed the fix/socket-host-literal branch from 471df9a to 3297355 Compare November 10, 2026 17:47
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

Rebased onto current main as one commit; the branch previously conflicted over 370 lines because its socket-host helpers and the TLS protocol-version work that landed since rewrite the same region of javascriptSemanticResources.ts.

The two sides are independent additions that share the region's leading /** and its trailing };:

  • main declares TLS_PROTOCOL_VERSIONS, rejectsTlsProtocolVersionLiteral and tlsOptionMerge.
  • This branch declares staticConstantValue, MemberRead, isPlainOptionsLiteral, defaultPrototypeMaySupply and finalMemberNode.

No declaration name is shared, and git diff <merge-base> <branch> shows the branch never touched the three main-side names, so the union keeps both blocks — closing main's function and opening this branch's block at the seam — and the acquisition filter now ANDs rejectsTlsProtocolVersionLiteral with rejectsSocketHostMember.

Validation: a full-project tsc --noEmit reports no error naming this file. I could not execute the branch's 203 test cases locally: the pinned toolchain moved to Node 24.22.1 and npm ci does not complete against the registry from this host, so the installed dependencies are incomplete. CI on this PR is the first test run, and the earlier failing shards were inherited from a red main rather than from this change.

Resolved against current main. The branch's socket-host work and the TLS
protocol-version work that landed since rewrite the same helper region, so the
squash merge conflicted over 370 lines.

Both sides are complete additions that share the region's leading `/**` and its
trailing `};`: main's side declares TLS_PROTOCOL_VERSIONS,
rejectsTlsProtocolVersionLiteral and tlsOptionMerge, while this branch declares
staticConstantValue, MemberRead, isPlainOptionsLiteral, defaultPrototypeMaySupply
and finalMemberNode. No declaration name is shared, and the branch never touched
the three main-side names, so the union keeps both blocks, closes main's function
and opens this branch's block at the seam. The acquisition filter now ANDs
rejectsTlsProtocolVersionLiteral with rejectsSocketHostMember.

Verified with a full-project typecheck: no error names this file (the reported
errors are missing modules from an interrupted dependency install). The branch's
203 test cases could not be executed locally because `npm ci` cannot complete
against the registry here, so CI is the first test run.
@XiaoBinGan
XiaoBinGan force-pushed the fix/socket-host-literal branch from 3297355 to f5a9cca Compare November 10, 2026 17:55
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

…mutator

Two producer findings, both measured on Node 24.22.1.

**A mutator call changes a prototype with no assignment in the source.** The trigger only looked at
assignment, update and delete targets, so `Object.defineProperty(Object.prototype, "path", {value:
"/tmp/a.sock"})` left the prototype facts off and the later `net.connect({port: 0, host: 1})` lost
its acquisition. The call is a write target now, and the spelling test it needs is shared with the
assignment arm so the two cannot drift.

**A write through an alias names the alias, not the owner.** `const p =
Object.getPrototypeOf({}); p.path = "/tmp/a.sock"` reaches `Object.prototype` and connects, but
nothing connected `p` to `Object`. The alias table is built syntactically — bindings are not
resolved at the point the facts are indexed, and `p` is recognisable without them — and a write
whose base is such an alias reports the owner.

The alias is also a fact trigger: the write below spells `p`, so only the call that produced it can
turn the prototype facts on.

`src/domain/javascript` — 5462 passing. Reverting both halves fails the new cases.
@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

Both producer findings fixed in ae82d8897, each measured on Node 24.22.1.

A mutator call now counts as a prototype write. Object.defineProperty(Object.prototype, "path", {value: "/tmp/a.sock"}) connects a later net.connect({port: 0, host: 1}) over the inherited path — confirmed. The trigger only looked at assignment, update and delete targets, so the facts stayed off. The spelling test the assignment arm already had is now shared, so the two arms cannot drift.

An alias is resolved to its owner. const p = Object.getPrototypeOf({}); p.path = "/tmp/a.sock" connects — confirmed. Nothing tied p to Object.

The alias table is syntactic, and the reason is worth stating: indexPrototypeUncertaintySteps runs before bindAssignment, so resolveSemanticBindingState has nothing to return at that point. I tried moving the producer after the binding loop first, and it broke two existing cases (retains prototype uncertainty for an empty template in for-in/for-of) because the prototype facts then carried a different effect order. Rather than reorder the pass, the alias is recognised from the declarator shape, which needs no bindings.

The alias is also a fact trigger: the write below spells p, so only the call that produced it can turn the facts on. readsIntrinsicPrototype handles that.

Still open on this PR, and I am not claiming them: the later-options tls.connect host merge, and the opaque-eval case. Both are in the same host filter and I will take them next unless you would rather they were separate changes.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ae82d8897c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Two host-filter findings, both measured on Node 24.22.1.

**`tls` merges a later options object before the host is read.**

| call | outcome |
| --- | --- |
| `tls.connect({port: 0, host: 1}, {host: "localhost"})` | socket created |
| `tls.connect({port: 0, host: "localhost"}, {host: 1})` | THREW `ERR_INVALID_ARG_TYPE` |
| `tls.connect({port: 0, host: 1}, {})` | THREW — an empty override writes nothing |

The filter read only slot 0, so it decided from a value the merge had replaced. `mergedOptionsLiteral`
returns the later literal when it writes `host`, nothing when it cannot change the host, and
`unknown` when it might, so the overload test and the host read both see the effective object.

**An opaque global effect can patch the intrinsic a value folds through.** `isUnmodifiedGlobalReference`
covers the writes the source shows; it does not cover `globalThis.eval("Number = String")`, which the
analyzer records separately.

| call | outcome |
| --- | --- |
| `globalThis.eval("Number = String"); net.connect({port: 0, host: Number(1)})` | socket created |
| `net.connect({port: 0, host: Number(1)})` | THREW `ERR_INVALID_ARG_TYPE` |

`semanticOpaqueGlobalMayHaveChanged` gates the fold, so a call whose intrinsic may have been replaced
stays undecided.

`src/domain/javascript` — 5462 passing.
@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

Both fixed in e4c0cc3ab, measured on Node 24.22.1.

The merged host. tls.connect({port: 0, host: 1}, {host: "localhost"}) creates a socket, tls.connect({port: 0, host: "localhost"}, {host: 1}) throws ERR_INVALID_ARG_TYPE, and tls.connect({port: 0, host: 1}, {}) throws because an empty override writes nothing. The filter read only slot 0, so it decided from a value the merge had replaced. mergedOptionsLiteral returns the later literal when it writes host, nothing when it cannot change the host, and unknown when it might — and both the overload test and the host read now use that effective object.

The opaque patch. isUnmodifiedGlobalReference covers the writes the source shows; it does not cover globalThis.eval("Number = String"), which this analyzer records separately. globalThis.eval("Number = String"); net.connect({port: 0, host: Number(1)}) creates a socket while the same call without the eval throws. semanticOpaqueGlobalMayHaveChanged gates the fold now.

All four threads on this PR are addressed. The two producer-side ones changed where the facts come from rather than how the filter reads them, which I think is the right split: the filter asked a correct question and the answer table was incomplete.

…guous alias

Two producer findings.

**`Reflect.defineProperty` has the same effect as the `Object` form.** Measured on Node 24.22.1,
`Reflect.defineProperty(Object.prototype, "path", {value: "/tmp/a.sock"})` then
`net.connect({port: 0, host: 1})` connects over the inherited path. The receiver test only accepted
`Object`. Two of the three mutators take a `Reflect` spelling (`Reflect.apply` and
`Reflect.construct` are not property definitions), so only those two are accepted.

**A name with two different owners is not an alias.** The table was first-wins over the whole
program, so an inner `const p = Object.getPrototypeOf({})` shadowing an outer
`p = Object.getPrototypeOf([])` resolved the inner write to `Array` — a prototype mutation
attributed to the wrong owner. A second declarator with a different owner now makes the name
unusable instead.

That leaves one shape undecided and I would rather say so than guess: the shadowed write reports
nothing, because the table is built from the program rather than from the binding at the write.
Deciding it needs per-write scope resolution, which is a different piece of work. Attributing it to
`Array` was worse — that is a wrong fact, while no fact at least keeps the answer open.

`src/domain/javascript` — 5467 passing.
@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

Both fixed in 63aca7993.

Reflect.defineProperty — confirmed, it reaches Object.prototype the same way. The receiver test only accepted Object. Two of the three mutators have a Reflect spelling (Reflect.apply and Reflect.construct are not property definitions), so exactly those two are accepted from Reflect.

The first-wins map — you are right, and the failure was worse than a miss: an inner const p = Object.getPrototypeOf({}) shadowing an outer p = Object.getPrototypeOf([]) attributed the inner write to Array. That is a wrong fact, not a missing one, and it would have made the filter reason about the wrong prototype.

I have not made the inner write correct, and I want to be direct about why. The table is built from the program; it does not know which declarator is in scope at the write, so picking the inner one would be as unfounded as picking the outer. A second declarator with a different owner now makes the name unusable, so the answer stays open instead of being attributed to Array.

Deciding it properly needs the scope of the write, which means carrying the binding index into this pass — resolveSemanticBindingState has nothing to return there because indexPrototypeUncertaintySteps runs before bindAssignment. I tried moving the producer after the binding loop and it broke the for-in/for-of uncertainty cases, so the pass order is not free to change. If you think this belongs in the PR anyway, say so and I will take the binding index through the pass; otherwise it is a follow-up with its own test.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 63aca79932

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

);
} else {
const owner = globalOwner(value);
const owner = globalOwner(value) ?? aliasOwner(value);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Do not taint prototypes on alias rebinding

When a prototype alias is later rebound, for example let p = Object.getPrototypeOf({}); p = {}; net.connect({ port: 0, host: 1 }), this fallback treats the identifier assignment itself as an Object.prototype mutation. defaultPrototypeMaySupply then makes the absent path unknown and preserves an acquisition, but the rebinding does not touch Object.prototype and Node throws on the numeric host; bare alias writes need to update or retire the alias rather than call taint.

AGENTS.md reference: AGENTS.md:L19-L19

Useful? React with 👍 / 👎.

gensokyo-dev added a commit that referenced this pull request Nov 14, 2026
net and tls connect through options.host || "localhost" and throw
ERR_INVALID_ARG_TYPE from the call when that is not a string, so a truthy
non-string host leaves no socket. Read the final host, path and TLS socket
members through one option reader shared with the TLS protocol-version
check, and drop the acquisition only when the host is statically truthy and
not a string while no truthy path or TLS socket, or an Object.prototype
write that may supply one, skips the host read.

The truthy and falsy host tests come from #9380. Its intrinsic-prototype
gating changes are not included.

Fixes #10002

Co-Authored-By: 吴佳浩 <[email protected]>
Co-Authored-By: gensokyo-dev <[email protected]>
N0zoM1z0 pushed a commit that referenced this pull request Nov 14, 2026
net and tls connect through options.host || "localhost" and throw
ERR_INVALID_ARG_TYPE from the call when that is not a string, so a truthy
non-string host leaves no socket. Read the final host, path and TLS socket
members through one option reader shared with the TLS protocol-version
check, and drop the acquisition only when the host is statically truthy and
not a string while no truthy path or TLS socket, or an Object.prototype
write that may supply one, skips the host read.

The truthy and falsy host tests come from #9380. Its intrinsic-prototype
gating changes are not included.

Fixes #10002

Co-Authored-By: 吴佳浩 <[email protected]>
Co-Authored-By: gensokyo-dev <[email protected]>
@N0zoM1z0

Copy link
Copy Markdown
Collaborator

Thank you. #10538 reimplemented the socket host decision on the existing TLS option reader and kept your truthy/falsy host tests, crediting you as co-author. The intrinsic-prototype gating commits are not included. Closing this PR as superseded.

@N0zoM1z0 N0zoM1z0 closed this Nov 14, 2026
@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

Understood — thanks for carrying it over. I re-read main before answering, and the two routes those commits covered are now owned by different modules than the ones I patched:

  • a mutator call that edits a prototype — indexPrototypeUncertaintySteps in javascriptSemanticAnalysis.ts treats defineProperty / defineProperties / setPrototypeOf on an intrinsic owner as a write site and taints the owner, only for argument 0.
  • a write through a Object.getPrototypeOf(...) alias — javascriptSemanticAmbientWrites.ts resolves the alias and the existing suite asserts it (javascriptStaticAnalysis.mapEndpoints.test.ts, const records = new Map(); Object.getPrototypeOf(records).get = fetch; new Map().get("/accounts")).

So I have nothing left to carry over from that branch, and I am not reopening it. If a route is still unproven somewhere, the smallest useful thing I can add is the failing input plus the runtime measurement that shows it, not the patched branch.

@morluto morluto added bug Something isn't working area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] net/tls socket host member is not decided by its string type

3 participants