fix: require explicit public network binds#7
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens the Node adapter’s network exposure defaults by ensuring both listen() and serve() bind to loopback (127.0.0.1) unless the caller explicitly opts into a public bind via allowPublicBind: true, aligning with Issue #6’s security requirement.
Changes:
- Introduces
resolveBindHost()to centralize loopback-default binding and public-bind opt-in enforcement. - Updates
listen()andserve()to use the resolved host for both binding and Host allowlisting. - Adds test coverage and documentation describing the new default and opt-in behavior.
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 |
|---|---|
| tests/node.test.ts | Adds a regression test asserting loopback-default binding and requiring explicit public-bind opt-in. |
| src/serve.ts | Uses resolveBindHost() for consistent binding/allowedHosts behavior in serve(). |
| src/listen.ts | Uses resolveBindHost() for consistent binding/allowedHosts behavior in listen(). |
| src/contracts.ts | Adds allowPublicBind?: boolean to the public options contract (via ListenOptions). |
| src/bind.ts | Adds shared host resolution + opt-in enforcement helper. |
| README.md | Documents loopback-default binding and the allowPublicBind opt-in requirement. |
Comments suppressed due to low confidence (1)
tests/node.test.ts:37
- Same pattern as above: combining the type check and value assertion can turn a non-TCP address into
false === "0.0.0.0", which is harder to debug than an explicit guard.
const publicAddress = publicServer.address();
expect(typeof publicAddress === "object" && publicAddress?.address).toBe("0.0.0.0");
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Closes #6. Defaults both server entrypoints to 127.0.0.1, rejects implicit public hosts, and documents the allowPublicBind opt-in.