@@ -148,6 +148,21 @@ func InitV2DocRouter(docHTML string, docYAML string) http.Handler {
148
148
149
149
func InitFile () http.Handler {
150
150
return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
151
+ token := r .URL .Query ().Get ("token" )
152
+ if len (token ) == 0 {
153
+ w .Header ().Set ("Content-Type" , "application/json" )
154
+ w .WriteHeader (http .StatusUnauthorized )
155
+ w .Write ([]byte (`{"message": "token not found"}` ))
156
+ return
157
+ }
158
+
159
+ valid , _ , errs := jwt .Validate (token , func () (* ecdsa.PublicKey , error ) { return external .GetPublicKey (config .CommonInfo .RuntimePath ) })
160
+ if errs != nil || ! valid {
161
+ w .Header ().Set ("Content-Type" , "application/json" )
162
+ w .WriteHeader (http .StatusUnauthorized )
163
+ w .Write ([]byte (`{"message": "validation failure"}` ))
164
+ return
165
+ }
151
166
filePath := r .URL .Query ().Get ("path" )
152
167
fileName := path .Base (filePath )
153
168
w .Header ().Add ("Content-Disposition" , "attachment; filename*=utf-8''" + url .PathEscape (fileName ))
@@ -158,6 +173,21 @@ func InitFile() http.Handler {
158
173
159
174
func InitDir () http.Handler {
160
175
return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
176
+ token := r .URL .Query ().Get ("token" )
177
+ if len (token ) == 0 {
178
+ w .Header ().Set ("Content-Type" , "application/json" )
179
+ w .WriteHeader (http .StatusUnauthorized )
180
+ w .Write ([]byte (`{"message": "token not found"}` ))
181
+ return
182
+ }
183
+
184
+ valid , _ , errs := jwt .Validate (token , func () (* ecdsa.PublicKey , error ) { return external .GetPublicKey (config .CommonInfo .RuntimePath ) })
185
+ if errs != nil || ! valid {
186
+ w .Header ().Set ("Content-Type" , "application/json" )
187
+ w .WriteHeader (http .StatusUnauthorized )
188
+ w .Write ([]byte (`{"message": "validation failure"}` ))
189
+ return
190
+ }
161
191
t := r .URL .Query ().Get ("format" )
162
192
files := r .URL .Query ().Get ("files" )
163
193
0 commit comments