Skip to content

Commit e7139a9

Browse files
committed
Enforce the egg's file denylist more thoroughly
Closes pterodactyl/panel#5042
1 parent 1f77d22 commit e7139a9

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

router/router_download.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ func getDownloadFile(c *gin.Context) {
7878
return
7979
}
8080

81+
if err := s.Filesystem().IsIgnored(token.FilePath); err != nil {
82+
middleware.CaptureAndAbort(c, err)
83+
return
84+
}
85+
8186
f, st, err := s.Filesystem().File(token.FilePath)
8287
if err != nil {
8388
middleware.CaptureAndAbort(c, err)

router/router_server_files.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ import (
3131
func getServerFileContents(c *gin.Context) {
3232
s := middleware.ExtractServer(c)
3333
p := strings.TrimLeft(c.Query("file"), "/")
34+
if err := s.Filesystem().IsIgnored(p); err != nil {
35+
middleware.CaptureAndAbort(c, err)
36+
return
37+
}
3438
f, st, err := s.Filesystem().File(p)
3539
if err != nil {
3640
middleware.CaptureAndAbort(c, err)
@@ -214,6 +218,9 @@ func postServerDeleteFiles(c *gin.Context) {
214218
case <-ctx.Done():
215219
return ctx.Err()
216220
default:
221+
if err := s.Filesystem().IsIgnored(pi); err != nil {
222+
return err
223+
}
217224
return s.Filesystem().Delete(pi)
218225
}
219226
})
@@ -324,6 +331,11 @@ func postServerPullRemoteFile(c *gin.Context) {
324331
UseHeader: data.UseHeader,
325332
})
326333

334+
if err := s.Filesystem().IsIgnored(dl.Path()); err != nil {
335+
middleware.CaptureAndAbort(c, err)
336+
return
337+
}
338+
327339
download := func() error {
328340
s.Log().WithField("download_id", dl.Identifier).WithField("url", u.String()).Info("starting pull of remote file to disk")
329341
if err := dl.Execute(); err != nil {

server/filesystem/compress.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ import (
2828
// and the compressed file will be placed at that location named
2929
// `archive-{date}.tar.gz`.
3030
func (fs *Filesystem) CompressFiles(dir string, paths []string) (ufs.FileInfo, error) {
31+
for _, file := range paths {
32+
if err := fs.IsIgnored(path.Join(dir, file)); err != nil {
33+
return nil, err
34+
}
35+
}
3136
a := &Archive{Filesystem: fs, BaseDirectory: dir, Files: paths}
3237
d := path.Join(
3338
dir,

sftp/handler.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ func (h *Handler) Fileread(request *sftp.Request) (io.ReaderAt, error) {
7979
}
8080
h.mu.Lock()
8181
defer h.mu.Unlock()
82+
if err := h.fs.IsIgnored(request.Filepath); err != nil {
83+
return nil, err
84+
}
8285
f, _, err := h.fs.File(request.Filepath)
8386
if err != nil {
8487
if !errors.Is(err, os.ErrNotExist) {
@@ -104,6 +107,10 @@ func (h *Handler) Filewrite(request *sftp.Request) (io.WriterAt, error) {
104107

105108
h.mu.Lock()
106109
defer h.mu.Unlock()
110+
111+
if err := h.fs.IsIgnored(request.Filepath); err != nil {
112+
return nil, err
113+
}
107114
// The specific permission required to perform this action. If the file exists on the
108115
// system already it only needs to be an update, otherwise we'll check for a create.
109116
permission := PermissionFileUpdate
@@ -148,6 +155,10 @@ func (h *Handler) Filecmd(request *sftp.Request) error {
148155
l = l.WithField("target", request.Target)
149156
}
150157

158+
if err := h.fs.IsIgnored(request.Filepath); err != nil {
159+
return err
160+
}
161+
151162
switch request.Method {
152163
// Allows a user to make changes to the permissions of a given file or directory
153164
// on their server using their SFTP client.

0 commit comments

Comments
 (0)