Skip to content

Commit

Permalink
fix: avoid access to arbitrary resource via parent (#10356)
Browse files Browse the repository at this point in the history
Checks whether the Url contains a directory change and a double encoding in Flow bundles resource handling servlet. Returns 403 Forbidden immediately and skip the request handling, if does.
  • Loading branch information
Denis committed Mar 22, 2021
1 parent ffd01c3 commit c454b70
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public static String getCancelingRelativePath(String pathToCancel) {
* @return {@code true}, if the given path has a directory change
* instruction, {@code false} otherwise.
*/
static boolean isPathUnsafe(String path) {
public static boolean isPathUnsafe(String path) {
// Check that the path does not have '/../', '\..\', %5C..%5C,
// %2F..%2F, nor '/..', '\..', %5C.., %2F..
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
import org.osgi.util.tracker.BundleTracker;
import org.slf4j.LoggerFactory;

import com.vaadin.flow.server.HandlerHelper;

/**
* Bundle tracker to discover all classes in active bundles.
* <p>
Expand Down Expand Up @@ -89,6 +91,10 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
resp.setStatus(HttpURLConnection.HTTP_NOT_FOUND);
return;
}
if (HandlerHelper.isPathUnsafe(pathInfo)) {
resp.setStatus(HttpServletResponse.SC_FORBIDDEN);
return;
}
URL resource = bundle.getResource(resourceDirPath + pathInfo);
if (resource == null) {
resp.setStatus(HttpURLConnection.HTTP_NOT_FOUND);
Expand Down

0 comments on commit c454b70

Please sign in to comment.