Fix ZipSlip vuln and integer conversion issue
This commit is contained in:
@@ -136,7 +136,7 @@ func main() {
|
|||||||
rmqUser := os.Getenv("MRVA_RABBITMQ_USER")
|
rmqUser := os.Getenv("MRVA_RABBITMQ_USER")
|
||||||
rmqPass := os.Getenv("MRVA_RABBITMQ_PASSWORD")
|
rmqPass := os.Getenv("MRVA_RABBITMQ_PASSWORD")
|
||||||
|
|
||||||
rmqPortAsInt, err := strconv.Atoi(rmqPort)
|
rmqPortAsInt, err := strconv.ParseInt(rmqPort, 10, 16)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("Failed to parse RabbitMQ port", slog.Any("error", err))
|
slog.Error("Failed to parse RabbitMQ port", slog.Any("error", err))
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|||||||
@@ -4,9 +4,11 @@ import (
|
|||||||
"archive/tar"
|
"archive/tar"
|
||||||
"archive/zip"
|
"archive/zip"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// UnzipFile extracts a zip file to the specified destination
|
// UnzipFile extracts a zip file to the specified destination
|
||||||
@@ -19,6 +21,12 @@ func UnzipFile(zipFile, dest string) error {
|
|||||||
|
|
||||||
for _, f := range r.File {
|
for _, f := range r.File {
|
||||||
fPath := filepath.Join(dest, f.Name)
|
fPath := filepath.Join(dest, f.Name)
|
||||||
|
|
||||||
|
// mitigate ZipSlip
|
||||||
|
if !strings.HasPrefix(filepath.Clean(fPath), filepath.Clean(dest)+string(os.PathSeparator)) {
|
||||||
|
return fmt.Errorf("illegal file path: %s", fPath)
|
||||||
|
}
|
||||||
|
|
||||||
if f.FileInfo().IsDir() {
|
if f.FileInfo().IsDir() {
|
||||||
if err := os.MkdirAll(fPath, os.ModePerm); err != nil {
|
if err := os.MkdirAll(fPath, os.ModePerm); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -84,6 +92,12 @@ func Untar(r io.Reader, dest string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fPath := filepath.Join(dest, header.Name)
|
fPath := filepath.Join(dest, header.Name)
|
||||||
|
|
||||||
|
// mitigate ZipSlip
|
||||||
|
if !strings.HasPrefix(filepath.Clean(fPath), filepath.Clean(dest)+string(os.PathSeparator)) {
|
||||||
|
return fmt.Errorf("illegal file path: %s", fPath)
|
||||||
|
}
|
||||||
|
|
||||||
if header.Typeflag == tar.TypeDir {
|
if header.Typeflag == tar.TypeDir {
|
||||||
if err := os.MkdirAll(fPath, os.ModePerm); err != nil {
|
if err := os.MkdirAll(fPath, os.ModePerm); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in New Issue
Block a user