{"record":{"id":"b18d7fa844410085","repo":"apolloconfig/apollo","slug":"invalid-file-path-in-zip","errorCode":null,"errorMessage":"Invalid file path in ZIP.","messagePattern":"Invalid file path in ZIP\\.","errorType":"validation","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigsImportService.java","lineNumber":195,"sourceCode":"    }\n\n    List<ImportNamespaceData> toImportNSs = Lists.newArrayList();\n    ZipEntry entry;\n    while ((entry = dataZip.getNextEntry()) != null) {\n      if (entry.isDirectory()) {\n        continue;\n      }\n\n      // file.path format :\n      // ${appId}/${env}/${appId}+${cluster}+${namespaceName}\n      String filePath = entry.getName();\n      String content = readContent(dataZip);\n      if (content == null) {\n        throw new BadRequestException(\"Failed to read file content.\");\n      }\n      String[] info = filePath.replace('\\\\', '/').split(\"/\");\n      if (info.length != 3) {\n        throw new BadRequestException(\"Invalid file path in ZIP.\");\n      }\n      String fileName = info[2];\n      String fileNamePrefix = String.format(\"%s+%s+\", appId, clusterName);\n\n      if (!info[0].equals(appId) || !info[1].equalsIgnoreCase(env.getName())\n          || !fileName.startsWith(fileNamePrefix)) {\n        throw new BadRequestException(\"The content of the file to be imported is incorrect.\");\n      }\n      if (!fileName.endsWith(ConfigFileUtils.CLUSTER_METADATA_FILE_SUFFIX)) {\n        toImportNSs.add(new ImportNamespaceData(env, fileName, content, ignoreConflictNamespace));\n      }\n    }\n\n    if (CollectionUtils.isEmpty(toImportNSs)) {\n      throw new BadRequestException(\"The configuration to be imported is empty.\");\n    }\n\n    try {","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigsImportService.java#L177-L213","documentation":"Thrown as a BadRequestException by ConfigsImportService.importAppConfigFromZipFile() when a zip entry's file path does not split into exactly 3 segments by '/'. The expected path format is ${appId}/${env}/${appId}+${cluster}+${namespaceName}. Paths with fewer or more segments indicate a structurally invalid zip for app-config import.","triggerScenarios":"Importing a zip via importAppConfigFromZipFile that contains entries whose paths don't conform to the 3-segment appId/env/filename format. This includes entries at the root, nested subdirectories, or paths with extra slashes.","commonSituations":"Using a full-export zip (from importDataFromZipFile format which has 4+ segments) with the single-app import endpoint; zip created by an older/newer Apollo version with a different path layout; manually edited zip with extra directories.","solutions":["Ensure the zip was generated by the single-app export endpoint (matching importAppConfigFromZipFile), not the full data export.","Inspect the zip's entry paths (unzip -l) and confirm each non-directory entry matches ${appId}/${env}/${filename}.","Re-export the specific app's configuration from the portal using the correct export function.","Remove any extraneous directory entries or restructure paths to the expected 3-segment format."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Validate zip entry path format before import\ntry (ZipInputStream zis = new ZipInputStream(new FileInputStream(file))) {\n  ZipEntry entry;\n  while ((entry = zis.getNextEntry()) != null) {\n    if (entry.isDirectory()) continue;\n    String[] segments = entry.getName().replace('\\\\', '/').split(\"/\");\n    if (segments.length != 3) {\n      throw new IllegalArgumentException(\n        \"Invalid zip entry path (expected 3 segments): \" + entry.getName());\n    }\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure the zip was produced by the correct single-app export endpoint.","Do not mix full-data export zips with single-app import endpoints.","Inspect zip entry paths with unzip -l before importing."],"tags":["apollo-portal","config-import","zip","bad-request","path-validation"],"backgroundTag":null,"analyzedSha":"d95fc18d112589efc09ddcbe1507047584d55251","analyzedAt":"2026-08-14T04:00:05.477Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}