mirror of
https://github.com/usatiuk/dhfs.git
synced 2025-10-29 04:57:48 +01:00
Server: fix for non-absolute WebUi paths
This commit is contained in:
@@ -15,11 +15,14 @@ import java.util.Optional;
|
|||||||
@ApplicationScoped
|
@ApplicationScoped
|
||||||
public class WebUiRouter {
|
public class WebUiRouter {
|
||||||
|
|
||||||
@ConfigProperty(name = "dhfs.webui.root")
|
private final Optional<String> _root;
|
||||||
Optional<String> root;
|
|
||||||
|
public WebUiRouter(@ConfigProperty(name = "dhfs.webui.root") Optional<String> root) {
|
||||||
|
_root = root.map(s -> Path.of(s).normalize().toString());
|
||||||
|
}
|
||||||
|
|
||||||
void installRoute(@Observes StartupEvent startupEvent, Router router) {
|
void installRoute(@Observes StartupEvent startupEvent, Router router) {
|
||||||
root.ifPresent(r -> {
|
_root.ifPresent(r -> {
|
||||||
router.route().path("/").handler(ctx -> ctx.redirect("/webui"));
|
router.route().path("/").handler(ctx -> ctx.redirect("/webui"));
|
||||||
router.route()
|
router.route()
|
||||||
.path("/webui/*")
|
.path("/webui/*")
|
||||||
@@ -28,7 +31,7 @@ public class WebUiRouter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void handle(RoutingContext event) {
|
public void handle(RoutingContext event) {
|
||||||
var indexHtml = Paths.get(root.orElseThrow(() -> new IllegalStateException("Web ui root not set but handler called")), "index.html").toString();
|
var indexHtml = Paths.get(_root.orElseThrow(() -> new IllegalStateException("Web ui root not set but handler called")), "index.html").toString();
|
||||||
|
|
||||||
HttpServerRequest request = event.request();
|
HttpServerRequest request = event.request();
|
||||||
String requestedPath = Path.of(event.currentRoute().getPath()).relativize(Path.of(event.normalizedPath())).toString();
|
String requestedPath = Path.of(event.currentRoute().getPath()).relativize(Path.of(event.normalizedPath())).toString();
|
||||||
@@ -38,8 +41,8 @@ public class WebUiRouter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Path requested = Paths.get(root.get(), requestedPath);
|
Path requested = Paths.get(_root.get(), requestedPath);
|
||||||
if (!requested.normalize().startsWith(Paths.get(root.get()))) {
|
if (!requested.normalize().startsWith(Paths.get(_root.get()))) {
|
||||||
request.response().setStatusCode(404).end();
|
request.response().setStatusCode(404).end();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user