Skip to content
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

fix(config): allow empty IP and be strict on ports #240

Merged
merged 2 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions cmd/outline-ss-server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"net"
"reflect"
"strconv"
"strings"

"github.com/go-viper/mapstructure/v2"
Expand Down Expand Up @@ -228,12 +229,26 @@ func (c *Config) validate() error {
}

func validateAddress(addr string) error {
host, _, err := net.SplitHostPort(addr)
host, portStr, err := net.SplitHostPort(addr)
if err != nil {
return err
}
if ip := net.ParseIP(host); ip == nil {
return fmt.Errorf("address must be IP, found: %s", host)
// NOTE: We allow addresses with only the port number set . This will result
// in an address that listens on all available network interfaces (both IPv4
// and IPv6).
if host != "" {
if ip := net.ParseIP(host); ip == nil {
return fmt.Errorf("address must be IP, found: %s", host)
}
}
if portStr != "" {
port, err := strconv.Atoi(portStr)
if err != nil {
return fmt.Errorf("invalid port: %s", portStr)
}
if port < 0 || port > 65535 {
return fmt.Errorf("port out of range: %d", port)
}
}
return nil
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/outline-ss-server/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ services:
- listeners:
- type: tcp
address: "[::]:9000"
- type: udp
address: ":9000"
- type: websocket-stream
web_server: my_web_server
path: "/tcp"
Expand Down