Path: blob/dev/pkg/installer/zipslip_unix_test.go
2070 views
package installer12import (3"io/fs"4"os"5"path/filepath"6"runtime"7"testing"8"time"910"github.com/stretchr/testify/require"11)1213var _ fs.FileInfo = &tempFileInfo{}1415type tempFileInfo struct {16name string17}1819func (t *tempFileInfo) Name() string {20return t.name21}2223func (t *tempFileInfo) ModTime() time.Time {24return time.Now()25}2627func (t *tempFileInfo) Mode() fs.FileMode {28return fs.ModePerm29}3031func (t tempFileInfo) IsDir() bool {32return false33}3435func (t *tempFileInfo) Size() int64 {36return 10037}3839func (t *tempFileInfo) Sys() any {40return nil41}4243func TestZipSlip(t *testing.T) {44if runtime.GOOS == "windows" {45t.Skip("Skipping Unix Zip LFI Check")46}4748configuredTemplateDirectory := filepath.Join(os.TempDir(), "templates")49defer func() {50_ = os.RemoveAll(configuredTemplateDirectory)51}()5253t.Run("negative scenarios", func(t *testing.T) {54filePathsFromZip := []string{55"./../nuclei-templates/../cve/test.yaml",56"nuclei-templates/../cve/test.yaml",57"nuclei-templates/././../cve/test.yaml",58"nuclei-templates/.././../cve/test.yaml",59"nuclei-templates/.././../cve/../test.yaml",60}61tm := TemplateManager{}6263for _, filePathFromZip := range filePathsFromZip {64var tmp fs.FileInfo = &tempFileInfo{name: filePathFromZip}65writePath := tm.getAbsoluteFilePath(configuredTemplateDirectory, filePathFromZip, tmp)66require.Equal(t, "", writePath, filePathFromZip)67}68})69}707172