Skip to content

Commit

Permalink
added basic local connection option (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
mosajjal authored Oct 11, 2023
1 parent eecf94a commit 03505d9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions config.defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ general:
public_ipv4:
# Public IPv6 of the server, reply address of DNS AAAA queries
public_ipv6:
# allow connections from sniproxy to RFC1918 addresses. default is false.
allow_conn_to_local: false
# log level for the application. choices: debug, info, warn, error
# by default, the logs are colored so they are not suited for logging to a file.
# in order to disable colors, set NO_COLOR=true in the environment variables
Expand Down
2 changes: 1 addition & 1 deletion https.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func handle443(conn net.Conn, httpslog zerolog.Logger) error {
return err
}
// TODO: handle timeout and context here
if rAddr.IsLoopback() || rAddr.IsPrivate() || rAddr.Equal(net.IPv4(0, 0, 0, 0)) || rAddr.Equal(net.IP(c.PublicIPv4)) || rAddr.Equal(net.IP(c.sourceAddr)) || rAddr.Equal(net.IP(c.PublicIPv6)) {
if rAddr.IsLoopback() || (rAddr.IsPrivate() && !c.AllowConnToLocal) || rAddr.Equal(net.IPv4(0, 0, 0, 0)) || rAddr.Equal(net.IP(c.PublicIPv4)) || rAddr.Equal(net.IP(c.sourceAddr)) || rAddr.Equal(net.IP(c.PublicIPv6)) {
httpslog.Info().Msg("connection to private IP or self ignored")
return nil
}
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type runConfig struct {
BindHTTPS string `yaml:"bind_https"`
Interface string `yaml:"interface"`
BindPrometheus string `yaml:"bind_prometheus"`
AllowConnToLocal bool `yaml:"allow_conn_to_local"`

acl []acl.ACL

Expand Down Expand Up @@ -301,6 +302,7 @@ func main() {
c.PublicIPv6, _ = getPublicIPv6()
}
c.BindPrometheus = generalConfig.String("prometheus")
c.AllowConnToLocal = generalConfig.Bool("allow_conn_to_local")

var err error
c.acl, err = acl.StartACLs(&logger, k)
Expand Down

0 comments on commit 03505d9

Please sign in to comment.