diff --git a/core/plugin.go b/core/plugin.go index e317bbb6d..ea8c53f83 100644 --- a/core/plugin.go +++ b/core/plugin.go @@ -54,6 +54,18 @@ func ToPluginType(name string) (PluginType, error) { return t, nil } +func CheckPluginType(id PluginType) bool { + pts := map[PluginType]string{ + 0: "collector", + 1: "processor", + 2: "publisher", + } + + _, ok := pts[id] + + return ok +} + func (pt PluginType) String() string { return []string{ "collector", diff --git a/mgmt/rest/v1/config.go b/mgmt/rest/v1/config.go index 23215b658..8ee1d8aa2 100644 --- a/mgmt/rest/v1/config.go +++ b/mgmt/rest/v1/config.go @@ -20,6 +20,7 @@ limitations under the License. package v1 import ( + "fmt" "net/http" "strconv" @@ -148,6 +149,9 @@ func (s *apiV1) setPluginConfigItem(w http.ResponseWriter, r *http.Request, p ht func getPluginType(t string) (core.PluginType, error) { if ityp, err := strconv.Atoi(t); err == nil { + if !core.CheckPluginType(core.PluginType(ityp)) { + return core.PluginType(-1), fmt.Errorf("invalid plugin type id given %d", ityp) + } return core.PluginType(ityp), nil } ityp, err := core.ToPluginType(t)