mirror of
https://github.com/goharbor/harbor.git
synced 2025-02-28 09:42:05 +01:00
fix: handle codeql golang security issues
Signed-off-by: chlins <chenyuzh@vmware.com>
This commit is contained in:
parent
bc6a7f65a6
commit
9e8218f63b
@ -107,13 +107,13 @@ func (p *pgsql) Register(alias ...string) error {
|
|||||||
|
|
||||||
// UpgradeSchema calls migrate tool to upgrade schema to the latest based on the SQL scripts.
|
// UpgradeSchema calls migrate tool to upgrade schema to the latest based on the SQL scripts.
|
||||||
func (p *pgsql) UpgradeSchema() error {
|
func (p *pgsql) UpgradeSchema() error {
|
||||||
port, err := strconv.ParseInt(p.port, 10, 64)
|
port, err := strconv.Atoi(p.port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
m, err := NewMigrator(&models.PostGreSQL{
|
m, err := NewMigrator(&models.PostGreSQL{
|
||||||
Host: p.host,
|
Host: p.host,
|
||||||
Port: int(port),
|
Port: port,
|
||||||
Username: p.usr,
|
Username: p.usr,
|
||||||
Password: p.pwd,
|
Password: p.pwd,
|
||||||
Database: p.database,
|
Database: p.database,
|
||||||
|
@ -59,7 +59,14 @@ func ReversibleEncrypt(str, key string) (string, error) {
|
|||||||
if block, err = aes.NewCipher(keyBytes); err != nil {
|
if block, err = aes.NewCipher(keyBytes); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
cipherText := make([]byte, aes.BlockSize+len(str))
|
|
||||||
|
// ensures the value is no larger than 64 MB, which fits comfortably within an int and avoids the overflow
|
||||||
|
if len(str) > 64*1024*1024 {
|
||||||
|
return "", errors.New("str value too large")
|
||||||
|
}
|
||||||
|
|
||||||
|
size := aes.BlockSize + len(str)
|
||||||
|
cipherText := make([]byte, size)
|
||||||
iv := cipherText[:aes.BlockSize]
|
iv := cipherText[:aes.BlockSize]
|
||||||
if _, err = io.ReadFull(rand.Reader, iv); err != nil {
|
if _, err = io.ReadFull(rand.Reader, iv); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -163,12 +163,9 @@ func ParseProjectIDOrName(value interface{}) (int64, string, error) {
|
|||||||
|
|
||||||
var id int64
|
var id int64
|
||||||
var name string
|
var name string
|
||||||
switch value.(type) {
|
switch v := value.(type) {
|
||||||
case int:
|
case int, int64:
|
||||||
i := value.(int)
|
id = reflect.ValueOf(v).Int()
|
||||||
id = int64(i)
|
|
||||||
case int64:
|
|
||||||
id = value.(int64)
|
|
||||||
case string:
|
case string:
|
||||||
name = value.(string)
|
name = value.(string)
|
||||||
default:
|
default:
|
||||||
|
@ -3,6 +3,9 @@ package robot
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
rbac_project "github.com/goharbor/harbor/src/common/rbac/project"
|
rbac_project "github.com/goharbor/harbor/src/common/rbac/project"
|
||||||
"github.com/goharbor/harbor/src/common/utils"
|
"github.com/goharbor/harbor/src/common/utils"
|
||||||
"github.com/goharbor/harbor/src/lib/config"
|
"github.com/goharbor/harbor/src/lib/config"
|
||||||
@ -15,7 +18,6 @@ import (
|
|||||||
rbac_model "github.com/goharbor/harbor/src/pkg/rbac/model"
|
rbac_model "github.com/goharbor/harbor/src/pkg/rbac/model"
|
||||||
robot "github.com/goharbor/harbor/src/pkg/robot"
|
robot "github.com/goharbor/harbor/src/pkg/robot"
|
||||||
"github.com/goharbor/harbor/src/pkg/robot/model"
|
"github.com/goharbor/harbor/src/pkg/robot/model"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -88,7 +90,12 @@ func (d *controller) Create(ctx context.Context, r *Robot) (int64, string, error
|
|||||||
r.Duration = int64(config.RobotTokenDuration(ctx))
|
r.Duration = int64(config.RobotTokenDuration(ctx))
|
||||||
expiresAt = time.Now().AddDate(0, 0, config.RobotTokenDuration(ctx)).Unix()
|
expiresAt = time.Now().AddDate(0, 0, config.RobotTokenDuration(ctx)).Unix()
|
||||||
} else {
|
} else {
|
||||||
expiresAt = time.Now().AddDate(0, 0, int(r.Duration)).Unix()
|
durationStr := strconv.FormatInt(r.Duration, 10)
|
||||||
|
duration, err := strconv.Atoi(durationStr)
|
||||||
|
if err != nil {
|
||||||
|
return 0, "", err
|
||||||
|
}
|
||||||
|
expiresAt = time.Now().AddDate(0, 0, duration).Unix()
|
||||||
}
|
}
|
||||||
|
|
||||||
pwd := utils.GenerateRandomString()
|
pwd := utils.GenerateRandomString()
|
||||||
|
@ -20,7 +20,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/registry/auth/basic"
|
"github.com/goharbor/harbor/src/pkg/registry/auth/basic"
|
||||||
@ -289,7 +288,7 @@ func (a *adapter) PushBlob(repository, digest string, size int64, blob io.Reader
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
rangeSize := strconv.Itoa(int(size))
|
rangeSize := fmt.Sprintf("%d", size)
|
||||||
req.Header.Set("Content-Length", rangeSize)
|
req.Header.Set("Content-Length", rangeSize)
|
||||||
req.Header.Set("Content-Range", fmt.Sprintf("0-%s", rangeSize))
|
req.Header.Set("Content-Range", fmt.Sprintf("0-%s", rangeSize))
|
||||||
req.Header.Set("Content-Type", "application/octet-stream")
|
req.Header.Set("Content-Type", "application/octet-stream")
|
||||||
|
Loading…
Reference in New Issue
Block a user