~wegtam/smederee

Showing details for patch b711e3105ec606d0818643babfcb80f7b7ccacce.
2024-10-29 (Tue), 6:58 AM - Jens Grassel - b711e3105ec606d0818643babfcb80f7b7ccacce

Hotfix: prevent crashes and internal server errors

Several deep links on deleted repositories lead to crashes and internal
server errors, namely history, patch details and stats. These are now
prevented and a proper not found code (404) is returned.
Summary of changes
1 files modified with 30 lines added and 12 lines removed
  • modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala with 30 added and 12 removed lines
diff -rN -u old-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala new-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala
--- old-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala	2024-11-24 18:10:14.518250570 +0000
+++ new-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala	2024-11-24 18:10:14.518250570 +0000
@@ -1748,8 +1748,11 @@
                 repositoryName
             ) / "history" :? HistoryFromQueryParameter(fromCount) as user =>
             for {
-                csrf <- Sync[F].delay(ar.req.getCsrfToken)
-                resp <- doShowRepositoryHistory(csrf)(user.some)(repositoryOwnerName, repositoryName)(fromCount)
+                csrf      <- Sync[F].delay(ar.req.getCsrfToken)
+                repoAndId <- loadRepo(user.some)(repositoryOwnerName, repositoryName)
+                resp <- repoAndId.fold(NotFound())(_ =>
+                    doShowRepositoryHistory(csrf)(user.some)(repositoryOwnerName, repositoryName)(fromCount)
+                )
             } yield resp
     }
 
@@ -1758,8 +1761,11 @@
                 repositoryName
             ) / "history" :? HistoryFromQueryParameter(fromCount) =>
             for {
-                csrf <- Sync[F].delay(req.getCsrfToken)
-                resp <- doShowRepositoryHistory(csrf)(None)(repositoryOwnerName, repositoryName)(fromCount)
+                csrf      <- Sync[F].delay(req.getCsrfToken)
+                repoAndId <- loadRepo(None)(repositoryOwnerName, repositoryName)
+                resp <- repoAndId.fold(NotFound())(_ =>
+                    doShowRepositoryHistory(csrf)(None)(repositoryOwnerName, repositoryName)(fromCount)
+                )
             } yield resp
     }
 
@@ -1778,8 +1784,11 @@
                 repositoryName
             ) / "patch" / DarcsHashPathParameter(hash) as user =>
             for {
-                csrf <- Sync[F].delay(ar.req.getCsrfToken)
-                resp <- doShowRepositoryPatchDetails(csrf)(user.some)(repositoryOwnerName, repositoryName)(hash)
+                csrf      <- Sync[F].delay(ar.req.getCsrfToken)
+                repoAndId <- loadRepo(user.some)(repositoryOwnerName, repositoryName)
+                resp <- repoAndId.fold(NotFound())(_ =>
+                    doShowRepositoryPatchDetails(csrf)(user.some)(repositoryOwnerName, repositoryName)(hash)
+                )
             } yield resp
     }
 
@@ -1788,8 +1797,11 @@
                 repositoryName
             ) / "patch" / DarcsHashPathParameter(hash) =>
             for {
-                csrf <- Sync[F].delay(req.getCsrfToken)
-                resp <- doShowRepositoryPatchDetails(csrf)(None)(repositoryOwnerName, repositoryName)(hash)
+                csrf      <- Sync[F].delay(req.getCsrfToken)
+                repoAndId <- loadRepo(None)(repositoryOwnerName, repositoryName)
+                resp <- repoAndId.fold(NotFound())(_ =>
+                    doShowRepositoryPatchDetails(csrf)(None)(repositoryOwnerName, repositoryName)(hash)
+                )
             } yield resp
     }
 
@@ -1798,8 +1810,11 @@
                 repositoryName
             ) / "stats" as user =>
             for {
-                csrf <- Sync[F].delay(ar.req.getCsrfToken)
-                resp <- doShowRepositoryStatistics(csrf)(user.some)(repositoryOwnerName, repositoryName)
+                csrf      <- Sync[F].delay(ar.req.getCsrfToken)
+                repoAndId <- loadRepo(user.some)(repositoryOwnerName, repositoryName)
+                resp <- repoAndId.fold(NotFound())(_ =>
+                    doShowRepositoryStatistics(csrf)(user.some)(repositoryOwnerName, repositoryName)
+                )
             } yield resp
     }
 
@@ -1808,8 +1823,11 @@
                 repositoryName
             ) / "stats" =>
             for {
-                csrf <- Sync[F].delay(req.getCsrfToken)
-                resp <- doShowRepositoryStatistics(csrf)(None)(repositoryOwnerName, repositoryName)
+                csrf      <- Sync[F].delay(req.getCsrfToken)
+                repoAndId <- loadRepo(None)(repositoryOwnerName, repositoryName)
+                resp <- repoAndId.fold(NotFound())(_ =>
+                    doShowRepositoryStatistics(csrf)(None)(repositoryOwnerName, repositoryName)
+                )
             } yield resp
     }