Skip to content

[Nexus] Fix: Reject partially numeric network IDs#8830

Open
royalpinto007 wants to merge 1 commit into
thirdweb-dev:mainfrom
royalpinto007:nexus/strict-network-id
Open

[Nexus] Fix: Reject partially numeric network IDs#8830
royalpinto007 wants to merge 1 commit into
thirdweb-dev:mainfrom
royalpinto007:nexus/strict-network-id

Conversation

@royalpinto007

@royalpinto007 royalpinto007 commented Jul 6, 2026

Copy link
Copy Markdown

Notes for the reviewer

Fixes #8829.

networkToChainId previously used loose numeric parsing, so malformed values like eip155:1abc, eip155:1.5, and 1abc could be accepted as chain ID 1. This PR adds strict chain ID parsing for CAIP-style and plain numeric network IDs before falling back to named networks.

I also added a package-local Vitest script for @thirdweb-dev/nexus so this parser behavior can be covered directly.

How to test

  • pnpm --filter @thirdweb-dev/nexus test
  • pnpm --filter @thirdweb-dev/nexus build
  • pnpm --filter @thirdweb-dev/nexus lint

Note: lint passes and reports one existing warning in packages/nexus/src/encode.ts about let safe being assignable as const; I did not touch that unrelated file.


PR-Codex overview

This PR focuses on enhancing the networkToChainId function in the nexus package to reject partially numeric network IDs, ensuring stricter validation for network identifiers.

Detailed summary

  • Updated networkToChainId to reject partially numeric network IDs.
  • Introduced a new function parseChainId for improved validation.
  • Added test cases for valid and invalid network identifiers in schemas.test.ts.
  • Added vitest as a testing dependency in package.json.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • Bug Fixes
    • Tightened network ID parsing so partially numeric values are now rejected.
    • Improved validation for chain IDs to only accept safe whole numbers, reducing invalid network handling.
  • Tests
    • Added automated coverage for valid network ID parsing and rejection of invalid inputs.
  • Chores
    • Added a test command and test tooling support for the package.

@vercel

vercel Bot commented Jul 6, 2026

Copy link
Copy Markdown

@royalpinto007 is attempting to deploy a commit to the thirdweb Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot

changeset-bot Bot commented Jul 6, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a1a3943

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@thirdweb-dev/nexus Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: aeac2422-e488-4bdd-b64d-a8507a76d6d5

📥 Commits

Reviewing files that changed from the base of the PR and between 8c521aa and a1a3943.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (4)
  • .changeset/nexus-strict-network-id.md
  • packages/nexus/package.json
  • packages/nexus/src/schemas.test.ts
  • packages/nexus/src/schemas.ts

Walkthrough

Adds a strict parseChainId helper in the Nexus package's schemas.ts, replacing loose parseInt-based parsing in networkToChainId to reject partially numeric or unsafe integer network IDs. Includes new Vitest tests, a vitest devDependency and test script, and a changeset entry.

Changes

Strict Network ID Parsing

Layer / File(s) Summary
Strict chain ID parsing
packages/nexus/src/schemas.ts
Adds parseChainId helper using a regex (^[1-9]\d*$) and Number.isSafeInteger check; networkToChainId now uses it for both eip155: and plain-integer parsing, throwing Invalid network: ${network} on invalid input.
Test coverage and tooling
packages/nexus/src/schemas.test.ts, packages/nexus/package.json, .changeset/nexus-strict-network-id.md
Adds Vitest tests for valid, partially numeric, and unsafe integer network IDs; adds vitest devDependency and test script; adds changeset patch note.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant networkToChainId
  participant parseChainId

  Caller->>networkToChainId: network string
  networkToChainId->>parseChainId: parse numeric portion
  parseChainId-->>networkToChainId: number or undefined
  alt invalid or partially numeric
    networkToChainId-->>Caller: throw Invalid network error
  else valid safe integer
    networkToChainId-->>Caller: return chain id
  end
Loading

Related Issues: #8829

Suggested labels: patch, nexus

Suggested reviewers: none identified

🎭 A digit that limps mid-string,

No longer slips past the ring—

Strict regex stands guard,

Safe integers, hard,

Only true numbers take wing.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: stricter rejection of partially numeric network IDs in Nexus.
Description check ✅ Passed The description includes reviewer notes and test steps, covering the template’s required sections well enough.
Linked Issues check ✅ Passed The code and tests implement the linked issue’s strict parsing requirement and reject malformed numeric network IDs.
Out of Scope Changes check ✅ Passed The added Vitest dependency, test script, and changeset are directly tied to testing and releasing the fix.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Nexus] networkToChainId accepts partially numeric network IDs

1 participant