security: remediate vulnerabilities and issues from codebase audit
All checks were successful
Automated Container Build / build-and-push (push) Successful in 1m15s
All checks were successful
Automated Container Build / build-and-push (push) Successful in 1m15s
This commit is contained in:
parent
b60a09196a
commit
fb3f3a3393
15 changed files with 465 additions and 208 deletions
|
|
@ -75,6 +75,15 @@ func main() {
|
|||
workers.StartBackupWorker(cfg, db)
|
||||
workers.StartTrashWorker(cfg, db)
|
||||
|
||||
// Start prune worker
|
||||
go func() {
|
||||
ticker := time.NewTicker(12 * time.Hour)
|
||||
for range ticker.C {
|
||||
workers.Tasks.CleanOldTasks()
|
||||
db.CleanOldAuditLogs()
|
||||
}
|
||||
}()
|
||||
|
||||
// Create Fiber app
|
||||
app := fiber.New(fiber.Config{
|
||||
BodyLimit: 100 * 1024 * 1024 * 1024, // 100 GB (for chunked uploads, each chunk is smaller)
|
||||
|
|
@ -94,8 +103,13 @@ func main() {
|
|||
return c.Next()
|
||||
})
|
||||
app.Use(helmet.New())
|
||||
allowedOrigins := os.Getenv("ALLOWED_ORIGINS")
|
||||
if allowedOrigins == "" {
|
||||
allowedOrigins = "http://localhost:3000"
|
||||
}
|
||||
|
||||
app.Use(cors.New(cors.Config{
|
||||
AllowOrigins: "*",
|
||||
AllowOrigins: allowedOrigins,
|
||||
AllowHeaders: "Origin, Content-Type, Accept, Authorization, Upload-Length, Upload-Offset, Upload-Metadata, Tus-Resumable",
|
||||
AllowMethods: "GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD",
|
||||
ExposeHeaders: "Location, Upload-Offset, Upload-Length, Tus-Resumable, Tus-Version, Tus-Extension, Tus-Max-Size",
|
||||
|
|
@ -116,6 +130,7 @@ func main() {
|
|||
Max: 20,
|
||||
Expiration: 1 * time.Minute,
|
||||
}))
|
||||
public.Post("/share/:id/token", shareHandler.CreateShareToken)
|
||||
public.Post("/share/:id", shareHandler.GetPublicShare)
|
||||
public.Get("/download/:id", shareHandler.DownloadPublicShare)
|
||||
|
||||
|
|
@ -125,6 +140,12 @@ func main() {
|
|||
|
||||
// === PROTECTED ROUTES (require JWT) ===
|
||||
protected := app.Group("/api", middleware.AuthMiddleware(cfg.JWTSecret))
|
||||
|
||||
// Apply rate limiting to all authenticated endpoints (e.g. 100 req/min)
|
||||
protected.Use(limiter.New(limiter.Config{
|
||||
Max: 100,
|
||||
Expiration: 1 * time.Minute,
|
||||
}))
|
||||
|
||||
// Token refresh
|
||||
protected.Post("/auth/refresh", authHandler.Refresh)
|
||||
|
|
@ -137,6 +158,9 @@ func main() {
|
|||
protected.Post("/auth/2fa/confirm", authHandler.Confirm2FA)
|
||||
protected.Post("/auth/2fa/disable", authHandler.Disable2FA)
|
||||
|
||||
// Download tokens
|
||||
protected.Get("/auth/download-token", authHandler.GetDownloadToken)
|
||||
|
||||
// Settings & Audit
|
||||
protected.Get("/settings", settingsHandler.GetSettings)
|
||||
protected.Put("/settings", settingsHandler.UpdateSettings)
|
||||
|
|
@ -162,8 +186,6 @@ func main() {
|
|||
protected.Post("/files/rename", fsHandler.Rename)
|
||||
protected.Post("/files/move", fsHandler.Move)
|
||||
protected.Post("/files/copy", fsHandler.Copy)
|
||||
protected.Get("/files/download-folder", fsHandler.DownloadFolder)
|
||||
protected.Post("/files/download-bulk", fsHandler.DownloadBulk)
|
||||
protected.Post("/files/upload", fsHandler.Upload)
|
||||
|
||||
protected.Get("/files/folders-tree", fsHandler.GetFolderTree)
|
||||
|
|
@ -172,6 +194,8 @@ func main() {
|
|||
files := protected.Group("/files", middleware.PathJail(cfg.StorageDir))
|
||||
files.Get("/info/*", fsHandler.GetExtendedFileInfo)
|
||||
files.Get("/thumbnail/:checksum", fsHandler.ServeThumbnail)
|
||||
files.Get("/download-folder", fsHandler.DownloadFolder)
|
||||
files.Post("/download-bulk", fsHandler.DownloadBulk)
|
||||
files.Get("/download/*", fsHandler.Download)
|
||||
files.Post("/zip", archiveHandler.Zip)
|
||||
files.Post("/unzip", archiveHandler.Unzip)
|
||||
|
|
|
|||
Reference in a new issue