Skip to content

fix(javascript): reject an http method token Node refuses at the call site - #9683

Merged
N0zoM1z0 merged 2 commits into
morluto:mainfrom
XiaoBinGan:fix/http-method-token
Nov 21, 2026
Merged

N0zoM1z0 merged 2 commits into
morluto:mainfrom
XiaoBinGan:fix/http-method-token

Conversation

@XiaoBinGan

Copy link
Copy Markdown
Contributor

Summary

http.request and https.request validate options.method with checkIsHttpToken before they build the request, so a literal outside the token set throws ERR_INVALID_HTTP_TOKEN from the call itself and no request exists. The analysis reported one anyway.

Measured on Node 24.22.1

options.method outcome
"GET", "get", "M-SEARCH", "X", "!#$%&'*+-.^_`|~" request constructed
"" request constructed — Node reads it as "not given" and falls back to GET
"BAD METHOD", "G/ET", "G:ET", "G,ET", "GET ", " ", "\t", "GéT" THREW ERR_INVALID_HTTP_TOKEN

Two consequences worth naming:

  • The accepted set is the RFC 9110 token character class, not a list of verbs. "GET " fails on the trailing space while "get" and "M-SEARCH" pass.
  • An empty string is accepted, because Node reads "" as "not given" rather than as an invalid token. Treating it as invalid would drop a real request.

fetch and WebSocket read a different member and validate no token, so they are untouched. A non-string method throws ERR_INVALID_ARG_TYPE, but that is left undecided because the reported fields do not describe the type check.

Contract and boundary impact

  • Semantic owner and earliest changed stage: request candidate collection 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 a request operation or its fields; an accepted call keeps both.
  • Generated metadata, package, or installation impact: none.

Expected effects:

  • Analysis facts only; no target interaction.

Validation performed

  • 16 cases, 8 failing before this commit.
  • src/domain/javascript — 5402 passed.
  • npm run format:check — exit 0 for the files this PR touches. The reported issue is in src/cli/adbCommands.ts.
  • npm run lint — the one error is the adbCommands.ts duplicate declaration below.
  • npm run build — fails only on that same adbCommands.ts error.

tsc, lint and build all fail on src/cli/adbCommands.ts(46,9): error TS2451: Cannot redeclare block-scoped variable 'packageName', which main at e9b6c87c1 already has and which this PR does not touch. #9677 and #9678 are open fixes for it. I did not include it here so this PR keeps one outcome.

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 9, 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-12T00:51:57.297788Z 17e9047 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.

@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: 632392c78f

ℹ️ 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

Both fixed in 3db1facc0, each measured on Node 24.22.1 first.

An erased TypeScript assertion hides the options object. http.request(({host: "h", method: "BAD METHOD"}) as any) throws ERR_INVALID_HTTP_TOKEN at runtime, but node.arguments[0] is a TSAsExpression, so the raw isObjectExpression test chose the absent second argument and returned false before the unwrap. The first argument is now unwrapped before the slot is chosen.

A leading spread shifts the options slot. Confirmed:

call Node 24.22.1
http.request(...[{host, path}, () => {}], {method: "BAD METHOD"}) OK — builds a GET request
http.request({host, method: "BAD METHOD"}) THREW ERR_INVALID_HTTP_TOKEN

The spread fills both runtime slots and the trailing object is ignored, so this branch was inspecting an argument Node never reads and dropping a real request. A spread argument now leaves the position unresolved and keeps the request — the same rule as the TLS overload-slot reader on main.

You also suggested sharing the normalized selection with requestFields. I did not do that here: requestFields reads the fields of whichever object it selects, and changing what it selects would change the reported field set in cases this fix does not measure. If you want them unified, that is a separate change with its own evidence and I will take it as its own PR.

18 cases; the two new ones fail against the pre-fix file and pass here. src/domain/javascript: 5402 → 5404 passing.

@XiaoBinGan
XiaoBinGan force-pushed the fix/http-method-token branch from 3db1fac to 76926ce Compare November 10, 2026 02:55

@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: 76926ce8da

ℹ️ 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

Both fixed in 2e36db24d, each measured on Node 24.22.1.

