Make safe HTTP client options composable - #68
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR makes “safe HTTP” configuration composable across the codebase by moving per-host private-network allowlisting into safehttp.Options, having fetch use the shared host-aware gate logic, and re-exporting client option helpers at the registries package root.
Changes:
- Add
AllowPrivateHosts []stringandCheckHostIPtosafehttpto allow private-network IPs only for explicitly allowlisted hosts. - Update
fetch.WithAllowPrivateHoststo populatesafehttp.Optionsand gate resolved IPs viasafehttp.CheckHostIP. - Re-export
WithSafeHTTP,WithHTTPClient, andWithTransportfromregistriesroot and add coverage for these root options.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| safehttp/safehttp.go | Adds per-host private allowlist support, host-aware IP checks, and host normalization. |
| safehttp/safehttp_test.go | Adds tests covering allowlisted private hosts behavior and redirect refusal to unlisted private targets. |
| fetch/fetcher.go | Switches fetcher gating to safehttp.CheckHostIP and stores allowlist in safehttp.Options. |
| fetch/fetcher_test.go | Updates tests to reflect AllowPrivateHosts storage/composition behavior. |
| registries.go | Re-exports WithSafeHTTP, WithHTTPClient, and WithTransport at the package root. |
| registries_test.go | Adds regression tests ensuring root-level option re-exports behave as expected. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Add per-host private-address allowlists to
safehttp.Optionsand use the shared host-aware gate fromfetch. Re-exportWithSafeHTTP,WithHTTPClient, andWithTransportfrom the root package.Closes #28
Closes #67