-
Notifications
You must be signed in to change notification settings - Fork 2
Only forward traffic to global unicast #660
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
Conversation
There was a problem hiding this 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 refactors the BlockLocal filter to use Go's native IP address methods instead of the external iptool library, simplifying the codebase and reducing dependencies. The change replaces custom IP privacy detection logic with the standard library's IsGlobalUnicast() method.
Key changes:
- Removed direct dependency on
github.com/getlantern/iptool - Replaced
ipt.IsPrivate(ipAddr)with!ipAddr.IP.IsGlobalUnicast()for detecting local/private addresses - Updated several indirect dependency versions in
go.mod
Reviewed Changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| proxyfilters/blocklocal.go | Removed iptool import and replaced IsPrivate() call with native IsGlobalUnicast() method |
| go.mod | Moved iptool from direct to indirect dependencies and updated version hashes for related packages |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
proxyfilters/blocklocal.go
Outdated
| // in the form host or host:port | ||
| if err == nil { | ||
| if ipt.IsPrivate(ipAddr) { | ||
| if !ipAddr.IP.IsGlobalUnicast() { |
Copilot
AI
Oct 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using !IsGlobalUnicast() is not semantically equivalent to IsPrivate(). IsGlobalUnicast() returns false for unspecified addresses (0.0.0.0), loopback addresses, multicast addresses, and link-local addresses, but it also returns false for IPv4 broadcast addresses and other special-purpose addresses that may not be considered 'private' in the traditional RFC 1918 sense. This could inadvertently block legitimate traffic or allow traffic that should be blocked. Consider using IsPrivate() || IsLoopback() || IsLinkLocalUnicast() || IsLinkLocalMulticast() for more precise control.
| if !ipAddr.IP.IsGlobalUnicast() { | |
| if ipAddr.IP.IsPrivate() || ipAddr.IP.IsLoopback() || ipAddr.IP.IsLinkLocalUnicast() || ipAddr.IP.IsLinkLocalMulticast() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we want to allow broadcast addresses either, or multicast. Seems like a potential for amplification attacks.
|
I think we need |
|
Oh very interesting. I didn't realize that some private addresses could also be considered global unicast -- I guess I always thought of the "global" part as public! Good catch. |
This pull request refactors how local/private IP addresses are detected in the
BlockLocalfilter, simplifying the code and removing an external dependency. The main change is the replacement of the customiptoollibrary with Go's built-in IP address methods, resulting in cleaner and more maintainable code.Dependency management:
github.com/getlantern/iptoolas a direct dependency from therequireblock ingo.mod.github.com/getlantern/netxas a direct dependencyCode simplification and refactoring:
iptoolfromproxyfilters/blocklocal.go, as it is no longer needed.iptoolobject in theBlockLocalfunction.ipt.IsPrivate(ipAddr)with Go's native!ipAddr.IP.IsGlobalUnicast()to check for non-global (local/private) IP addresses, simplifying the logic and leveraging standard library functionality.