A callable first argument is the callback. http.request(() => {}, {method: "BAD METHOD"}) and the function spelling both return a GET ClientRequest — confirmed. A callable anywhere in the argument list now leaves the position unresolved.

Object.assign runs getters before it copies. http.request({get x() { this.method = "GET"; }, method: "BAD METHOD"}) returns a GET request — confirmed. The reader bails on an options literal carrying a getter, the same rule the TLS and socket readers use.

src/domain/javascript: 5404 → 5407 passing.

@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: 2e36db24d5

ℹ️ 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

Both fixed in 28e9b304e, each measured on Node 24.22.1.

Only a callable in slot 0 is the callback. http.request({method: "BAD METHOD"}, () => {}) throws ERR_INVALID_HTTP_TOKEN — confirmed. The bailout looked at every argument; it now looks at slot 0 only, so a callback after the options no longer suppresses the check.

A getter only rewrites a member that follows it. Object.assign walks in order:

call Node 24.22.1
{get x() {...}, method: "BAD METHOD"} request constructed — the getter runs first
{method: "BAD METHOD", get x() {...}} THREW — the invalid value was copied first

methodGetterPrecedesMember compares the getter index against the member index instead of treating every getter as able to rewrite it. That is the same ordering fact the TLS merge reader needed, so the rule is now consistent across both readers.

src/domain/javascript: 5407 → 5411 passing.

@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: 28e9b304e3

ℹ️ 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

Both fixed in afe3cae7c, each measured on Node 24.22.1.

An erased assertion leaves the same callback. http.request((() => {}) as any, {method: "BAD METHOD"}) returns a default GET — confirmed. The guard tested the raw TSAsExpression, so it missed the function. The slot-0 value is unwrapped first now.

Object.assign enumerates integer-index keys before string keys. You were right that source order is not copy order:

call Node 24.22.1
{method: "BAD METHOD", get 0() {...}} request constructed — getter 0 runs first
{method: "BAD METHOD", get x() {...}} THREW — the invalid value was copied first
{get 0() {...}, method: "BAD METHOD"} request constructed
{get x() {...}, method: "BAD METHOD"} request constructed

methodGetterPrecedesMember compares [group, order] tuples now — integer group ascending, then the string group in insertion order.

Worth recording: my first attempt folded both groups into one number (key * 1e6 + index) and lost precision past 2^53, so two of these four cases reported the opposite answer while the tests still read plausibly. The tuple form is what makes the two groups independent.

src/domain/javascript: 5411 → 5414 passing.

@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: afe3cae7ce

ℹ️ 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 fixed in 4a08abb2e, each measured on Node 24.22.1.

A redefined key keeps its first insertion position. Confirmed:

call Node 24.22.1
{x: 0, method: "BAD METHOD", get x() {...}} request constructed — x enumerates first
{y: 0, method: "BAD METHOD", get x() {...}} THREW — the getter is on a fresh key

The helper now takes each key's position from its first insertion and its descriptor from the last. That is the distinction I had been collapsing: position and descriptor are two different facts about a redefined key, and using the AST index of the last write was reading the wrong one.

Only an ECMAScript array index enumerates in the integer group. Confirmed the boundary:

key outcome
get 4294967294() request constructed — array index, runs first
get 4294967295() THREW — enumerates with the string keys

The predicate is canonical integer, >= 0, < 2 ** 32 - 1 now instead of digits-only. String(key) === name also rules out "01" and "1e3", which are digits-only matches but not array indexes.

A spread after the options slot cannot move it. http.request({method: "BAD METHOD"}, ...[]) throws — confirmed. Only a spread in slot 0 leaves the position unresolved.

src/domain/javascript: 5414 → 5420 passing.

@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: 4a08abb2e4

ℹ️ 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/http-method-token branch from 4a08abb to 67d62e1 Compare November 10, 2026 19:08

@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: 67d62e118e

ℹ️ 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 four fixed in d6c96470e, each measured on Node 24.22.1.

https and http disagree about a falsy input. Confirmed:

call Node 24.22.1
https.request(null, {method: "BAD METHOD"}) ClientRequest — later object never read
https.request(false, {...}), https.request(0, {...}) ClientRequest
http.request(null, {method: "BAD METHOD"}) THREW ERR_INVALID_ARG_TYPE

