From 41a722bdbf46c33057a39386d6d520de3883bf97 Mon Sep 17 00:00:00 2001 From: fuzd Date: Wed, 28 Feb 2024 15:57:48 +0800 Subject: [PATCH] Add header validation to prevent service panic. --- types/services/routine.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/types/services/routine.go b/types/services/routine.go index 966c5999..c3c0e774 100644 --- a/types/services/routine.go +++ b/types/services/routine.go @@ -335,6 +335,9 @@ func CheckSmtp(s *Service, record bool) (*Service, error) { // check if 'Content-Type' header was defined for _, header := range headers { + if len(strings.Split(header, "=")) < 2 { + continue + } switch strings.ToLower(strings.Split(header, "=")[0]) { case "username": username = strings.Split(header, "=")[1] @@ -447,6 +450,9 @@ func CheckImap(s *Service, record bool) (*Service, error) { // check if 'Content-Type' header was defined for _, header := range headers { + if len(strings.Split(header, "=")) < 2 { + continue + } switch strings.ToLower(strings.Split(header, "=")[0]) { case "username": username = strings.Split(header, "=")[1] @@ -547,6 +553,9 @@ func CheckHttp(s *Service, record bool) (*Service, error) { // check if 'Content-Type' header was defined for _, header := range headers { + if len(strings.Split(header, "=")) < 2 { + continue + } if strings.Split(header, "=")[0] == "Content-Type" { contentType = strings.Split(header, "=")[1] break