Skip to content

Commit

Permalink
fix(NET-760): check for private network range
Browse files Browse the repository at this point in the history
  • Loading branch information
Aceix committed Dec 7, 2023
1 parent 530dbdc commit db4dff8
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions controllers/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"net"
"net/http"
"strings"

Expand Down Expand Up @@ -246,6 +247,40 @@ func createNetwork(w http.ResponseWriter, r *http.Request) {
return
}

// validate address ranges: must be private
if network.AddressRange != "" {
ip, _, err := net.ParseCIDR(network.AddressRange)
if err != nil {
logger.Log(0, r.Header.Get("user"), "failed to create network: ",
err.Error())
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))
return
}
if !ip.IsPrivate() {
err := errors.New("address range must be private")
logger.Log(0, r.Header.Get("user"), "failed to create network: ",
err.Error())
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))
return
}
}
if network.AddressRange6 != "" {
ip, _, err := net.ParseCIDR(network.AddressRange6)
if err != nil {
logger.Log(0, r.Header.Get("user"), "failed to create network: ",
err.Error())
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))
return
}
if !ip.IsPrivate() {
err := errors.New("address range must be private")
logger.Log(0, r.Header.Get("user"), "failed to create network: ",
err.Error())
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))
return
}
}

network, err = logic.CreateNetwork(network)
if err != nil {
logger.Log(0, r.Header.Get("user"), "failed to create network: ",
Expand Down

0 comments on commit db4dff8

Please sign in to comment.