{"record":{"id":"1d026774d22be191","repo":"googleapis/mcp-toolbox","slug":"path-q-escapes-configured-directory-q","errorCode":null,"errorMessage":"path %q escapes configured directory %q","messagePattern":"path %q escapes configured directory %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/tools/cloudstorage/cloudstoragecommon/paths.go","lineNumber":141,"sourceCode":"func ResolveWithinDir(dir, rel string) (string, error) {\n\tcleanDir, err := ValidateLocalPath(dir)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"directory %q is invalid: %w\", dir, err)\n\t}\n\tif rel == \"\" {\n\t\treturn \"\", fmt.Errorf(\"relative path is empty\")\n\t}\n\tif filepath.IsAbs(rel) {\n\t\treturn \"\", fmt.Errorf(\"path %q must be relative\", rel)\n\t}\n\n\tcleanDest := filepath.Clean(filepath.Join(cleanDir, rel))\n\tout, err := escapes(cleanDir, cleanDest)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"path %q cannot be resolved within %q: %w\", rel, cleanDir, err)\n\t}\n\tif out {\n\t\treturn \"\", fmt.Errorf(\"path %q escapes configured directory %q\", rel, cleanDir)\n\t}\n\n\t// Repeat the check against the real targets. A symlink under cleanDir can\n\t// point anywhere, so the name-level check above proves nothing on its own.\n\tresolvedDir, err := ResolveSymlinks(cleanDir)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"directory %q cannot be resolved: %w\", cleanDir, err)\n\t}\n\tresolvedDest, err := ResolveSymlinks(cleanDest)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"path %q cannot be resolved: %w\", rel, err)\n\t}\n\tout, err = escapes(resolvedDir, resolvedDest)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"path %q cannot be resolved within %q: %w\", rel, cleanDir, err)\n\t}\n\tif out {\n\t\treturn \"\", fmt.Errorf(\"path %q resolves through a symbolic link to a target outside configured directory %q\", rel, cleanDir)","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/tools/cloudstorage/cloudstoragecommon/paths.go#L123-L159","documentation":"Path-containment guard in ResolveWithinDir: after joining, the cleaned destination starts with '..' or is absolute relative to the configured directory, so writing/reading there would escape destination_dir (classic traversal such as '../../etc/passwd').","triggerScenarios":"Thrown at internal/tools/cloudstorage/cloudstoragecommon/paths.go:141 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Remove '..' sequences and use a plain path relative to destination_dir","If the file legitimately lives elsewhere, extend destination_dir rather than traversing out of it"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}