requestMethod now reports which module supplied the callee, and the reader keeps the request only on https. The http shape needs no new handling — finding no options object already reports it.

A spread supplies the first insertion position. {...{x: 0}, method: "BAD METHOD", get x() {...}} builds the request. An empty spread supplies nothing, so {...{}, method: "BAD METHOD"} still throws — the reader sees through an object-literal argument and only bails for a spread it cannot empty out. That keeps the rule precise instead of making every spread a bailout.

A computed accessor can run before any named member. const k = "x"; {get [k]() {...}, method: "BAD METHOD"} builds the request; semanticStaticPropertyKey returned null, so the old loop erased the accessor entirely.

__proto__: value takes no own-key slot. {__proto__: null, method: "BAD METHOD", get __proto__() {...}} throws ERR_INVALID_HTTP_TOKEN — setting the prototype does not create the position the later accessor would need.

On the duplicate tests: you were right, both standalone cases repeated entries in the it.each blocks above them. They are folded in, so each outcome has one place.

src/domain/javascript: 5427 → 5433 passing. Reverting the reader fails 6 of 40.

XiaoBinGan added a commit to XiaoBinGan/rea that referenced this pull request Nov 11, 2026
A review finding, measured on Node 24.22.1. `ClientRequest` copies the options with
`Object.assign`, so a getter enumerated before `path` runs first and can rewrite the value that
is then validated:

| call | outcome |
| --- | --- |
| `{get agent() { this.path = "/ok"; return undefined; }, path: "/a b"}` | request constructed |
| `{path: "/a b", get agent() { this.path = "/ok"; }}` | THREW `ERR_UNESCAPED_CHARACTERS` |

`optionGetterPrecedesMember` compares enumeration order rather than source order, because
`Object.assign` does not follow the source: an ECMAScript array index comes first and a redefined
key keeps its first insertion position while its descriptor comes from the last write.

Note for merge order: morluto#9683 carries the same ordering rule for `options.method` on this file. If
that lands first, `methodGetterPrecedesMember` and this helper are the same function and should be
collapsed into one.

`src/domain/javascript`: 5422 passing. Reverting the reader fails 2 of the new cases.

@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: d6c96470ed

ℹ️ 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 fixed in 6ab666be8, each measured on Node 24.22.1.

A callable binding is the callback. Confirmed:

call Node 24.22.1
const cb = () => {}; http.request(cb, {method: "BAD METHOD"}) default GET — slot 1 unread
const cb = {}; http.request(cb, {method: "BAD METHOD"}) THREW ERR_INVALID_HTTP_TOKEN

isCallableNode follows a stable binding through semanticStableInitializer, so the binding case is decided and a non-function binding still decides from slot 0 — the second row is the control that keeps the fix from becoming a blanket bailout.

The HTTPS head is unwrapped once at the top of the function. https.request((null as any), {method: "BAD METHOD"}) builds a default request, and the raw-node test missed the erased assertion. Every later check now reads the same unwrapped value, so this cannot drift again.

Only the colon form __proto__ sets the prototype. const __proto__ = 0; {__proto__, method: "BAD METHOD", get __proto__() {...}} builds the request while the colon form throws. The exclusion requires !property.shorthand now.

src/domain/javascript: 5439 passing. Reverting the reader fails 4 of the 46 cases in the file.

@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: 6ab666be89

ℹ️ 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/http-method-token branch from 6ab666b to d7355cd Compare November 11, 2026 16:56

@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: d7355cdf87

ℹ️ 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

I replaced this branch with a much smaller slice (d7355cdf8, +136 instead of +468), so these five threads point at code that no longer exists. Rather than answer each one against deleted lines, here is the honest account of what changed and why, including the gaps.

Why it shrank. Every finding below was real, and the fixes for them grew the change to 468 lines of one function — eight commits, 25 review threads, and still growing. That growth was itself the problem: I was trying to decide Object.assign's enumeration order (integer keys first, first-insertion position for a redefined key, computed getter keys, spread-supplied keys) inside a change whose stated outcome was "reject a method token Node refuses". Those are two different questions.

