MCPcopy Index your code
hub / github.com/docker/docker-agent / resolveCachePath

Function resolveCachePath

pkg/teamloader/cache.go:51–61  ·  view source on GitHub ↗

resolveCachePath returns path unchanged when it is empty (in-memory cache) or absolute; otherwise it joins it with parentDir, cleans the result, and refuses any path that escapes parentDir via "..". Note: This is a lexical check only and does not resolve symlinks. An attacker with write access to p

(path, parentDir string)

Source from the content-addressed store, hash-verified

49// significant privileges
50// 3. The cache only stores agent responses, not sensitive data
51func resolveCachePath(path, parentDir string) (string, error) {
52 if path == "" || filepath.IsAbs(path) {
53 return path, nil
54 }
55 resolved := filepath.Clean(filepath.Join(parentDir, path))
56 cleanParent := filepath.Clean(parentDir) + string(filepath.Separator)
57 if !strings.HasPrefix(resolved+string(filepath.Separator), cleanParent) {
58 return "", fmt.Errorf("cache path %q escapes parent directory", path)
59 }
60 return resolved, nil
61}

Callers 1

buildAgentCacheFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected