@@ -103,14 +103,29 @@ func FsMove(c *gin.Context) {
103103 }
104104 if ! req .Overwrite {
105105 for _ , name := range req .Names {
106- if res , _ := fs .Get (c , stdpath .Join (dstDir , name ), & fs.GetArgs {NoLog : true }); res != nil {
106+ dstPath , err := utils .JoinUnderBase (dstDir , name )
107+ if err != nil {
108+ common .ErrorResp (c , err , 400 )
109+ return
110+ }
111+ if res , _ := fs .Get (c , dstPath , & fs.GetArgs {NoLog : true }); res != nil {
107112 common .ErrorStrResp (c , fmt .Sprintf ("file [%s] exists" , name ), 403 )
108113 return
109114 }
110115 }
111116 }
112117 for i , name := range req .Names {
113- err := fs .Move (c , stdpath .Join (srcDir , name ), dstDir , len (req .Names ) > i + 1 )
118+ srcPath , err := utils .JoinUnderBase (srcDir , name )
119+ if err != nil {
120+ common .ErrorResp (c , err , 400 )
121+ return
122+ }
123+ _ , err = utils .JoinUnderBase (dstDir , name )
124+ if err != nil {
125+ common .ErrorResp (c , err , 400 )
126+ return
127+ }
128+ err = fs .Move (c , srcPath , dstDir , len (req .Names ) > i + 1 )
114129 if err != nil {
115130 common .ErrorResp (c , err , 500 )
116131 return
@@ -155,15 +170,30 @@ func FsCopy(c *gin.Context) {
155170 }
156171 if ! req .Overwrite {
157172 for _ , name := range req .Names {
158- if res , _ := fs .Get (c , stdpath .Join (dstDir , name ), & fs.GetArgs {NoLog : true }); res != nil {
173+ dstPath , err := utils .JoinUnderBase (dstDir , name )
174+ if err != nil {
175+ common .ErrorResp (c , err , 400 )
176+ return
177+ }
178+ if res , _ := fs .Get (c , dstPath , & fs.GetArgs {NoLog : true }); res != nil {
159179 common .ErrorStrResp (c , fmt .Sprintf ("file [%s] exists" , name ), 403 )
160180 return
161181 }
162182 }
163183 }
164184 var addedTasks []task.TaskExtensionInfo
165185 for i , name := range req .Names {
166- t , err := fs .Copy (c , stdpath .Join (srcDir , name ), dstDir , len (req .Names ) > i + 1 )
186+ srcPath , err := utils .JoinUnderBase (srcDir , name )
187+ if err != nil {
188+ common .ErrorResp (c , err , 400 )
189+ return
190+ }
191+ _ , err = utils .JoinUnderBase (dstDir , name )
192+ if err != nil {
193+ common .ErrorResp (c , err , 400 )
194+ return
195+ }
196+ t , err := fs .Copy (c , srcPath , dstDir , len (req .Names ) > i + 1 )
167197 if t != nil {
168198 addedTasks = append (addedTasks , t )
169199 }
@@ -204,8 +234,16 @@ func FsRename(c *gin.Context) {
204234 common .ErrorResp (c , errs .PermissionDenied , 403 )
205235 return
206236 }
237+ if err := utils .ValidateNameComponent (req .Name ); err != nil {
238+ common .ErrorResp (c , err , 400 )
239+ return
240+ }
207241 if ! req .Overwrite {
208- dstPath := stdpath .Join (stdpath .Dir (reqPath ), req .Name )
242+ dstPath , err := utils .JoinUnderBase (stdpath .Dir (reqPath ), req .Name )
243+ if err != nil {
244+ common .ErrorResp (c , err , 400 )
245+ return
246+ }
209247 if dstPath != reqPath {
210248 if res , _ := fs .Get (c , dstPath , & fs.GetArgs {NoLog : true }); res != nil {
211249 common .ErrorStrResp (c , fmt .Sprintf ("file [%s] exists" , req .Name ), 403 )
@@ -251,7 +289,12 @@ func FsRemove(c *gin.Context) {
251289 return
252290 }
253291 for _ , name := range req .Names {
254- err := fs .Remove (c , stdpath .Join (reqDir , name ))
292+ removePath , err := utils .JoinUnderBase (reqDir , name )
293+ if err != nil {
294+ common .ErrorResp (c , err , 400 )
295+ return
296+ }
297+ err = fs .Remove (c , removePath )
255298 if err != nil {
256299 common .ErrorResp (c , err , 500 )
257300 return
0 commit comments