What the branch decides now. Only shapes where the copied value is certainly the syntactic one: slot 0 is an options literal, or slot 0 is a string, a template, or a verified new URL. Everything else keeps the request.

The gaps this leaves, stated plainly:

call Node 24.22.1 this branch
function cb() {}; http.request(cb, {...}) request constructed kept — correct, isCallableNode is gone and a non-object head is no longer decided
{...{x: 0}, method: "BAD METHOD"} THREW kept
{method: "BAD METHOD", get [4294967295]() {...}} THREW kept
{set x(_) {}, method: "BAD METHOD"} THREW kept
https.request(-0, {method: "BAD METHOD"}) request constructed kept — correct

The first and last are right. The middle three are the deliberate cost: the request is kept where Node would throw. That direction is the safe one — the alternative deletes real requests, which is the failure I have had to fix most often across these threads.

The duplicate-test finding is moot: the test file is rewritten for the smaller scope, and each outcome appears once.

The enumeration-order work belongs in its own change, where it can be reviewed as one piece instead of accreting one row per review round. I would rather hand you a 136-line change with a named gap than a 468-line one with the same gap plus ten more open threads.

… site

`http`/`https` validate `options.method` with `checkIsHttpToken` before the request exists, so a
literal outside the RFC 9110 token class throws `ERR_INVALID_HTTP_TOKEN` and no request is
created. The analyzer reported one anyway.

Measured on Node 24.22.1:

| call | outcome |
| --- | --- |
| `http.request({method: "BAD METHOD"})` | THREW `ERR_INVALID_HTTP_TOKEN` |
| `http.request({method: "GET"})`, `{method: "POST"}` | request constructed |
| `http.request({method: ""})` | request constructed — empty is a valid token, Node falls back to GET |
| `http.request("http://h/", {method: "BAD METHOD"})` | THREW |
| `http.request(new URL("http://h/"), {method: "BAD METHOD"})` | THREW |

## What this decides, and what it deliberately does not

Only shapes where the copied value is certainly the syntactic one:

- slot 0 is an options literal, or
- slot 0 is a string, a template or a verified `new URL`, so the `(url, options)` overload is proven

Every other shape keeps the request. Each of these was measured and can put something else in the
slot or change the copied value:

| call | outcome | why undecided here |
| --- | --- | --- |
| `http.request(() => {}, {method: "BAD METHOD"})` | request constructed | slot 0 is the callback, slot 1 unread |
| `https.request(null, {method: "BAD METHOD"})` | request constructed | `https` keeps its default options for a falsy input |
| `{get x() { this.method = "GET"; }, method: "BAD METHOD"}` | request constructed | the getter runs before the copy |
| `{method: "BAD METHOD", get x() { this.method = "GET"; }}` | THREW | getter after the copy cannot rescue it, but this reader does not model copy order |
| `{...{host: "h"}, method: "BAD METHOD"}` | THREW | a spread may replace the member |

The last two are the honest gap in this change. Closing them needs `Object.assign`'s enumeration
order — integer keys first, first-insertion position for a redefined key — which is a different
piece of work and belongs in its own change rather than widening this one.

Keeping a request Node never makes is the safer direction, and it is the direction I chose
wherever the copy is not certainly the literal.

## Contract and boundary impact

- Semantic owner and earliest changed stage: request candidate collection in the JavaScript domain.
- CLI and MCP/tool-catalog contract: none.
- Provider, bridge, target-format, or platform compatibility: `fetch` and `WebSocket` keep their
  existing behavior; both use a different member and do not validate a token.
- Evidence, artifact, provenance, or reconstruction contract: a refused call no longer reports a
  request operation or its linked release.
- Generated metadata, package, or installation impact: none.

Expected effects:

- [x] Analysis facts only; no target interaction.

## Validation performed

- 15 cases in `javascriptSemanticAnalysis.http_method_token.test.ts`; reverting the reader fails 5.
- `src/domain/javascript` — 5644 passing.
- `npm run format:check` — exit 0.
- `npm run lint` — 0 errors.

## Before merge

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

## Author readiness

Human owner: @XiaoBinGan

