瀏覽代碼

Improve create alerts input (#493)

* check decisions start_ip & end_ip fields
erenJag 4 年之前
父節點
當前提交
71325d9134
共有 1 個文件被更改,包括 6 次插入0 次删除
  1. 6 0
      pkg/apiserver/controllers/v1/alerts.go

+ 6 - 0
pkg/apiserver/controllers/v1/alerts.go

@@ -121,6 +121,12 @@ func (c *Controller) CreateAlert(gctx *gin.Context) {
 	for _, alert := range input {
 		if len(alert.Decisions) > 0 {
 			log.Debugf("alert %s already has decisions, don't apply profiles", *alert.Message)
+			for _, decision := range alert.Decisions {
+				if decision.EndIP != 0 && decision.StartIP != 0 && decision.EndIP < decision.StartIP {
+					gctx.JSON(http.StatusBadRequest, gin.H{"message": "'start_ip' must be lower than or equal to 'end_ip' in decisions"})
+					return
+				}
+			}
 		} else {
 			decisions, err := csprofiles.EvaluateProfiles(c.Profiles, alert)
 			if err != nil {