Skip to content

Commit 9184178

Browse files
authored
Merge branch 'main' into ale-feat-subdir-flag
2 parents 8bc3f33 + fbab2b6 commit 9184178

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

internal/shared/clients.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,12 @@ func (c *ClientFactory) InitSDKConfig(ctx context.Context, dirPath string) error
222222
return slackerror.New(slackerror.ErrHooksJSONLocation)
223223
}
224224
// Move upward one directory level
225-
dirPath = filepath.Dir(dirPath)
225+
parentDir := filepath.Dir(dirPath)
226+
if parentDir == dirPath {
227+
// Reached a filesystem root not covered above (e.g. D:\ when SYSTEMROOT is on C:\)
228+
return slackerror.New(slackerror.ErrHooksJSONLocation)
229+
}
230+
dirPath = parentDir
226231
}
227232
configFileBytes, err := afero.ReadFile(c.Fs, hooksJSONFilePath)
228233
if err != nil {

internal/shared/clients_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ func Test_ClientFactory_InitSDKConfig(t *testing.T) {
110110
mockWorkingDirectory: filepath.Join("path", "outside", "home", "to", "project"),
111111
expectedError: slackerror.New(slackerror.ErrHooksJSONLocation),
112112
},
113+
"errors if traversal reaches a filesystem root": {
114+
mockHooksJSONContent: "{}",
115+
mockHooksJSONFilePath: filepath.Join(string(filepath.Separator), "other", "volume", "project", "package.json"),
116+
mockWorkingDirectory: filepath.Join(string(filepath.Separator), "other", "volume", "project"),
117+
expectedError: slackerror.New(slackerror.ErrHooksJSONLocation),
118+
},
113119
}
114120
for name, tc := range tests {
115121
t.Run(name, func(t *testing.T) {

0 commit comments

Comments
 (0)