- [x] 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.
- [x] I checked the evidence above, confirm it supports the current change, and recorded meaningful validation gaps.
- [x] I declare this PR ready for initial maintainer review.
@XiaoBinGan
XiaoBinGan force-pushed the fix/http-method-token branch from d7355cd to 17e9047 Compare November 12, 2026 00:48
XiaoBinGan added a commit to XiaoBinGan/rea that referenced this pull request Nov 12, 2026
A review finding, measured on Node 24.22.1. `ClientRequest` copies the options with
`Object.assign`, so a getter enumerated before `path` runs first and can rewrite the value that
is then validated:

| call | outcome |
| --- | --- |
| `{get agent() { this.path = "/ok"; return undefined; }, path: "/a b"}` | request constructed |
| `{path: "/a b", get agent() { this.path = "/ok"; }}` | THREW `ERR_UNESCAPED_CHARACTERS` |

`optionGetterPrecedesMember` compares enumeration order rather than source order, because
`Object.assign` does not follow the source: an ECMAScript array index comes first and a redefined
key keeps its first insertion position while its descriptor comes from the last write.

Note for merge order: morluto#9683 carries the same ordering rule for `options.method` on this file. If
that lands first, `methodGetterPrecedesMember` and this helper are the same function and should be
collapsed into one.

`src/domain/javascript`: 5422 passing. Reverting the reader fails 2 of the new cases.

@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: 17e90478cc

ℹ️ 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".

A review finding, measured on Node 24.22.1. `_` is an RFC 9110 `tchar`, and the class I wrote
omitted it, so a valid method was reported as refused:

| call | outcome |
| --- | --- |
| `http.request({method: "M_SEARCH"})` | request constructed |
| `http.request({method: "X_CUSTOM"})` | request constructed |
| `http.request({method: "_"})` | request constructed |
| `http.request({method: "M-SEARCH"})` | request constructed |
| `http.request({method: "A B"})` | THREW `ERR_INVALID_HTTP_TOKEN` |

The class now matches RFC 9110 exactly. Three cases pin the characters a hand-written class is
most likely to drop: `_`, and the `-` that was already present.

`src/domain/javascript`: 5665 passing.
@XiaoBinGan
XiaoBinGan force-pushed the fix/http-method-token branch from e5d5d5f to 6383983 Compare November 12, 2026 01:17
@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

Fixed in 638398356. You are right — _ is an RFC 9110 tchar and my hand-written class dropped it:

call Node 24.22.1
http.request({method: "M_SEARCH"}) request constructed
http.request({method: "X_CUSTOM"}) request constructed
http.request({method: "_"}) request constructed
http.request({method: "M-SEARCH"}) request constructed
http.request({method: "A B"}) THREW ERR_INVALID_HTTP_TOKEN

The class matches RFC 9110 exactly now, and three cases pin the characters a hand-written class is
most likely to drop: _, -, and the empty string that is valid but looks invalid.

Worth saying: this is the second time in this PR that a hand-written spelling of a standard
disagreed with the standard. I should have started from the RFC's character list rather than typing
one out.

@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

Re-checked against main (ebd709cef); the change is still missing there.

src/domain/javascript/javascriptSemanticDataEffects.ts on main has no http method-token rejection — no ERR_INVALID_HTTP_TOKEN, no token-class check — so a literal method Node refuses at the call site still yields a request in the graph. That is exactly what this branch adds. Not superseded, and the branch applies cleanly.

@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: On Node 22.23.4, 24.22.1 and 26.12.1, all 18 tests in the PR's test file passed. With the old source file put back, 5 of the 18 tests failed on each version. The head is 1769 commits behind main; I did not test a merge.

Findings

I ran the PR's changed test file, src/domain/javascript/javascriptSemanticAnalysis.http_method_token.test.ts, at head 6383983. For the red run, I put the old source file back.

