Skip to content

Commit

Permalink
🧼 Validate filenames Length.
Browse files Browse the repository at this point in the history
  • Loading branch information
Danieloni1 committed May 23, 2024
1 parent 2bb7872 commit 1e9e8d8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions api/r0/upload_async.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ func UploadMediaAsync(r *http.Request, rctx rcontext.RequestContext, user _apime
server := _routers.GetParam("server", r)
mediaId := _routers.GetParam("mediaId", r)
filename := filepath.Base(r.URL.Query().Get("filename"))
// GK-CUSTOMIZATION: Sanitize the filename
if len(filename) > 24 {
return &_responses.ErrorResponse{
Code: common.ErrCodeBadRequest,
Message: "Filename too long.",
InternalCode: common.ErrCodeBadRequest,
}
}

rctx = rctx.LogWithFields(logrus.Fields{
"mediaId": mediaId,
Expand Down
8 changes: 8 additions & 0 deletions api/r0/upload_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ type MediaUploadedResponse struct {

func UploadMediaSync(r *http.Request, rctx rcontext.RequestContext, user _apimeta.UserInfo) interface{} {
filename := filepath.Base(r.URL.Query().Get("filename"))
// GK-CUSTOMIZATION: Sanitize the filename
if len(filename) > 24 {
return &_responses.ErrorResponse{
Code: common.ErrCodeBadRequest,
Message: "Filename too long.",
InternalCode: common.ErrCodeBadRequest,
}
}

rctx = rctx.LogWithFields(logrus.Fields{
"filename": filename,
Expand Down

0 comments on commit 1e9e8d8

Please sign in to comment.