Skip to content

Commit 2d3e6e8

Browse files
committed
Remove symlink check
1 parent c00d955 commit 2d3e6e8

File tree

3 files changed

+1
-70
lines changed

3 files changed

+1
-70
lines changed

internal/config/types.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"errors"
1111
"fmt"
1212
"log/slog"
13-
"os"
1413
"path/filepath"
1514
"regexp"
1615
"strings"
@@ -484,13 +483,6 @@ func isAllowedDir(path string, allowedDirs []string) (bool, error) {
484483
directoryPath = filepath.Dir(directoryPath)
485484
}
486485

487-
fInfo, _ := os.Stat(directoryPath)
488-
if fInfo != nil {
489-
if isSymlink(directoryPath) {
490-
return false, errors.New("path is a symlink, skipping " + directoryPath)
491-
}
492-
}
493-
494486
for _, allowedDirectory := range allowedDirs {
495487
// Check if the directoryPath starts with the allowedDirectory
496488
// This allows for subdirectories within the allowed directories.
@@ -501,13 +493,3 @@ func isAllowedDir(path string, allowedDirs []string) (bool, error) {
501493

502494
return false, nil
503495
}
504-
505-
func isSymlink(path string) bool {
506-
// check if it contains a symlink
507-
lInfo, _ := os.Lstat(path)
508-
if lInfo != nil && lInfo.Mode()&os.ModeSymlink != 0 {
509-
return true
510-
}
511-
512-
return false
513-
}

internal/config/types_test.go

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
package config
77

88
import (
9-
"os"
109
"testing"
1110

1211
"github.com/stretchr/testify/require"
@@ -77,53 +76,3 @@ func TestTypes_isAllowedDir(t *testing.T) {
7776
})
7877
}
7978
}
80-
81-
func TestTypes_isAllowedDirWithSymlink(t *testing.T) {
82-
t.Run("Test 1: Symlink in allowed directory is not allowed", func(t *testing.T) {
83-
allowedDirs := []string{"/etc/nginx"}
84-
filePath := "file.conf"
85-
symlinkPath := "file_link"
86-
87-
// Create a temp directory for the symlink
88-
tempDir := t.TempDir()
89-
defer os.RemoveAll(tempDir) // Clean up the temp directory after the test
90-
91-
// Ensure the temp directory is in the allowedDirs
92-
allowedDirs = append(allowedDirs, tempDir)
93-
94-
filePath = tempDir + "/" + filePath
95-
defer os.RemoveAll(filePath)
96-
err := os.WriteFile(filePath, []byte("test content"), 0o600)
97-
require.NoError(t, err)
98-
99-
// Create a symlink for testing
100-
symlinkPath = tempDir + "/" + symlinkPath
101-
defer os.Remove(symlinkPath)
102-
err = os.Symlink(filePath, symlinkPath)
103-
require.NoError(t, err)
104-
105-
result, err := isAllowedDir(symlinkPath, allowedDirs)
106-
require.Error(t, err)
107-
require.False(t, result, "Symlink in allowed directory should return false")
108-
})
109-
}
110-
111-
func TestTypes_isSymlink(t *testing.T) {
112-
// create temp dir
113-
tempDir := t.TempDir()
114-
tempConf := tempDir + "test.conf"
115-
defer os.RemoveAll(tempDir)
116-
117-
t.Run("Test 1: File is not a symlink", func(t *testing.T) {
118-
filePath := tempConf
119-
err := os.WriteFile(filePath, []byte("test content"), 0o600)
120-
require.NoError(t, err)
121-
require.False(t, isSymlink(filePath), "File is not a symlink")
122-
})
123-
t.Run("Test 2: File is a symlink", func(t *testing.T) {
124-
filePath := tempDir + "test_conf_link"
125-
err := os.Symlink(tempConf, filePath)
126-
require.NoError(t, err)
127-
require.True(t, isSymlink(filePath), "File is a symlink")
128-
})
129-
}

internal/watcher/file/file_watcher_service_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ func TestFileWatcherService_Watch(t *testing.T) {
266266

267267
select {
268268
case <-channel:
269-
t.Fatalf("Expected file to be skipped")
269+
t.Fatalf("Expected file to be skipped: %v", skippableFile.Name())
270270
case <-time.After(150 * time.Millisecond):
271271
return
272272
}

0 commit comments

Comments
 (0)