Check Node 22.23.4 Node 24.22.1 Node 26.12.1
Head, as is pass: 1 file, 18 of 18 tests pass: 1 file, 18 of 18 tests pass: 1 file, 18 of 18 tests
Red run fail: 5 failed, 13 passed (18) fail: 5 failed, 13 passed (18) fail: 5 failed, 13 passed (18)
  • In the red run, I swapped src/domain/javascript/javascriptSemanticDataEffects.ts back to the merge base 047d75a.
  • The same 5 tests failed on all three Node versions.
  • I took the failing names from the Node 24.22.1 log.
  • All 5 are cases of emits no request for a method literal Node refuses, listed below.
  • The other 13 tests passed without the change.
  • The PR changes 2 files against the merge base: the test file above and src/domain/javascript/javascriptSemanticDataEffects.ts.
  • The head is 1769 commits behind main 3d95d34.

The 5 failing cases:

http.request("http://h/", { method: "BAD METHOD" })
http.request({ method: "BAD METHOD" })
http.request({ method: "BAD METHOD" }, {})
http.request(new URL("http://h/"), { method: "BAD METHOD" })
https.request({ method: "BAD METHOD" })

CI on head 6383983 reads mergeable true, state clean, not a draft.

  • Workflow runs: CI is completed/success, PR readiness is completed/success, PR title is completed/success, and CodeQL production is completed/skipped.
  • Check runs: 20 are success, including Source tests, Static checks and CI required. 23 are skipped.
  • Commit status: PR readiness is success.

Not run

  • A run against a real JavaScript bundle. The test feeds the analyzer short source strings.
  • The full test suite in my VM. I ran only the changed test file there.
  • A merge with current main, 3d95d34.
Test setup
  • Box: Fedora 44 VM (4 vCPUs, 8 GB, Linux 7.2.11) on my Nobara 44 PC
  • Node: 22.23.4, 24.22.1, 26.12.1
  • Head / base: 6383983 / 047d75a (merge base with main)
  • Red run: 6383983 with the changed source file from 047d75a
  • Install: npm ci --offline and npm run test:prepare on Node 24.22.1
Commands
npm ci --offline
npm run test:prepare
xvfb-run -a npm run test:focused -- src/domain/javascript/javascriptSemanticAnalysis.http_method_token.test.ts

🤖 Written and tested with Claude Code (Sonnet 5.5, verified by Opus 5.5), posted with my OK 🦊

@gensokyo-dev gensokyo-dev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Verified: the tests for this change pass locally and CI is green. The change is limited to the rule described above, and other cases keep their existing behavior. Thanks.

@N0zoM1z0
N0zoM1z0 merged commit 62c4c25 into morluto:main Nov 21, 2026
44 checks passed
@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
vincentkoc added a commit that referenced this pull request Nov 30, 2026
* fix(javascript): reject an http path Node refuses at the call site

`http.request` and `https.request` validate `options.path` before they build the request, so
a literal carrying an unescaped character throws `ERR_UNESCAPED_CHARACTERS` from the call
itself and no request exists. The analysis reported one anyway.

The accepted set was measured rather than guessed: every ASCII code point was placed inside
a literal path on Node 24.22.1 and exactly `0x00`-`0x20` are refused while `0x21`-`0x7f` are
accepted. That makes it a closed range, not a list of known-bad characters, and three
consequences follow that a hand-written list would get wrong:

| `options.path` | outcome |
| --- | --- |
| `"/a b"`, `" "`, `"\t"`, `"\n"`, `"\u0000"` | THREW `ERR_UNESCAPED_CHARACTERS` |
| `"/a%20b"` | request constructed — the escape is what the literal above should have been |
| `"/aéb"` | request constructed — non-ASCII is inside the accepted range |
| `""` | request constructed — Node reads it as "not given" and falls back to `/` |

`fetch` reads a different member and validates no path. A spread argument or a binding leaves
the answer to the runtime, the same rule the sibling overload-slot readers use.

14 cases, 7 failing before this commit. `src/domain/javascript`: 5372 to 5386 passing.
`tsc` reports only the pre-existing `adbCommands.ts` duplicate `packageName`, which `main`
already has and `#9677`/`#9678` fix.

* fix(javascript): bound the accepted http path range at Latin-1

A reviewer caught that my "non-ASCII is accepted" claim was not established: I had probed
ASCII plus `U+00E9` and generalised from two data points. Probing the upper bound on Node
24.22.1 shows the accepted range is exactly `U+0021`-`U+00FF`:

