{"record":{"id":"ac72395f50e9bdaf","repo":"googleapis/mcp-toolbox","slug":"path-q-contains","errorCode":null,"errorMessage":"path %q contains '..'","messagePattern":"path %q contains '\\.\\.'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/tools/cloudstorage/cloudstoragecommon/paths.go","lineNumber":47,"sourceCode":"// remain the real isolation boundary; this check just prevents obvious\n// traversal mistakes and forces callers to be explicit about where they want\n// bytes to land. Confining a path to a configured directory is a separate\n// concern; see ResolveWithinDir and ResolveSymlinks.\nfunc ValidateLocalPath(p string) (string, error) {\n\tif p == \"\" {\n\t\treturn \"\", fmt.Errorf(\"path is empty\")\n\t}\n\t// Reject any \"..\" segment in the raw input. We check the raw input\n\t// (not just the cleaned output) so that escapes like\n\t// \"/legit/../../etc/passwd\" — which filepath.Clean collapses to an\n\t// innocuous-looking absolute path — are still rejected. Legitimate\n\t// names that happen to *contain* two dots (e.g. \"foo..bar\") are fine;\n\t// only a standalone \"..\" segment is disallowed.\n\tfor _, seg := range strings.FieldsFunc(p, func(r rune) bool {\n\t\treturn r == '/' || r == '\\\\'\n\t}) {\n\t\tif seg == \"..\" {\n\t\t\treturn \"\", fmt.Errorf(\"path %q contains '..'\", p)\n\t\t}\n\t}\n\tclean := filepath.Clean(p)\n\tif !filepath.IsAbs(clean) {\n\t\treturn \"\", fmt.Errorf(\"path %q must be absolute\", p)\n\t}\n\treturn clean, nil\n}\n\n// ResolveSymlinks returns the final filesystem target of path, following every\n// symbolic link along the way. Comparing *this* against a configured boundary —\n// rather than the caller-supplied name — is what stops a path that merely looks\n// like it sits inside the boundary from opening a file outside it.\n//\n// Paths whose trailing components do not exist yet (the normal case for a\n// download destination) are resolved as deeply as the filesystem allows, and\n// the missing components are appended literally.\n//","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/tools/cloudstorage/cloudstoragecommon/paths.go#L29-L65","documentation":"ValidateLocalPath found a standalone \"..\" segment in the raw path — a path-traversal attempt (or mistake) that filepath.Clean would silently collapse, so it is rejected outright to keep the download/upload destination from escaping the intended location.","triggerScenarios":"Thrown at internal/tools/cloudstorage/cloudstoragecommon/paths.go:47 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Remove \"..\" segments and use explicit absolute paths","Construct paths from trusted, validated components","Reject user-supplied relative path fragments at the tool boundary"],"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"}