Skip to content

Commit

Permalink
Compare canonical paths of Wsdl path and Archive path to avoid outsid…
Browse files Browse the repository at this point in the history
…e hits
  • Loading branch information
piyumaldk committed Mar 19, 2024
1 parent 88bb094 commit 14edd9d
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1631,7 +1631,13 @@ private static byte[] loadWsdlFile(String pathToArchive, APIDTO apiDto) throws I
}

if (!StringUtils.isEmpty(pathToWsdl)) {
return FileUtils.readFileToByteArray(new File(pathToWsdl));
// Check the Canonical paths
File file = new File(pathToWsdl);
String canonicalPath = file.getCanonicalPath();
if (!canonicalPath.startsWith(new File(pathToArchive).getCanonicalPath())) {
throw new IOException("Attempt to upload invalid zip archive. File path is outside target directory");

Check warning on line 1638 in components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/ImportUtils.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/ImportUtils.java#L1638

Added line #L1638 was not covered by tests
}
return FileUtils.readFileToByteArray(file);
}
throw new IOException("Missing WSDL file. It should be present.");
}
Expand Down

0 comments on commit 14edd9d

Please sign in to comment.