Skip to content

Commit 6f7bc87

Browse files
committed
Merge branch 'release/2.0.1'
2 parents 6feec9f + d2f0939 commit 6f7bc87

File tree

8 files changed

+56
-14
lines changed

8 files changed

+56
-14
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>org.cryptomator</groupId>
55
<artifactId>webdav-nio-adapter</artifactId>
6-
<version>2.0.0</version>
6+
<version>2.0.1</version>
77
<name>WebDAV-NIO Adapter</name>
88
<description>Embedded Jetty serving a WebDAV servlet to access resources at a given NIO path.</description>
99
<url>https://github.com/cryptomator/webdav-nio-adapter</url>
@@ -21,7 +21,7 @@
2121
<!-- dependencies -->
2222
<integrations-api.version>1.2.0</integrations-api.version>
2323
<webdavservlet.version>1.2.3</webdavservlet.version>
24-
<jetty.version>10.0.13</jetty.version>
24+
<jetty.version>10.0.14</jetty.version>
2525
<slf4j.version>2.0.6</slf4j.version>
2626

2727
<!-- test dependencies -->
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.cryptomator.frontend.webdav;
2+
3+
public interface ContextPathRegistry {
4+
5+
boolean add(String contextPath);
6+
boolean remove(String contextPath);
7+
8+
}

src/main/java/org/cryptomator/frontend/webdav/DefaultServlet.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,20 @@
1313
import javax.servlet.http.HttpServletRequest;
1414
import javax.servlet.http.HttpServletResponse;
1515
import java.io.IOException;
16-
import java.util.Collection;
16+
import java.util.Collections;
17+
import java.util.Set;
1718
import java.util.function.Predicate;
1819
import java.util.regex.Pattern;
1920

