@@ -2,6 +2,8 @@ package router
2
2
3
3
import (
4
4
"fmt"
5
+ "net/http"
6
+ "path/filepath"
5
7
"regexp"
6
8
"time"
7
9
@@ -14,7 +16,7 @@ import (
14
16
"github.com/gotify/server/v2/config"
15
17
"github.com/gotify/server/v2/database"
16
18
"github.com/gotify/server/v2/docs"
17
- "github.com/gotify/server/v2/error"
19
+ gerror "github.com/gotify/server/v2/error"
18
20
"github.com/gotify/server/v2/model"
19
21
"github.com/gotify/server/v2/plugin"
20
22
"github.com/gotify/server/v2/ui"
@@ -24,8 +26,8 @@ import (
24
26
func Create (db * database.GormDatabase , vInfo * model.VersionInfo , conf * config.Configuration ) (* gin.Engine , func ()) {
25
27
g := gin .New ()
26
28
27
- g .Use (gin .LoggerWithFormatter (logFormatter ), gin .Recovery (), error .Handler (), location .Default ())
28
- g .NoRoute (error .NotFound ())
29
+ g .Use (gin .LoggerWithFormatter (logFormatter ), gin .Recovery (), gerror .Handler (), location .Default ())
30
+ g .NoRoute (gerror .NotFound ())
29
31
30
32
streamHandler := stream .New (time .Duration (conf .Server .Stream .PingPeriodSeconds )* time .Second , 15 * time .Second , conf .Server .Stream .AllowedOrigins )
31
33
authentication := auth.Auth {DB : db }
@@ -61,7 +63,8 @@ func Create(db *database.GormDatabase, vInfo *model.VersionInfo, conf *config.Co
61
63
62
64
g .GET ("/health" , healthHandler .Health )
63
65
g .GET ("/swagger" , docs .Serve )
64
- g .Static ("/image" , conf .UploadedImagesDir )
66
+ g .StaticFS ("/image" , & onlyImageFS {inner : gin .Dir (conf .UploadedImagesDir , false )})
67
+
65
68
g .GET ("/docs" , docs .UI )
66
69
67
70
g .Use (func (ctx * gin.Context ) {
@@ -194,3 +197,15 @@ func logFormatter(param gin.LogFormatterParams) string {
194
197
param .ErrorMessage ,
195
198
)
196
199
}
200
+
201
+ type onlyImageFS struct {
202
+ inner http.FileSystem
203
+ }
204
+
205
+ func (fs * onlyImageFS ) Open (name string ) (http.File , error ) {
206
+ ext := filepath .Ext (name )
207
+ if ! api .ValidApplicationImageExt (ext ) {
208
+ return nil , fmt .Errorf ("invalid file" )
209
+ }
210
+ return fs .inner .Open (name )
211
+ }
0 commit comments