Skip to content

Commit

Permalink
Merge pull request #3 from ilyaglow/security-fix
Browse files Browse the repository at this point in the history
Fix path traversal and storage path leak
  • Loading branch information
jessfraz authored Jul 18, 2018
2 parents edb6057 + d794e21 commit 1af2fac
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"io/ioutil"
"net/http"
"os"
"path"
"path/filepath"
"strings"

Expand Down Expand Up @@ -172,7 +173,7 @@ func (cmd *serverCommand) pasteHandler(w http.ResponseWriter, r *http.Request) {
return
}

filename := filepath.Join(cmd.storage, strings.Trim(r.URL.Path, "/"))
filename := filepath.Join(cmd.storage, filepath.FromSlash(path.Clean("/"+strings.Trim(r.URL.Path, "/"))))

var handler func(data []byte) (string, error)

Expand Down Expand Up @@ -213,7 +214,7 @@ func (cmd *serverCommand) pasteHandler(w http.ResponseWriter, r *http.Request) {

// check if the file exists
if _, err := os.Stat(filename); os.IsNotExist(err) {
writeError(w, fmt.Sprintf("No such file or directory: %s", filename))
writeError(w, fmt.Sprintf("No such file or directory: %s", r.URL.Path))
return
}

Expand Down

0 comments on commit 1af2fac

Please sign in to comment.