{"record":{"id":"6b44f7c37dc9ff5b","repo":"docker/cli","slug":"unexpected-path-format","errorCode":null,"errorMessage":"unexpected path format","messagePattern":"unexpected path format","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/context/store/store.go","lineNumber":376,"sourceCode":"\timportContentType, err := getImportContentType(r)\n\tif err != nil {\n\t\treturn err\n\t}\n\tswitch importContentType {\n\tcase zipType:\n\t\treturn importZip(name, s, r)\n\tdefault:\n\t\t// Assume it's a TAR (TAR does not have a \"magic number\")\n\t\treturn importTar(name, s, r)\n\t}\n}\n\nfunc isValidFilePath(p string) error {\n\tif p != metaFile && !strings.HasPrefix(p, \"tls/\") {\n\t\treturn errors.New(\"unexpected context file\")\n\t}\n\tif path.Clean(p) != p {\n\t\treturn errors.New(\"unexpected path format\")\n\t}\n\tif strings.Contains(p, `\\`) {\n\t\treturn errors.New(`unexpected '\\' in path`)\n\t}\n\treturn nil\n}\n\nfunc importTar(name string, s Writer, reader io.Reader) error {\n\ttr := tar.NewReader(&limitedReader{R: reader, N: maxAllowedFileSizeToImport})\n\ttlsData := ContextTLSData{\n\t\tEndpoints: map[string]EndpointTLSData{},\n\t}\n\tvar importedMetaFile bool\n\tfor {\n\t\thdr, err := tr.Next()\n\t\tif err == io.EOF {\n\t\t\tbreak\n\t\t}","sourceCodeStart":358,"sourceCodeEnd":394,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/context/store/store.go#L358-L394","documentation":"Returned by isValidFilePath when path.Clean(p) != p, i.e. the entry path is not in canonical form (contains redundant slashes, '.' or '..' segments, or trailing slashes). Canonicalizing during import prevents path-traversal and duplicate/ambiguous file placement; only already-clean paths are accepted.","triggerScenarios":"An archive entry whose name is like 'tls/../tls/ca.pem', 'tls//ca.pem', './meta.json', or 'tls/./ca.pem'. Crafted archives attempting directory traversal via '..' segments.","commonSituations":"A malicious or buggy archive producer emits non-canonical paths. Attempting path traversal to escape the context directory. Tar entries created with non-normalized path separators.","solutions":["Recreate the archive with normalized entry paths (no '..', '.', or double slashes).","Use 'docker context export' on a valid context to produce a well-formed archive.","Inspect entries with 'tar -tf archive' or 'unzip -l' and fix any non-canonical paths."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if path.Clean(p) != p {\n    return fmt.Errorf(\"path %q is not canonical; reject to prevent traversal\", p)\n}","typeGuard":"func isCanonicalPath(p string) bool { return path.Clean(p) == p }","tryCatchPattern":null,"preventionTips":["Normalize paths with path.Clean before packaging archives.","Reject any entry containing '..' or '//' at ingest.","Produce archives only through docker context export."],"tags":["context","import","archive","security","path-traversal","validation"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}