Skip to content

Commit c454b70

Browse files
author
Denis
authored
fix: avoid access to arbitrary resource via parent (#10356)
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.
1 parent ffd01c3 commit c454b70

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

flow-server/src/main/java/com/vaadin/flow/server/HandlerHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public static String getCancelingRelativePath(String pathToCancel) {
195195
* @return {@code true}, if the given path has a directory change
196196
* instruction, {@code false} otherwise.
197197
*/
198-
static boolean isPathUnsafe(String path) {
198+
public static boolean isPathUnsafe(String path) {
199199
// Check that the path does not have '/../', '\..\', %5C..%5C,
200200
// %2F..%2F, nor '/..', '\..', %5C.., %2F..
201201
try {

flow-server/src/main/java/com/vaadin/flow/server/osgi/VaadinBundleTracker.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
import org.osgi.util.tracker.BundleTracker;
5050
import org.slf4j.LoggerFactory;
5151

52+
import com.vaadin.flow.server.HandlerHelper;
53+
5254
/**
5355
* Bundle tracker to discover all classes in active bundles.
5456
* <p>
@@ -89,6 +91,10 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
8991
resp.setStatus(HttpURLConnection.HTTP_NOT_FOUND);
9092
return;
9193
}
94+
if (HandlerHelper.isPathUnsafe(pathInfo)) {
95+
resp.setStatus(HttpServletResponse.SC_FORBIDDEN);
96+
return;
97+
}
9298
URL resource = bundle.getResource(resourceDirPath + pathInfo);
9399
if (resource == null) {
94100
resp.setStatus(HttpURLConnection.HTTP_NOT_FOUND);

0 commit comments

Comments
 (0)