MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / ensureInsideDir

Function ensureInsideDir

internal/aiagentconfig/builder.go:190–201  ·  view source on GitHub ↗

ensureInsideDir verifies that filePath is inside dir. Both paths must be already resolved (no symlinks). Returns an error if the file escapes.

(filePath, dir string)

Source from the content-addressed store, hash-verified

188// ensureInsideDir verifies that filePath is inside dir. Both paths must be
189// already resolved (no symlinks). Returns an error if the file escapes.
190func ensureInsideDir(filePath, dir string) error {
191 rel, err := filepath.Rel(dir, filePath)
192 if err != nil {
193 return fmt.Errorf("path escapes root directory via symlink")
194 }
195
196 if rel == ".." || strings.HasPrefix(rel, ".."+string(filepath.Separator)) {
197 return fmt.Errorf("path escapes root directory via symlink")
198 }
199
200 return nil
201}

Callers 1

safeReadFileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected