MCPcopy Create free account
hub / github.com/GongShichen/LuminaCode / ValidatePaths

Function ValidatePaths

tools/bash/validation.go:317–356  ·  view source on GitHub ↗
(command string, workspaceRoot string)

Source from the content-addressed store, hash-verified

315}
316
317func ValidatePaths(command string, workspaceRoot string) (bool, []string) {
318 paths := ExtractPaths(command)
319 invalid := []string{}
320
321 root, err := resolvePath(workspaceRoot)
322 if err != nil {
323 return false, paths
324 }
325
326 for _, p := range paths {
327 if strings.HasPrefix(p, "/dev/") || strings.HasPrefix(p, "/proc/") || strings.HasPrefix(p, "/sys/") {
328 continue
329 }
330
331 if isSpecialSafePath(p) {
332 continue
333 }
334
335 if IsPathWithinWorkspace(p, root) {
336 continue
337 }
338
339 full := p
340 if !filepath.IsAbs(p) {
341 full = filepath.Join(root, p)
342 }
343 resolvedFull, err := resolvePath(full)
344 if err != nil {
345 invalid = append(invalid, p)
346 continue
347 }
348
349 rel, err := filepath.Rel(root, resolvedFull)
350 if err != nil || rel == ".." || strings.HasPrefix(rel, ".."+string(filepath.Separator)) {
351 invalid = append(invalid, p)
352 }
353 }
354
355 return len(invalid) == 0, invalid
356}
357
358func isSpecialSafePath(p string) bool {
359 switch p {

Callers

nothing calls this directly

Calls 4

ExtractPathsFunction · 0.85
resolvePathFunction · 0.85
isSpecialSafePathFunction · 0.85
IsPathWithinWorkspaceFunction · 0.85

Tested by

no test coverage detected