Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,15 @@ public InputStream getResourceAsStream(String resourceName)
}
else
{
return Files.newInputStream(new File(_directory, resourceName).toPath());
File file = new File(_directory, resourceName);
// A resource name is built from an attacker-controllable handle read out of a
// compiled .xsb; a handle containing "../" would otherwise let the resolved path
// escape the resource directory and read arbitrary .xsb-suffixed files on disk.
if (!isContainedIn(file, _directory))
{
return null;
}
return Files.newInputStream(file.toPath());
}
}
catch (IOException e)
Expand All @@ -61,6 +69,20 @@ public InputStream getResourceAsStream(String resourceName)
}
}

private static boolean isContainedIn(File file, File directory)
{
try
{
String dirPath = directory.getCanonicalPath() + File.separator;
String filePath = file.getCanonicalPath();
return filePath.startsWith(dirPath);
}
catch (IOException e)
{
return false;
}
}

public void close()
{
if (_zipfile != null)
Expand Down
Loading