Skip to content

Commit 6ab43e7

Browse files
exaVPatrick Del Conte
authored andcommitted
allow restriction of destination ip address
ALLOWED_DEST_FQDN can also match IP if FQDN is not defined
1 parent d034754 commit 6ab43e7

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Simple socks5 server using go-socks5 with authentication, allowed ips list and d
2424
|PROXY_USER|String|EMPTY|Set proxy user (also required existed PROXY_PASS)|
2525
|PROXY_PASSWORD|String|EMPTY|Set proxy password for auth, used with PROXY_USER|
2626
|PROXY_PORT|String|1080|Set listen port for application inside docker container|
27-
|ALLOWED_DEST_FQDN|String|EMPTY|Allowed destination address regular expression pattern. Default allows all.|
27+
|ALLOWED_DEST_FQDN|String|EMPTY|Allowed destination address regular expression pattern. Default allows all. Examples "(192.168.0.1|go.dev)"|
2828
|ALLOWED_IPS|String|Empty|Set allowed IP's that can connect to proxy, separator `,`|
2929

3030

ruleset.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ type PermitDestAddrPatternRuleSet struct {
1919
}
2020

2121
func (p *PermitDestAddrPatternRuleSet) Allow(ctx context.Context, req *socks5.Request) (context.Context, bool) {
22-
match, _ := regexp.MatchString(p.AllowedFqdnPattern, req.DestAddr.FQDN)
23-
return ctx, match
22+
var match bool
23+
if req.DestAddr.FQDN != nil {
24+
match, _ = regexp.MatchString(p.AllowedFqdnPattern, *req.DestAddr.FQDN)
25+
} else if req.DestAddr.IP != nil {
26+
match, _ = regexp.MatchString(p.AllowedFqdnPattern, *req.DestAddr.IP)
27+
} else {
28+
match = true
29+
}
30+
return ctx, match
2431
}

0 commit comments

Comments
 (0)