| `options.path` | outcome |
| --- | --- |
| `U+007F`, `U+00A0`, `U+00E9`, `U+00FF` | request constructed |
| `U+0100`, `U+1000`, `U+4E00`, `U+2028`, `U+1F600`, `U+10FFFF` | THREW `ERR_UNESCAPED_CHARACTERS` |
| `0x00`-`0x20` | THREW `ERR_UNESCAPED_CHARACTERS` |

So the rule is a closed **Latin-1** range, not ASCII and not a list of known-bad characters.
`path: "/aĀb"` throws, and the previous regex emitted a request for it.

`/[^\u0021-\u00ff]/u` is the range, and four above-Latin-1 cases plus three inside-Latin-1
controls now pin both ends. 21 cases; reverting the pattern fails the new upper-bound cases.
`src/domain/javascript`: 5400 passing.

* fix(javascript): restrict the spread bailout to the options slot

A reviewer caught that the spread bailout was too wide. Expanding a later argument cannot
change an object Node already picked, so the call still throws:

| call | Node 24.22.1 |
| --- | --- |
| `http.request({path: "/a b"}, ...callbacks)` | THREW `ERR_UNESCAPED_CHARACTERS` |
| `http.request("http://h/", {path: "/a b"}, ...callbacks)` | THREW `ERR_UNESCAPED_CHARACTERS` |
| `http.request(...[{host}], {path: "/a b"})` | THREW `ERR_INVALID_ARG_TYPE` — the spread decides slot 0 |

Only a spread at or before the options slot can move it, so the loop now checks just those
indices. The previous version kept a request for either of the first two calls.

24 cases; reverting the loop to the blanket bailout fails 2 of them.
`src/domain/javascript`: 5407 to 5410 passing.

* fix(javascript): read slot 1 only for a proven url overload

A non-object first argument is the options slot only for Node's `(url, options)` overload.
Measured on Node 24.22.1, `http.request(() => {}, {path: "/a b"})` builds a request to `/`,
because `ClientRequest` reads the function as the callback and replaces options with
defaults — the second object is never read. The previous version read that object and dropped
a real request.

`optionsIndex` now requires a string, a no-substitution template or `new URL` before it looks
at slot 1; anything else is unresolved and keeps the request. Both directions are covered:
`http.request("/x", {path: "/a b"})` and `http.request(new URL("http://h/"), {path: "/a b"})`
still throw, so the URL overload is not weakened.

3 cases added; `src/domain/javascript`: 5410 passing.

* fix(javascript): verify the URL constructor before reading the options slot

A review finding, measured on Node 24.22.1. The `new URL` arm tested the callee by name:

| call | outcome |
| --- | --- |
| `const URL = Function; http.request(new URL(), {path: "/a b"})` | default `/` request — slot 0 is a function, so it is the callback |
| `http.request(new URL("http://h/"), {path: "/a b"})` | THREW `ERR_UNESCAPED_CHARACTERS` |

`isUnmodifiedGlobalReference(callee, state, "URL")` replaces the name test, so a replaced
`URL` no longer proves the `(url, options)` overload. `rejectsHttpPathLiteral` takes the
analysis state for that, which is the same guard the file already uses for `JSON.parse`.

`src/domain/javascript`: 5413 passing.

* fix(javascript): let an earlier getter decide the path

A review finding, measured on Node 24.22.1. `ClientRequest` copies the options with
`Object.assign`, so a getter enumerated before `path` runs first and can rewrite the value that
is then validated:

| call | outcome |
| --- | --- |
| `{get agent() { this.path = "/ok"; return undefined; }, path: "/a b"}` | request constructed |
| `{path: "/a b", get agent() { this.path = "/ok"; }}` | THREW `ERR_UNESCAPED_CHARACTERS` |

`optionGetterPrecedesMember` compares enumeration order rather than source order, because
`Object.assign` does not follow the source: an ECMAScript array index comes first and a redefined
key keeps its first insertion position while its descriptor comes from the last write.

Note for merge order: #9683 carries the same ordering rule for `options.method` on this file. If
that lands first, `methodGetterPrecedesMember` and this helper are the same function and should be
collapsed into one.

