CVE-2024-24749 (Java, published 2024-07-01T14:15Z)
Description: value: GeoServer is an open source server that allows users to share and edit geospatial data. Prior to versions 2.23.5 and 2.24.3, if GeoServer is deployed in the Windows operating system using an Apache Tomcat web application server, it is possible to bypass existing input validation in the GeoWebCache ByteStreamController class and read arbitrary classpath resources with specific file name extensions. If GeoServer is also deployed as a web archive using the data directory embedded in the `geoserver.war` file (rather than an external data directory), it will likely be possible to read specific resources to gain administrator privileges. However, it is very unlikely that production environments will be using the embedded data directory since, depending on how GeoServer is deployed, it will be erased and re-installed (which would also reset to the default password) either every time the server restarts or every time a new GeoServer WAR is installed and is therefore difficult to maintain. An external data directory will always be used if GeoServer is running in standalone mode (via an installer or a binary). Versions 2.23.5 and 2.24.3 contain a patch for the issue. Some workarounds are available. One may change from a Windows environment to a Linux environment; or change from Apache Tomcat to Jetty application server. One may also disable anonymous access to the embeded GeoWebCache administration and status pages.
Severity: nan (CVSS v3 base score: )
Weakness: NVD-CWE-noinfo \u2014 Insufficient Information
There is insufficient information about the issue to classify it; details are unkown or unspecified.
Repository: https://github.com/GeoWebCache/geowebcache
Files changed:
geowebcache/rest/src/main/java/org/geowebcache/rest/controller/ByteStreamController.java
geowebcache/rest/src/test/java/org/geowebcache/rest/controller/ByteStreamControllerTest.java
Commit message: [GWC-1210] Improve input validation in ByteStreamController (#1211)



Vulnerable code:
import java.io.UnsupportedEncodingException;
    String getFileName(HttpServletRequest request) {
        String path = request.getPathInfo();
        if (path.indexOf("/rest/web") != 0) {
            path = path.substring(path.indexOf("/rest/web"));
        }
        return path.substring("/rest/web/".length());
    ResponseEntity<?> doGet(HttpServletRequest request, HttpServletResponse response) {
        final String filename;
        try {
            filename = URLDecoder.decode(getFileName(request), "UTF-8");
        } catch (UnsupportedEncodingException e1) {
            throw new IllegalStateException(
                    "Could not decode encoding UTF-8", e1); // Should never happen

Fixed code:
import java.io.File;
    String getFileName(HttpServletRequest request) throws IOException {
        String path =
                URLDecoder.decode(request.getRequestURI(), "UTF-8")
                        .substring(request.getContextPath().length())
                        .replace(File.separatorChar, '/');
        int index = path.indexOf("/rest/web/");
        return index < 0 ? null : path.substring(index + "/rest/web/".length());
    ResponseEntity<?> doGet(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        final String filename = getFileName(request);
        if (filename == null || filename.isEmpty()) {
            return new ResponseEntity<>(HttpStatus.NOT_FOUND);
import static org.junit.Assume.assumeTrue;
import org.apache.commons.lang3.SystemUtils;

    @Test
    public void testBackreferenceWindows() throws Exception {
        assumeTrue(SystemUtils.IS_OS_WINDOWS);
        mockMvc.perform(get("/rest/web/..\\..\\shouldnt/access/test.png"))
                .andExpect(status().is4xxClientError());
    }

    @Test
    public void testBackreferenceWindows2() throws Exception {
        assumeTrue(SystemUtils.IS_OS_WINDOWS);
        mockMvc.perform(get("/rest/web/foo\\..\\..\\..\\shouldnt/access/test.png"))
                .andExpect(status().is4xxClientError());
    }