20-
class DefaultServlet extends HttpServlet {
21+
class DefaultServlet extends HttpServlet implements ContextPathRegistry {
2122

2223
private static final String METHOD_PROPFIND = "PROPFIND";
2324
private static final int TARPIT_DELAY_MS = 5000;
2425
private static final Pattern PATH_SEP_PATTERN = Pattern.compile("/");
25-
private final Collection<String> contextPaths;
26+
private final Set<String> synchronizedContextPaths;
2627

27-
public DefaultServlet(Collection<String> contextPaths) {
28-
this.contextPaths = contextPaths;
28+
public DefaultServlet(Set<String> contextPaths) {
29+
this.synchronizedContextPaths = Collections.synchronizedSet(contextPaths);
2930
}
3031

3132
@Override
@@ -78,7 +79,24 @@ protected void doPropfind(HttpServletRequest req, HttpServletResponse resp) thro
7879
}
7980

8081
private boolean isRequestedResourcePathPartOfValidContextPath(String requestedResourcePath) {
81-
return contextPaths.stream().anyMatch(cp -> isParentOrSamePath(cp, requestedResourcePath));
82+
//required for synchronized collections, see https://docs.oracle.com/en/java/javase/19/docs/api/java.base/java/util/Collections.html#synchronizedSet(java.util.Set)
83+
synchronized (synchronizedContextPaths) {
84+
return synchronizedContextPaths.stream().anyMatch(cp -> isParentOrSamePath(cp, requestedResourcePath));
85+
}
86+
}
87+
88+
@Override
89+
public boolean add(String contextPath) {
90+
synchronized (synchronizedContextPaths) {
91+
return synchronizedContextPaths.add(contextPath);
92+
}
93+
}
94+
95+
@Override
96+
public boolean remove(String contextPath) {
97+
synchronized (synchronizedContextPaths) {
98+
return synchronizedContextPaths.remove(contextPath);
99+
}
82100
}
83101

84102
private boolean isParentOrSamePath(String path, String potentialParent) {

src/main/java/org/cryptomator/frontend/webdav/WebDavServer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ public class WebDavServer {
3333
private final ExecutorService executorService;
3434
private final ServerConnector localConnector;
3535
private final ContextHandlerCollection servletCollectionCtx;
36+
private final DefaultServlet defaultServlet;
3637

37-
WebDavServer(Server server, ExecutorService executorService, ServerConnector connector, ContextHandlerCollection servletCollectionCtx) {
38+
WebDavServer(Server server, ExecutorService executorService, ServerConnector connector, ContextHandlerCollection servletCollectionCtx, DefaultServlet defaultServlet) {
3839
this.server = server;
3940
this.executorService = executorService;
4041
this.localConnector = connector;
4142
this.servletCollectionCtx = servletCollectionCtx;
43+
this.defaultServlet = defaultServlet;
4244
}
4345

4446
public static WebDavServer create(InetSocketAddress bindAddr) {
@@ -94,7 +96,7 @@ public synchronized void terminate() throws ServerLifecycleException {
9496
* @return The controller object for this new servlet
9597
*/
9698
public WebDavServletController createWebDavServlet(Path rootPath, String contextPath) {
97-
return WebDavServletFactory.createServletController(rootPath, contextPath, localConnector, servletCollectionCtx);
99+
return WebDavServletFactory.createServletController(rootPath, contextPath, localConnector, servletCollectionCtx, defaultServlet);
98100
}
99101

100102
}

src/main/java/org/cryptomator/frontend/webdav/WebDavServerFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public static WebDavServer createWebDavServer(InetSocketAddress bindAddr) {
101101
var servletCollectionCtx = createContextHandlerCollection(defaultServletCtx);
102102
var server = createServer(threadPool, servletCollectionCtx);
103103
var serverConnector = createServerConnector(server, bindAddr);
104-
return new WebDavServer(server, executorService, serverConnector, servletCollectionCtx);
104+
return new WebDavServer(server, executorService, serverConnector, servletCollectionCtx, defaultServlet);
105105
}
106106

107107
}

src/main/java/org/cryptomator/frontend/webdav/servlet/WebDavServletController.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.cryptomator.frontend.webdav.servlet;
22

3+
import org.cryptomator.frontend.webdav.ContextPathRegistry;
34
import org.cryptomator.frontend.webdav.ServerLifecycleException;
45
import org.eclipse.jetty.server.ServerConnector;
56
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
@@ -17,12 +18,14 @@ public class WebDavServletController {
1718
private final ServletContextHandler contextHandler;
1819
private final ContextHandlerCollection contextHandlerCollection;
1920
private final ServerConnector connector;
21+
private final ContextPathRegistry contextPathRegistry;
2022
private final String contextPath;
2123

22-
WebDavServletController(ServletContextHandler contextHandler, ContextHandlerCollection contextHandlerCollection, ServerConnector connector, String contextPath) {
24+
WebDavServletController(ServletContextHandler contextHandler, ContextHandlerCollection contextHandlerCollection, ServerConnector connector, ContextPathRegistry contextPathRegistry, String contextPath) {
2325
this.contextHandler = contextHandler;
2426
this.contextHandlerCollection = contextHandlerCollection;
2527
this.connector = connector;
28+
this.contextPathRegistry = contextPathRegistry;
2629
this.contextPath = contextPath;
2730
}
2831

@@ -33,6 +36,7 @@ public class WebDavServletController {
3336
*/
3437
public void start() throws ServerLifecycleException {
3538
try {
39+
contextPathRegistry.add(contextPath);
3640
contextHandlerCollection.addHandler(contextHandler);
3741
contextHandlerCollection.mapContexts();
3842
contextHandler.start();
@@ -52,6 +56,7 @@ public void stop() throws ServerLifecycleException {
5256
contextHandler.stop();
5357
contextHandlerCollection.removeHandler(contextHandler);
5458
contextHandlerCollection.mapContexts();
59+
contextPathRegistry.remove(contextPath);
5560
LOG.info("WebDavServlet stopped: " + contextPath);
5661
} catch (Exception e) {
5762
throw new ServerLifecycleException("Servlet couldn't be stopped", e);

src/main/java/org/cryptomator/frontend/webdav/servlet/WebDavServletFactory.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*******************************************************************************/
99
package org.cryptomator.frontend.webdav.servlet;
1010

11+
import org.cryptomator.frontend.webdav.ContextPathRegistry;
1112
import org.cryptomator.webdav.core.filters.*;
1213
import org.eclipse.jetty.server.ServerConnector;
1314
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
@@ -39,14 +40,14 @@ public static ServletContextHandler createServletContext(Path rootPath, String c
3940
return servletContext;
4041
}
4142

42-
public static WebDavServletController createServletController(Path rootPath, String untrimmedContextPath, ServerConnector serverConnector, ContextHandlerCollection contextHandlerCollection) {
43+
public static WebDavServletController createServletController(Path rootPath, String untrimmedContextPath, ServerConnector serverConnector, ContextHandlerCollection contextHandlerCollection, ContextPathRegistry contextPathRegistry) {
4344
var trimmedCtxPath = untrimmedContextPath;
4445
while (trimmedCtxPath.endsWith("/")) {
4546
trimmedCtxPath = trimmedCtxPath.substring(0, trimmedCtxPath.length() - 1);
4647
}
4748
String contextPath = trimmedCtxPath.startsWith("/") ? trimmedCtxPath : "/" + trimmedCtxPath;
4849
ServletContextHandler contextHandler = createServletContext(rootPath, contextPath);
49-
return new WebDavServletController(contextHandler, contextHandlerCollection, serverConnector, contextPath);
50+
return new WebDavServletController(contextHandler, contextHandlerCollection, serverConnector, contextPathRegistry, contextPath);
5051
}
5152

5253
}

suppression.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,13 @@
2121
<cpe>cpe:/a:cryptomator:cryptomator</cpe>
2222
<cve>CVE-2022-25366</cve>
2323
</suppress>
24+
<suppress>
25+
<notes><![CDATA[
26+
Suppress false positive, because com.google.common.io.Files.getTempDir() is not used
27+
]]></notes>
28+
<packageUrl regex="true">^pkg:maven/com\.google\.guava/guava@.*$</packageUrl>
29+
<vulnerabilityName>CVE-2020-8908</vulnerabilityName>
30+
<cve>CVE-2020-8908</cve>
31+
</suppress>
2432

2533
</suppressions>

0 commit comments

Comments
 (0)