-
Notifications
You must be signed in to change notification settings - Fork 17
Fix: Add Zod Validation to Internal and External Endpoints (Issue #434) #521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Roaring30s
wants to merge
27
commits into
livepeer:main
Choose a base branch
from
Roaring30s:zod-validation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
@Roaring30s is attempting to deploy a commit to the Livepeer Foundation Team on Vercel. A member of the Team first needs to authorize it. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add Comprehensive Zod Validation to API Endpoints
Fixes #434
Summary
This PR implements comprehensive Zod validation across all API endpoints mentioned in the original issue, covering input validation, output validation, and external API response validation. Additionally, several instances of unsafe destructuring have been fixed to prevent runtime crashes.
Changes
Validation Coverage
safeParse()and explicit checksSchema Organization
Endpoints Validated
Fully Tested ✅
/api/account-balance/[address]/api/ens-data/[address]/api/ens-data(bulk lookup)/api/ens-data/image/[name]/api/l1-delegator/[address]/api/pending-stake/[address]/api/pipelines/api/regions/api/treasury/*(4 endpoints)/api/contracts/api/current-round/api/generateProof(via Postman)/api/totalTokenSupply/api/upload-ipfs(via Postman, added 500KB limit)Validated but Not Fully Tested⚠️
/api/score- Missing environment variables/api/score/[address]- Missing environment variables/api/changefeed- Missing environment variables/api/usage- Missing environment variablesKey Improvements
/api/usageto prevent crashes with insufficient dataWebUrlSchema,TwitterHandleSchema, andGithubHandleSchemafor social links/api/upload-ipfsto prevent payload abuseThe following endpoints could not be fully tested due to missing environment variables:
/api/score/api/score/[address]/api/changefeed/api/usageThe validation logic has been implemented and follows the same patterns as tested endpoints, but happy path testing is recommended once environment variables are available.
Manual Testing URLs
For quick manual testing, use the following endpoints:
http://localhost:3000/api/account-balance/0x13364c017b282fb033107b3c0ccbf762332aceba
http://localhost:3000/api/ens-data/0x13364c017b282fb033107b3c0ccbf762332aceba
http://localhost:3000/api/ens-data
http://localhost:3000/api/ens-data/image/day-dreamer.eth
http://localhost:3000/api/l1-delegator/0x13364c017b282fb033107b3c0ccbf762332aceba
http://localhost:3000/api/pending-stake/0x13364c017b282fb033107b3c0ccbf762332aceba
http://localhost:3000/api/pipelines
http://localhost:3000/api/regions
http://localhost:3000/api/treasury/proposal/47675980806842999962173227987422002121354040219792725319563843023665050472833/state
http://localhost:3000/api/treasury/proposal/47675980806842999962173227987422002121354040219792725319563843023665050472833/votes/0x13364c017b282fb033107b3c0ccbf762332aceba
http://localhost:3000/api/treasury/votes/0x6cb1ce2516fb7d211038420a8cf9a843c7bd3b08
http://localhost:3000/api/treasury/votes/0x6cb1ce2516fb7d211038420a8cf9a843c7bd3b08/registered
http://localhost:3000/api/contracts
http://localhost:3000/api/current-round
http://localhost:3000/api/totalTokenSupply
Postman-only endpoints:
/api/generateProof(POST with account, delegate, stake, fees)/api/upload-ipfs(POST with poll proposal shape)Breaking Changes
None. All validation uses graceful fallbacks where appropriate.