Initial file filter code

This commit is contained in:
Mike Primm 2021-01-01 09:21:12 -06:00
parent 2b1d0aa955
commit 806e8c056a
2 changed files with 37 additions and 0 deletions

View File

@ -60,6 +60,7 @@ import org.dynmap.utils.BlockStep;
import org.dynmap.utils.ImageIOManager;
import org.dynmap.web.BanIPFilter;
import org.dynmap.web.CustomHeaderFilter;
import org.dynmap.web.FileNameFilter;
import org.dynmap.web.FilterHandler;
import org.dynmap.web.HandlerRouter;
import org.eclipse.jetty.server.Connector;
@ -973,6 +974,8 @@ public class DynmapCore implements DynmapCommonAPI {
if (checkbannedips) {
filters.add(new BanIPFilter(this));
}
filters.add(new FileNameFilter(this));
// filters.add(new LoginFilter(this));
/* Load customized response headers, if any */

View File

@ -0,0 +1,34 @@
package org.dynmap.web;
import org.dynmap.DynmapCore;
import org.dynmap.Log;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class FileNameFilter implements Filter {
public FileNameFilter(DynmapCore core) {
}
@Override
public void init(FilterConfig filterConfig) throws ServletException { }
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
String path = ((HttpServletRequest)request).getRequestURL().toString();
HttpServletResponse resp = (HttpServletResponse)response;
// Filter unneeded file requests
if (path.toLowerCase().endsWith(".php")) {
resp.sendError(404);
} else {
chain.doFilter(request, response);
}
}
@Override
public void destroy() { }
}