pterodactyl / panel

Pterodactyl® is a free, open-source game server management panel built with PHP, React, and Go. Designed with security in mind, Pterodactyl runs all game servers in isolated Docker containers while exposing a beautiful and intuitive UI to end users.
https://pterodactyl.io
Other
6.56k stars 1.64k forks source link

Requesting non-existent directory returns 500 error #4645

Closed Jelcoo closed 4 months ago

Jelcoo commented 1 year ago

Current Behavior

Requesting the file contents of a directory that does not exist returns an HTTP 500 error response

Expected Behavior

The API (Wings) should return the appropriate 404 error when a directory is not found.

Steps to Reproduce

Make a GET request to /api/client/servers/<id>/files/list?directory=unknown or whatever directory name you want that doesn't exist in the server.

Panel Version

1.11.2

Wings Version

1.11.0

Games and/or Eggs Affected

No response

Docker Image

No response

Error Logs

[2022-12-30 12:13:07] local.ERROR: GuzzleHttp\Exception\ServerException: Server error: `GET http://169.254.234.1:8080/api/servers/c094c33e-a5cd-4157-aa81-963a78931f78/files/list-directory?directory=unknown` resulted in a `500 Internal Server Error` response:
{"error":"An unexpected error was encountered while processing this request","request_id":"45665423-a3d9-426d-b861-47647 (truncated...)
ERROR: [Dec 30 12:22:56.821] error while handling HTTP request error=open /var/lib/pterodactyl/volumes/c094c33e-a5cd-4157-aa81-963a78931f78/unknown: no such file or directory request_id=d4747c65-d522-4e29-8c66-c8fdb565603f server_id=c094c33e-a5cd-4157-aa81-963a78931f78 status=500 url=/api/servers/c094c33e-a5cd-4157-aa81-963a78931f78/files/list-directory?directory=unknown

Stacktrace:
open /var/lib/pterodactyl/volumes/c094c33e-a5cd-4157-aa81-963a78931f78/unknown: no such file or directory
github.com/pterodactyl/wings/router.getServerListDirectory
        /srv/wings/router/router_server_files.go:82
github.com/gin-gonic/gin.(*Context).Next
        /root/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/context.go:173
github.com/pterodactyl/wings/router/middleware.ServerExists.func1
        /srv/wings/router/middleware/middleware.go:158
github.com/gin-gonic/gin.(*Context).Next
        /root/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/context.go:173
github.com/pterodactyl/wings/router/middleware.RequireAuthorization.func1
        /srv/wings/router/middleware/middleware.go:186
github.com/gin-gonic/gin.(*Context).Next
        /root/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/context.go:173
github.com/pterodactyl/wings/router/middleware.RequireAuthorization.func1
        /srv/wings/router/middleware/middleware.go:186
github.com/gin-gonic/gin.(*Context).Next
        /root/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/context.go:173
github.com/gin-gonic/gin.LoggerWithConfig.func1
        /root/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/logger.go:240
github.com/gin-gonic/gin.(*Context).Next
        /root/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/context.go:173
github.com/pterodactyl/wings/router/middleware.AttachApiClient.func1
        /srv/wings/router/middleware/middleware.go:51
github.com/gin-gonic/gin.(*Context).Next
        /root/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/context.go:173
github.com/pterodactyl/wings/router/middleware.AttachServerManager.func1
        /srv/wings/router/middleware/middleware.go:42
github.com/gin-gonic/gin.(*Context).Next
        /root/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/context.go:173
github.com/pterodactyl/wings/router/middleware.SetAccessControlHeaders.func1
        /srv/wings/router/middleware/middleware.go:135
github.com/gin-gonic/gin.(*Context).Next
        /root/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/context.go:173
github.com/pterodactyl/wings/router/middleware.CaptureErrors.func1
        /srv/wings/router/middleware/middleware.go:68
github.com/gin-gonic/gin.(*Context).Next
        /root/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/context.go:173
github.com/pterodactyl/wings/router/middleware.AttachRequestID.func1
        /srv/wings/router/middleware/middleware.go:33
github.com/gin-gonic/gin.(*Context).Next
        /root/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/context.go:173
github.com/gin-gonic/gin.CustomRecoveryWithWriter.func1
        /root/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/recovery.go:101
github.com/gin-gonic/gin.(*Context).Next
        /root/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/context.go:173
github.com/gin-gonic/gin.(*Engine).handleHTTPRequest
        /root/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/gin.go:616
github.com/gin-gonic/gin.(*Engine).ServeHTTP
        /root/go/pkg/mod/github.com/gin-gonic/gin@v1.8.1/gin.go:572
net/http.serverHandler.ServeHTTP
        /usr/local/go/src/net/http/server.go:2916
net/http.(*conn).serve
        /usr/local/go/src/net/http/server.go:1966
runtime.goexit
        /usr/local/go/src/runtime/asm_amd64.s:1571

Is there an existing issue for this?

Jelcoo commented 1 year ago

This is related to https://github.com/pterodactyl/panel/issues/4444 and https://github.com/pterodactyl/panel/pull/4637