mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-24 17:47:46 +01:00
fix[logger]:update log ID validation logic (#11351)
Signed-off-by: Steven Zou <szou@vmware.com>
This commit is contained in:
parent
fc7a601142
commit
f2beed577f
@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/goharbor/harbor/src/jobservice/errs"
|
||||
|
||||
@ -24,12 +25,8 @@ func NewFileGetter(baseDir string) *FileGetter {
|
||||
|
||||
// Retrieve implements @Interface.Retrieve
|
||||
func (fg *FileGetter) Retrieve(logID string) ([]byte, error) {
|
||||
if len(logID) != 24 {
|
||||
return nil, errors.New("invalid length of log identify")
|
||||
}
|
||||
|
||||
if _, err := hex.DecodeString(logID); err != nil {
|
||||
return nil, errors.New("invalid log identify")
|
||||
if err := isValidLogID(logID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fPath := path.Join(fg.baseDir, fmt.Sprintf("%s.log", logID))
|
||||
@ -40,3 +37,21 @@ func (fg *FileGetter) Retrieve(logID string) ([]byte, error) {
|
||||
|
||||
return ioutil.ReadFile(fPath)
|
||||
}
|
||||
|
||||
func isValidLogID(id string) error {
|
||||
lid := id
|
||||
segment := strings.LastIndex(lid, "@")
|
||||
if segment != -1 {
|
||||
lid = lid[:segment]
|
||||
}
|
||||
|
||||
if len(lid) != 24 {
|
||||
return errors.New("invalid length of log identify")
|
||||
}
|
||||
|
||||
if _, err := hex.DecodeString(lid); err != nil {
|
||||
return errors.New("invalid log identify")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user