Type Safe Fetch#1
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a new package-level fetch wrapper intended to provide SSRF-safe URL validation and optional runtime JSON response validation using TypeBox, and wires it into the public exports along with required dependency updates.
Changes:
- Added
lib/fetch.tsimplementing an SSRF-checkingfetchwrapper plusTypedResponse.typed()for TypeBox runtime validation. - Exported the new
fetchwrapper and types fromindex.ts. - Updated dependencies and changelog to reflect the new feature.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| package.json | Adds new runtime dependencies needed for type-safe fetching and validation. |
| package-lock.json | Locks new dependency tree for the added fetch/validation/error packages. |
| lib/fetch.ts | Implements SSRF validation + typed JSON parsing/validation around undici fetch. |
| index.ts | Exposes the new fetch wrapper and types from the package entry point. |
| CHANGELOG.md | Documents the new feature under a new version heading. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
1
to
+3
| export { isSafeUrl, isPrivateIPv4, isPrivateIPv6 } from './lib/safeurl.js'; | ||
| export { default as fetch, TypedResponse } from './lib/fetch.js'; | ||
| export type { FetchInit } from './lib/fetch.js'; |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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
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.
This pull request introduces a new type-safe, SSRF-protected fetch wrapper to the codebase, enhancing security and developer experience when making HTTP requests. The wrapper ensures URLs are validated before making requests and allows for runtime response validation using TypeBox schemas. It also updates the exports and dependencies to support this feature.
New fetch wrapper and type-safe HTTP requests:
fetchimplementation inlib/fetch.tsthat validates URLs for SSRF safety by default and allows disabling this check via thesafeUrloption. The wrapper usesundicifor HTTP requests and provides aTypedResponseclass for runtime JSON validation using TypeBox schemas.fetch,TypedResponse, andFetchInittypes from the package entry point inindex.ts.Dependency updates:
@openaddresses/batch-errorfor error handling,@sinclair/typeboxfor schema validation, andundicifor HTTP requests inpackage.json.Documentation: