Skip to content

Commit

Permalink
Checking for Filename Vulnerabilities
Browse files Browse the repository at this point in the history
IamDushu committed Jul 14, 2024
1 parent 8fb4cc1 commit 67a3324
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions controllers/galleries.go
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import (
"fmt"
"net/http"
"net/url"
"path/filepath"
"strconv"

"github.com/go-chi/chi/v5"
@@ -162,7 +163,7 @@ func (g Galleries) Delete(w http.ResponseWriter, r *http.Request) {
}

func (g Galleries) Image(w http.ResponseWriter, r *http.Request) {
filename := chi.URLParam(r, "filename")
filename := g.filename(w, r)
galleryID, err := strconv.Atoi(chi.URLParam(r, "id"))
if err != nil {
http.Error(w, "Invalid gallery Id", http.StatusFound)
@@ -181,7 +182,7 @@ func (g Galleries) Image(w http.ResponseWriter, r *http.Request) {
}

func (g Galleries) DeleteImage(w http.ResponseWriter, r *http.Request) {
filename := chi.URLParam(r, "filename")
filename := g.filename(w, r)
gallery, err := g.galleryByID(w, r, userMustOwnGallery)
if err != nil {
return
@@ -195,6 +196,12 @@ func (g Galleries) DeleteImage(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, editPath, http.StatusFound)
}

func (g Galleries) filename(_ http.ResponseWriter, r *http.Request) string {
filename := chi.URLParam(r, "filename")
filename = filepath.Base(filename)
return filename
}

type galleryOpt func(http.ResponseWriter, *http.Request, *models.Gallery) error

func (g Galleries) galleryByID(w http.ResponseWriter, r *http.Request, opts ...galleryOpt) (*models.Gallery, error) {

0 comments on commit 67a3324

Please sign in to comment.