aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/App.kt
diff options
context:
space:
mode:
authorMarvin Borner2019-04-19 23:38:36 +0200
committerMarvin Borner2019-04-19 23:38:36 +0200
commit9fe9795c996a6e37e894f7e42ba8761320c47798 (patch)
tree2b3bc8b325ff0e3ea31a555e7bdbfba933194c5f /src/main/kotlin/App.kt
parent5523bd7a5e30b09baa6bb3ccd23252d0ebef6000 (diff)
Increased stability and security
Co-authored-by: LarsVomMars <lars@kroenner.eu>
Diffstat (limited to 'src/main/kotlin/App.kt')
-rw-r--r--src/main/kotlin/App.kt13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/main/kotlin/App.kt b/src/main/kotlin/App.kt
index d3f0cd9..50c7c18 100644
--- a/src/main/kotlin/App.kt
+++ b/src/main/kotlin/App.kt
@@ -11,6 +11,7 @@ import io.javalin.security.*
import io.javalin.security.SecurityUtil.roles
import io.javalin.staticfiles.*
import java.io.*
+import java.net.*
import java.util.logging.*
const val fileHome = "files"
@@ -36,6 +37,18 @@ fun main() {
app.routes {
/**
+ * Normalizes and cleans the requested url
+ */
+ before("/*") { ctx ->
+ run {
+ if (URI(ctx.url()).normalize().toString() != ctx.url()) {
+ log.warning("Normalized url from ${ctx.url()} to ${URI(ctx.url()).normalize()}")
+ ctx.redirect(URI(ctx.url()).normalize().toString())
+ }
+ }
+ }
+
+ /**
* Main page
* TODO: Create landing page
*/