diff --git a/proxy/proxy.go b/proxy/proxy.go index c68c0099..83c4ce10 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -20,6 +20,7 @@ import ( "github.com/weaveworks/weave/common" weavedocker "github.com/weaveworks/weave/common/docker" weavenet "github.com/weaveworks/weave/net" + "github.com/weaveworks/weave/net/address" ) const ( @@ -505,6 +506,10 @@ func (proxy *Proxy) attach(containerID string) error { return nil } Log.Infof("Attaching container %s with WEAVE_CIDR \"%s\" to weave network", container.ID, strings.Join(cidrs, " ")) + if err := validateCIDRs(cidrs); err != nil { + return err + } + args := []string{"attach"} args = append(args, cidrs...) if !proxy.NoRewriteHosts { @@ -533,6 +538,23 @@ func callWeaveAttach(container *docker.Container, args []string) error { return nil } +func validateCIDRs(cidrs []string) error { + for _, cidr := range cidrs { + if cidr == "net:default" { + continue + } + for _, prefix := range []string{"ip:", "net:", ""} { + if strings.HasPrefix(cidr, prefix) { + if _, err := address.ParseCIDR(strings.TrimPrefix(cidr, prefix)); err == nil { + break + } + return fmt.Errorf("invalid WEAVE_CIDR: %s", cidr) + } + } + } + return nil +} + func (proxy *Proxy) weaveCIDRs(networkMode string, env []string) ([]string, error) { if networkMode == "host" || strings.HasPrefix(networkMode, "container:") || // Anything else, other than blank/none/default/bridge, is some sort of network plugin