diff --git a/traffic_ops/traffic_ops_golang/physlocation/phys_locations.go b/traffic_ops/traffic_ops_golang/physlocation/phys_locations.go index b24149fb03..db5e744aef 100644 --- a/traffic_ops/traffic_ops_golang/physlocation/phys_locations.go +++ b/traffic_ops/traffic_ops_golang/physlocation/phys_locations.go @@ -390,6 +390,22 @@ func UpdatePhysLocation(w http.ResponseWriter, r *http.Request) { return } + // checks to see if the supplied region name and ID in the phys_location body correspond to each other. + if physLocation.RegionName != "" { + regionName, ok, err := dbhelpers.GetRegionNameFromID(tx, physLocation.RegionID) + if err != nil { + api.HandleErr(w, r, tx, http.StatusInternalServerError, fmt.Errorf("error fetching name from region ID: %w", err), nil) + return + } else if !ok { + api.HandleErr(w, r, tx, http.StatusNotFound, errors.New("no such region"), nil) + return + } + if regionName != physLocation.RegionName { + api.HandleErr(w, r, tx, http.StatusBadRequest, errors.New("region name and ID do not match"), nil) + return + } + } + requestedID := inf.Params["id"] intRequestId, convErr := strconv.Atoi(requestedID)