Skip to content

feat: add zod validation to internal and external endpoints#612

Open
ECWireless wants to merge 6 commits intomainfrom
feat/add-zod-validation-to-internal-and-external-endpoints
Open

feat: add zod validation to internal and external endpoints#612
ECWireless wants to merge 6 commits intomainfrom
feat/add-zod-validation-to-internal-and-external-endpoints

Conversation

@ECWireless
Copy link
Copy Markdown
Collaborator

See #521 for all details. Original PR created by @Roaring30s .

ECWireless and others added 3 commits March 30, 2026 17:31
… (#521)

* feat: add account-balance zod validation

* feat: add ens name validation

* feat: add score and pending stake validation

* feat: add ens-data image validation

* feat: add ens-data index validation

* feat: add pipelines validation

* feat: add regions validation

* feat: add treasury proposal state validation

* feat: add proposal vote by address validation

* feat: add treasury votes validation

* feat: add score validation

* feat: add changefeed validation

* feat: add contract validation

* feat: add current-round validation

* feat: add generateProof validation

* feat: add totalTokenSupply validation

* feat: add upload ipfs validation

* refactor: refactor usage validation

* feat: add external validation for ens image

* refactor: refactor ens schema

* feat: add external checks for score endpoint

* fix: add guard for projectBySlugs

* refactor: refactor schemas

* feat: add defense checks to usage endpoint

* feat: add getEnsForAddress validation

---------

Co-authored-by: ECWireless <40322776+ECWireless@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 31, 2026 02:30
@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Mar 31, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
explorer-arbitrum-one Ready Ready Preview, Comment Mar 31, 2026 1:18pm

Request Review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces centralized Zod schemas and validation helpers, then applies them across multiple Next.js API routes to harden user-input handling and upstream-response parsing.

Changes:

  • Added reusable Zod schema modules under lib/api/schemas/* plus shared validation helpers in lib/api/errors.ts.
  • Updated a broad set of API routes to validate request inputs, external API responses, and/or endpoint outputs before returning JSON.
  • Added a new /api/totalTokenSupply endpoint backed by a subgraph query with response validation.

Reviewed changes

Copilot reviewed 37 out of 38 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
pages/api/usage.tsx Uses centralized usage schemas and validates output; adds guardrails for insufficient data.
pages/api/upload-ipfs.tsx Validates POST body and Pinata response; validates output shape.
pages/api/treasury/votes/[address]/registered.tsx Validates address input and response output for registered-to-vote.
pages/api/treasury/votes/[address]/index.tsx Validates address input and voting power output.
pages/api/treasury/proposal/[proposalId]/votes/[address].tsx Validates proposalId/address inputs and voting-power output.
pages/api/treasury/proposal/[proposalId]/state.tsx Validates proposalId input and proposal-state output.
pages/api/totalTokenSupply.tsx New endpoint querying subgraph totalSupply with schema validation.
pages/api/score/index.tsx Validates query params and upstream responses; adds output validation.
pages/api/score/[address].tsx Validates address input, upstream responses, and performance-metrics output.
pages/api/regions/index.ts Validates upstream regions payloads and validates merged output.
pages/api/pipelines/index.tsx Validates region query param and upstream pipelines payload.
pages/api/pending-stake/[address].tsx Validates address input and pending-stake output.
pages/api/l1-delegator/[address].tsx Validates address input and L1 delegator output.
pages/api/generateProof.tsx Validates POST body and proof output.
pages/api/ens-data/index.tsx Validates subgraph response + addresses and validates ENS identities output.
pages/api/ens-data/image/[name].tsx Validates ENS name and avatar result; adds URL validation before fetch.
pages/api/ens-data/[address].tsx Validates address input (including blacklist) and ENS identity output.
pages/api/current-round.tsx Validates subgraph result and current-round output.
pages/api/contracts.tsx Validates contracts-info output shape.
pages/api/changefeed.tsx Validates GraphQL envelope and changefeed response output.
pages/api/account-balance/[address].tsx Validates address input and account-balance output.
lib/api/schemas/usage.ts New Zod schemas for /api/usage input/output structures.
lib/api/schemas/upload-ipfs.ts New Zod schemas for IPFS upload input + Pinata response + output.
lib/api/schemas/treasury.ts New Zod schemas for treasury proposal/voting responses.
lib/api/schemas/total-token-supply.ts New Zod schemas for total supply subgraph response and output.
lib/api/schemas/subgraph.ts New Zod schemas for common subgraph envelopes and specific queries.
lib/api/schemas/staking.ts New Zod schemas for staking-related endpoint outputs.
lib/api/schemas/performance.ts New Zod schemas for metrics/score-related endpoints.
lib/api/schemas/index.ts Central barrel export for the new schema modules.
lib/api/schemas/generate-proof.ts New Zod schemas for generateProof input/output.
lib/api/schemas/ens.ts New Zod schemas for ENS identity/name/address and provider responses.
lib/api/schemas/current-round.ts New Zod schema for current-round endpoint output.
lib/api/schemas/contracts.ts New Zod schema for contracts endpoint output.
lib/api/schemas/common.ts New shared primitives (Address, URL, handles, regions, etc.).
lib/api/schemas/changefeed.ts New Zod schemas for changefeed GraphQL/envelope response validation.
lib/api/errors.ts Adds validateInput, validateOutput, validateExternalResponse helpers.
lib/api/ens.ts Validates ENS resolver/provider results with graceful fallbacks.
.gitignore Ignores *.tsbuildinfo.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

3 participants