@@ -90,8 +90,10 @@ func resolveGatewayDir(name string) (string, ConfigSource, error) {
9090 return "" , "" , fmt .Errorf ("%w: %q" , ErrGatewayNotFound , name )
9191}
9292
93- // validateGatewayName accepts a single safe path component,
94- // matching the Rust CLI's gateway-name rules.
93+ // validateGatewayName accepts portable, single-component gateway names.
94+ // Host-derived FQDN and IPv4 names may contain dots. Windows device names,
95+ // reserved filename characters, and ambiguous dot components are rejected
96+ // on every platform to keep SDK behavior consistent.
9597func validateGatewayName (name string ) error {
9698 if name == "" {
9799 return fmt .Errorf ("%w: name must not be empty" , ErrInvalidGatewayName )
@@ -105,6 +107,33 @@ func validateGatewayName(name string) error {
105107 if strings .ContainsRune (name , '\x00' ) {
106108 return fmt .Errorf ("%w: name must not contain NUL" , ErrInvalidGatewayName )
107109 }
110+ if strings .HasPrefix (name , "." ) || strings .HasSuffix (name , "." ) || strings .Contains (name , ".." ) {
111+ return fmt .Errorf ("%w: invalid dot placement" , ErrInvalidGatewayName )
112+ }
113+
114+ // This ASCII-only grammar excludes Windows reserved filename characters
115+ // (including colons in raw IPv6 addresses), spaces, and control characters.
116+ for _ , r := range name {
117+ if (r >= 'a' && r <= 'z' ) || (r >= 'A' && r <= 'Z' ) ||
118+ (r >= '0' && r <= '9' ) || r == '-' || r == '_' || r == '.' {
119+ continue
120+ }
121+ return fmt .Errorf ("%w: non-portable character %q" , ErrInvalidGatewayName , r )
122+ }
123+
124+ // Windows treats device names as reserved even with an extension:
125+ // e.g. CON.txt and COM1.example.com refer to device names.
126+ stem , _ , _ := strings .Cut (name , "." )
127+ stem = strings .ToUpper (stem )
128+ switch stem {
129+ case "CON" , "PRN" , "AUX" , "NUL" :
130+ return fmt .Errorf ("%w: reserved Windows device name" , ErrInvalidGatewayName )
131+ }
132+ // Reject COM0/LPT0 conservatively too, for Windows portability.
133+ if len (stem ) == 4 && (strings .HasPrefix (stem , "COM" ) || strings .HasPrefix (stem , "LPT" )) &&
134+ stem [3 ] >= '0' && stem [3 ] <= '9' {
135+ return fmt .Errorf ("%w: reserved Windows device name" , ErrInvalidGatewayName )
136+ }
108137 return nil
109138}
110139
0 commit comments