`src/domain/javascript`: 5422 passing. Reverting the reader fails 2 of the new cases.

* fix(javascript): walk a statically inert options spread

A review finding, measured on Node 24.22.1. An object-literal spread materializes its own keys as
data properties at its position, so it neither hides the member nor adds a getter:

| call | outcome |
| --- | --- |
| `http.request({...{host: "h"}, path: "/a b"})` | THREW `ERR_UNESCAPED_CHARACTERS` |
| `http.request({...{path: "/a b"}, host: "h"})` | THREW |
| `http.request({...{}, path: "/a b"})` | THREW |
| `http.request({...{get x() {}}, path: "/a b"})` | request constructed — the getter runs |

The order model skipped every spread and bailed out, so the first three kept a request Node never
creates. It now walks an object-literal spread: each entry takes the spread's position, a getter
inside the spread still bails, and a spread this reader cannot expand keeps the request.

The other finding on this PR — an own `__proto__` data key before `path` — does not reproduce.
`Object.assign({}, options)` does run the setter, but `http.request` validates the literal before
that copy:

| call | Node 24.22.1 |
| --- | --- |
| `http.request({["__proto__"]: {set path(_) {}}, path: "/a b"})` | THREW `ERR_UNESCAPED_CHARACTERS`, setter never called |
| `const c = Object.assign({}, {...}); http.request(c)` | OK — the setter consumed the path |

So the existing rejection is correct for the call shape this reader sees, and only a
pre-copied object changes the answer. I have replied on that thread with the reproduction
rather than changing the reader.

`src/domain/javascript`: 5660 passing.

* fix(javascript): give a spread member its own insertion position

A review finding, measured on Node 24.22.1. Every key a spread contributed was recorded at the
spread's outer index, so a key redefined later lost the position it kept at runtime:

`http.request({...{agent: null, path: "/a b"}, get agent() { this.path = "/ok"; return false; }})`
constructs a request, because `agent` takes the spread's position, the redefinition keeps it, and
the getter therefore runs before `path` is copied.

Positions are a running counter now, advanced for each contributed key, so a spread's members keep
their order relative to each other and to the members written after the spread.

`src/domain/javascript`: 5673 passing.

* fix(javascript): keep a getter a later setter does not remove

A review finding, measured on Node 24.22.1. An object literal merges `get x` and `set x` into one
accessor descriptor, so a later `set` entry does not take the getter away:

`http.request({get agent() { this.path = "/ok"; }, path: "/a b", set agent(_) {}})`
constructs a request, because the getter still runs before `path` is copied.

The order model kept only the last node per key, so the `set` entry replaced the `get` and the
getter disappeared from the scan. Getter keys are accumulated separately now, so a paired setter
cannot erase one.

`src/domain/javascript`: 5666 passing.

* fix(javascript): clear a getter fact a data property replaces

A review finding, measured on Node 24.22.1. A key's descriptor is whatever the literal leaves
there, so a later data entry removes the getter that an earlier one installed:

| call | outcome |
| --- | --- |
| `http.request({get agent() { this.path = "/ok"; }, path: "/a b"})` | request constructed |
| `http.request({get agent() { this.path = "/ok"; }, path: "/a b", agent: null})` | THREW `ERR_UNESCAPED_CHARACTERS` |
| `http.request({get agent() { this.path = "/ok"; }, path: "/a b", set agent(_) {}})` | request constructed |

The getter set only grew, so a redefinition left a fact that no longer held and emitted a phantom
request. A data entry clears the key now; a setter does not, because `get x` and `set x` merge into
one accessor descriptor instead of replacing each other.

`src/domain/javascript`: 5667 passing.

* fix(javascript): keep a request when a computed key could hold a getter's position

* fix(javascript): skip a spread's prototype setter so an outer getter's fact survives

* fix(javascript): retain effective option descriptors

* fix(javascript): follow Node request option evaluation

* test(javascript): expect known invalid copied methods

* test(javascript): distinguish global effect activations

---------

Co-authored-by: 吴佳浩 <[email protected]>
Co-authored-by: Vincent Koc <[email protected]>
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.

5 participants