Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce the egg's file denylist more thoroughly #183

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions router/router_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ func getDownloadFile(c *gin.Context) {
return
}

if err := s.Filesystem().IsIgnored(token.FilePath); err != nil {
middleware.CaptureAndAbort(c, err)
return
}

f, st, err := s.Filesystem().File(token.FilePath)
if err != nil {
middleware.CaptureAndAbort(c, err)
Expand Down
12 changes: 12 additions & 0 deletions router/router_server_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ import (
func getServerFileContents(c *gin.Context) {
s := middleware.ExtractServer(c)
p := strings.TrimLeft(c.Query("file"), "/")
if err := s.Filesystem().IsIgnored(p); err != nil {
middleware.CaptureAndAbort(c, err)
return
}
f, st, err := s.Filesystem().File(p)
if err != nil {
middleware.CaptureAndAbort(c, err)
Expand Down Expand Up @@ -214,6 +218,9 @@ func postServerDeleteFiles(c *gin.Context) {
case <-ctx.Done():
return ctx.Err()
default:
if err := s.Filesystem().IsIgnored(pi); err != nil {
return err
}
return s.Filesystem().Delete(pi)
}
})
Expand Down Expand Up @@ -324,6 +331,11 @@ func postServerPullRemoteFile(c *gin.Context) {
UseHeader: data.UseHeader,
})

if err := s.Filesystem().IsIgnored(dl.Path()); err != nil {
middleware.CaptureAndAbort(c, err)
return
}

download := func() error {
s.Log().WithField("download_id", dl.Identifier).WithField("url", u.String()).Info("starting pull of remote file to disk")
if err := dl.Execute(); err != nil {
Expand Down
5 changes: 5 additions & 0 deletions server/filesystem/compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ import (
// and the compressed file will be placed at that location named
// `archive-{date}.tar.gz`.
func (fs *Filesystem) CompressFiles(dir string, paths []string) (ufs.FileInfo, error) {
for _, file := range paths {
if err := fs.IsIgnored(path.Join(dir, file)); err != nil {
return nil, err
}
}
a := &Archive{Filesystem: fs, BaseDirectory: dir, Files: paths}
d := path.Join(
dir,
Expand Down
11 changes: 11 additions & 0 deletions sftp/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ func (h *Handler) Fileread(request *sftp.Request) (io.ReaderAt, error) {
}
h.mu.Lock()
defer h.mu.Unlock()
if err := h.fs.IsIgnored(request.Filepath); err != nil {
return nil, err
}
f, _, err := h.fs.File(request.Filepath)
if err != nil {
if !errors.Is(err, os.ErrNotExist) {
Expand All @@ -104,6 +107,10 @@ func (h *Handler) Filewrite(request *sftp.Request) (io.WriterAt, error) {

h.mu.Lock()
defer h.mu.Unlock()

if err := h.fs.IsIgnored(request.Filepath); err != nil {
return nil, err
}
// The specific permission required to perform this action. If the file exists on the
// system already it only needs to be an update, otherwise we'll check for a create.
permission := PermissionFileUpdate
Expand Down Expand Up @@ -148,6 +155,10 @@ func (h *Handler) Filecmd(request *sftp.Request) error {
l = l.WithField("target", request.Target)
}

if err := h.fs.IsIgnored(request.Filepath); err != nil {
return err
}

switch request.Method {
// Allows a user to make changes to the permissions of a given file or directory
// on their server using their SFTP client.
Expand Down