/** * TODO un-restrict it in a weekly after the patch */ @Override @Restricted(NoExternalUse.class) public boolean isDescendant(String potentialChildRelativePath) throws IOException { if (new File(potentialChildRelativePath).isAbsolute()) { throw new IllegalArgumentException("Only a relative path is supported, the given path is absolute: " + potentialChildRelativePath); } String relativePath = computeRelativePathToRoot(); try { return this.root.isDescendant(relativePath + potentialChildRelativePath); } catch (InterruptedException e) { return false; } }
/** * TODO un-restrict it in a weekly after the patch */ @Override @Restricted(NoExternalUse.class) public boolean isDescendant(String potentialChildRelativePath) throws IOException { if (new File(potentialChildRelativePath).isAbsolute()) { throw new IllegalArgumentException("Only a relative path is supported, the given path is absolute: " + potentialChildRelativePath); } FilePath root = new FilePath(this.root); String relativePath = computeRelativePathToRoot(); try { return root.isDescendant(relativePath + potentialChildRelativePath); } catch (InterruptedException e) { return false; } }
@Override public Environment setUp(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException { if (!StringUtils.isEmpty(location) && !StringUtils.isEmpty(file.getName())) { listener.getLogger().println("Copying file to "+location); FilePath ws = build.getWorkspace(); if (ws == null) { throw new IllegalStateException("The workspace should be created when setUp method is called"); } if (!ALLOW_FOLDER_TRAVERSAL_OUTSIDE_WORKSPACE && !ws.isDescendant(location)) { listener.error("Rejecting file path escaping base directory with relative path: " + location); // force the build to fail return null; } FilePath locationFilePath = ws.child(location); locationFilePath.getParent().mkdirs(); locationFilePath.copyFrom(file); locationFilePath.copyTo(new FilePath(getLocationUnderBuild(build))); } return new Environment() {}; } };