@Test @ConditionalRun(UnixPresent.class) public void shouldHandleLinksToCanonicalChildrenOfAllowedLinks() throws IOException, ForbiddenSymlinkException { File sourceRoot = createTemporaryDirectory("srcroot"); assertTrue(sourceRoot + " should be a dir", sourceRoot.isDirectory()); File realDir1 = createTemporaryDirectory("realdir1"); assertTrue(realDir1 + " should be a dir", realDir1.isDirectory()); File realDir1b = new File(realDir1, "b"); assertTrue(realDir1b + " should be created", realDir1b.mkdir()); final String SYMLINK1 = "symlink1"; File symlink1 = new File(sourceRoot, SYMLINK1); Files.createSymbolicLink(symlink1.toPath(), realDir1.toPath()); assertTrue(symlink1 + " should exist", symlink1.exists()); final String SYMLINK2 = "symlink2"; File symlink2 = new File(realDir1b, SYMLINK2); Files.createSymbolicLink(symlink2.toPath(), realDir1b.toPath()); assertTrue(symlink2 + " should exist", symlink2.exists()); Set<String> allowedSymLinks = new HashSet<>(); allowedSymLinks.add(symlink1.getPath()); String realDir1Canon = realDir1.getCanonicalPath(); String rel = PathUtils.getRelativeToCanonical(symlink2.toString(), realDir1Canon, allowedSymLinks, null); assertEquals("symlink2 should be allowed implicitly as a canonical child of symlink1", "b", rel); }
public static String getRelativeToCanonical(String path, String canonical) throws IOException { try { return getRelativeToCanonical(path, canonical, null, null); } catch (ForbiddenSymlinkException e) { return path; } }
PathUtils { public static String getRelativeToCanonical(String path, String canonical) throws IOException { try { return getRelativeToCanonical(path, canonical, null, null); } catch (ForbiddenSymlinkException e) { return path; } } }
PathUtils { public static String getRelativeToCanonical(String path, String canonical) throws IOException { try { return getRelativeToCanonical(path, canonical, null, null); } catch (ForbiddenSymlinkException e) { return path; } } private  PathUtils(); }
PathUtils { public static String getRelativeToCanonical(String path, String canonical) throws IOException { try { return getRelativeToCanonical(path, canonical, null, null); } catch (ForbiddenSymlinkException e) { return path; } } private  PathUtils(); static String getRelativeToCanonical(String path, String canonical); static String getRelativeToCanonical(String path, String canonical,
            Set<String> allowedSymlinks, Set<String> canonicalRoots); }
PathUtils { public static String getRelativeToCanonical(String path, String canonical) throws IOException { try { return getRelativeToCanonical(path, canonical, null, null); } catch (ForbiddenSymlinkException e) { return path; } } private  PathUtils(); static String getRelativeToCanonical(String path, String canonical); static String getRelativeToCanonical(String path, String canonical,
            Set<String> allowedSymlinks, Set<String> canonicalRoots);  }