Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guard against empty/dot directory names before recursive
Chown.With the new recursive
Chown, a request likename=""(or".") will resolve todata.Path, so this endpoint can recursively chown an existing tree instead of only the new folder. Please reject invalid names before create/chown.🔧 Proposed fix
func postServerCreateDirectory(c *gin.Context) { s := ExtractServer(c) var data struct { Name string `json:"name"` Path string `json:"path"` } // BindJSON sends 400 if the request fails, all we need to do is return if err := c.BindJSON(&data); err != nil { return } + name := strings.TrimSpace(data.Name) + if name == "" || name == "." || name == ".." { + c.AbortWithStatusJSON(http.StatusUnprocessableEntity, gin.H{ + "error": "Invalid directory name.", + }) + return + } + target := filepath.Join(data.Path, name) - if err := s.Filesystem().CreateDirectory(data.Name, data.Path); err != nil { + if err := s.Filesystem().CreateDirectory(name, data.Path); err != nil { ... } - if err := s.Filesystem().Chown(filepath.Join(data.Path, data.Name)); err != nil { + if err := s.Filesystem().Chown(target); err != nil { middleware.CaptureAndAbort(c, err) return } c.Status(http.StatusNoContent) }🤖 Prompt for AI Agents